Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ db/schema.rb*
*.log
*.sqlite3
*.swp
Gemfile.lock
.bundle
vendor/bundle
config/registry.yml
public/coverage
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.9.3-p551
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source "http://www.rubygems.org"

gemspec
27 changes: 18 additions & 9 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,23 @@

=== Installation

script/plugin install git://github.com/berk/registry.git
# Gemfile
gem 'registry', :git => 'https://github.com/ss/registry.git'

== Testing/Coverage

=== Test
# setup test environment
rbenv install 1.9.3-p551
gem install bundler -v '~>1.0.0'
bundle install --clean --path=vendor/bundle
bundle exec rake db:migrate

script/server
point your browser at http://localhost:3000/registry
# run tests
bundle exec rake test

# generate coverage report
bundle exec rake registry:coverage
# point your browser at http://localhost:3000/coverage/

=== Usage

Expand All @@ -37,7 +46,7 @@
=== Example usage

in app/controllers/api_controller.rb

class ApiController < ActionController::Base

before_filter :ensure_api_enabled, :check_rate_limit
Expand Down Expand Up @@ -80,21 +89,21 @@

development:
api_request_window: 100

test:
api_request_window: 100

production:
api_enabled: false
api_request_limit: 10
api_request_window: 10000


in lib/tasks/my_tasks.rake

desc 'Import configuration'
task :import_configuration => [:environment] do
Registry.import("#{Rails.root}/config/registry.yml")
Registry.import("#{Rails.root}/config/registry.yml", :verbose => true)
end

---
Expand Down
1 change: 0 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ require(File.join(File.dirname(__FILE__), 'config', 'boot'))

require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'

require 'tasks/rails'
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.3.1
18 changes: 14 additions & 4 deletions app/models/registry/entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#

require 'registry'
require File.expand_path(File.dirname(__FILE__) + '/../../../vendor/gems/metaskills-acts_as_versioned-0.6.3/lib/acts_as_versioned')
require 'acts_as_versioned'

module Registry
class Entry < ActiveRecord::Base
Expand Down Expand Up @@ -85,7 +85,12 @@ def self.export!(file_path = DEFAULT_YML_LOCATION)
# ==== Parameters
#
# * +file_path+ - Path to yml file.
# * +opts+ - Optional, merge options (see documentation for <tt>merge</tt> method)
# * +opts+ - Optional parameters
#
# ==== Options
#
# * <tt>verbose</tt> - If true, print information to stderr.
# * merge options (see documentation for <tt>merge</tt> method)
#
# ==== File Format
#
Expand Down Expand Up @@ -113,6 +118,7 @@ def self.import!(file_path = DEFAULT_YML_LOCATION, opts={})
hash = YAML.load_file(file_path)
default_entries = hash.delete(Registry::DEFAULTS_KEY) || {}
hash.each do |env, entries|
STDERR.puts "Importing: #{env}" if opts[:verbose]
root(env).merge(default_entries.deep_merge(entries), opts)
end
end
Expand Down Expand Up @@ -236,9 +242,13 @@ def to_form_property_hash
# * +hash+ - Optional, hash to update.
#
# call-seq:
# Registry::Entry.root.export #=> {'api' => {'enabled' => true}}
# Registry::Entry.root.export #=> {'api' => {'enabled' => true}, '_last_updated_at' => ...}
def export(hash={}, entries=nil)
entries ||= Entry.all(:conditions => ['env = ? and id != ?', env, id])

if entries.nil?
entries = Entry.all(:conditions => ['env = ? and id != ?', env, id])
hash['_last_updated_at'] = entries.inject(Time.at(0)) {|old_max, entry| [old_max, entry.updated_at].max}
end

properties, entries = entries.partition {|entry| entry.parent_id == id && !entry.folder?}
properties.each do |p|
Expand Down
19 changes: 9 additions & 10 deletions app/views/registry/registry/viewport.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
</head>

<body>
<script type="text/javascript">
<%= javascript_tag %{

Ext.onReady(function(){
Ext.QuickTips.init();
<%=render :partial => "grid" %>
<%=render :partial => "tree" %>
<%=render :partial => "info_panel" %>
<%=render :partial => "folder_form" %>
<%=render :partial => "property_form" %>
<%=render :partial => 'revisions' %>
Ext.QuickTips.init();
#{render :partial => "grid"}
#{render :partial => "tree"}
#{render :partial => "info_panel"}
#{render :partial => "folder_form"}
#{render :partial => "property_form"}
#{render :partial => 'revisions'}

var viewport = new Ext.Viewport({
layout: 'border',
Expand Down Expand Up @@ -49,9 +49,8 @@
}]
})]
});

});
</script>
} %>

</body>
</html>
14 changes: 0 additions & 14 deletions config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,3 @@ test:
database: db/test.sqlite3
pool: 5
timeout: 5000

pg_development:
adapter: postgresql
host: localhost
encoding: utf8
username: postgres
database: sme_dev

pg_test:
adapter: postgresql
host: localhost
encoding: utf8
username: postgres
database: sme_test
2 changes: 1 addition & 1 deletion config/environment.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Bootstrap the Rails environment, frameworks, and default configuration
require File.join(File.dirname(__FILE__), 'boot')

RAILS_GEM_VERSION = '2.3.10' unless defined? RAILS_GEM_VERSION
RAILS_GEM_VERSION = '2.3.18' unless defined? RAILS_GEM_VERSION

Rails::Initializer.run do |config|
# Settings in config/environments/* take precedence over those specified here.
Expand Down
12 changes: 12 additions & 0 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

require 'pp'

require 'test/unit'
require 'mocha/setup'

# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
# your test database is "scratch space" for the test suite and is wiped
Expand All @@ -25,3 +28,12 @@
config.action_mailer.delivery_method = :test

config.action_controller.session = { :key => "_test_session", :secret => "218d878f47b437169e7de9975d2e1286" }

if ENV['COVERAGE']
require 'simplecov'
FileUtils.rm_rf(Rails.root + 'public/coverage')
SimpleCov.start 'rails' do
add_filter '/vendor/bundle/'
coverage_dir 'public/coverage'
end
end
20 changes: 20 additions & 0 deletions config/preinitializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
begin
require 'rubygems'
require 'bundler'
rescue LoadError
raise "Could not load the bundler gem. Install it with `gem install bundler`."
end

if Gem::Version.new(Bundler::VERSION) <= Gem::Version.new("0.9.24")
raise RuntimeError, "Your bundler version is too old for Rails 2.3.\n" +
"Run `gem install bundler` to upgrade."
end

begin
# Set up load paths for all bundled gems
ENV["BUNDLE_GEMFILE"] = File.expand_path("../../Gemfile", __FILE__)
Bundler.setup
rescue Bundler::GemNotFound
raise RuntimeError, "Bundler couldn't find some gems.\n" +
"Did you run `bundle install`?"
end
File renamed without changes.
8 changes: 7 additions & 1 deletion lib/registry/transcoder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@
# Date transcoder
config.add_transcoder do
to_db {|value| value.strftime("%Y-%m-%d")}
from_db {|string| Date.parse(string)}
from_db do |string|
result = Date.strptime(string, '%d-%m-%Y') rescue nil
result ||= Date.strptime(string, '%Y-%m-%d') rescue nil
result ||= Date.strptime(string, '%m-%d-%Y') rescue nil

result || string
end

matches do |value|
value.is_a?(Date) or # to_db
Expand Down
9 changes: 3 additions & 6 deletions lib/tasks/registry.rake
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@ namespace :registry do
end

desc 'Generate coverage report'
task :coverage => [:environment] do
excludes = %w[boot.rb config vendor].join(',')
output_dir = "#{Rails.root}/public/coverage"
files = Dir['test/{unit,functional}/**/*_test.rb'].join(' ')
rm_rf(output_dir)
sh "rcov --rails -t --sort coverage -o public/coverage -x 'gems' #{files}"
task :coverage do
ENV['COVERAGE'] = '1'
system('rake test')
end

desc "Set a registry value (eg 'api.enabled'=true)"
Expand Down
26 changes: 26 additions & 0 deletions registry.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)

Gem::Specification.new do |gem|
gem.name = "registry"
gem.version = IO.read('VERSION')
gem.authors = ["Michael Berkovich", "Scott Steadman"]
gem.email = ["registry-gem@stdmn.com"]
gem.description = %q{Framework for controlling application behavior through configurable properties}
gem.summary = gem.description
gem.homepage = "https://github.com/ss/registry"
gem.license = 'MIT'

gem.add_development_dependency 'iconv'
gem.add_development_dependency 'mocha'
gem.add_development_dependency 'rails', '~> 2.3.0'
gem.add_development_dependency 'rake', '0.9.2.2'
gem.add_development_dependency 'shoulda', '3.0.1'
gem.add_development_dependency 'simplecov', '~>0.6.0'
gem.add_development_dependency 'sqlite3', '~>1.3.0'

gem.files = `git ls-files`.split($/)
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
gem.require_paths = ["lib"]
end
4 changes: 2 additions & 2 deletions script/breakpointer
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/breakpointer'
require File.expand_path('../../config/boot', __FILE__)
require 'commands/breakpointer'
2 changes: 1 addition & 1 deletion script/console
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env ruby
$lazy_load_rails = true
require File.dirname(__FILE__) + '/../config/boot'
require File.expand_path('../../config/boot', __FILE__)
require 'commands/console'
2 changes: 1 addition & 1 deletion script/dbconsole
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require File.expand_path('../../config/boot', __FILE__)
require 'commands/dbconsole'
4 changes: 2 additions & 2 deletions script/destroy
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/destroy'
require File.expand_path('../../config/boot', __FILE__)
require 'commands/destroy'
4 changes: 2 additions & 2 deletions script/generate
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/generate'
require File.expand_path('../../config/boot', __FILE__)
require 'commands/generate'
4 changes: 2 additions & 2 deletions script/plugin
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/plugin'
require File.expand_path('../../config/boot', __FILE__)
require 'commands/plugin'
4 changes: 2 additions & 2 deletions script/runner
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/runner'
require File.expand_path('../../config/boot', __FILE__)
require 'commands/runner'
4 changes: 2 additions & 2 deletions script/server
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/server'
require File.expand_path('../../config/boot', __FILE__)
require 'commands/server'
26 changes: 0 additions & 26 deletions script/skynet

This file was deleted.

17 changes: 0 additions & 17 deletions script/sweatshop

This file was deleted.

Loading