diff --git a/Rakefile b/Rakefile index cd327f6..76a46a8 100644 --- a/Rakefile +++ b/Rakefile @@ -6,17 +6,17 @@ require 'rake/gempackagetask' spec = Gem::Specification.new do |s| s.name = 'preferences' - s.version = '0.4.2' + s.version = '0.5.0' s.platform = Gem::Platform::RUBY s.summary = 'Adds support for easily creating custom preferences for ActiveRecord models' s.description = s.summary - s.files = FileList['{app,generators,lib,test}/**/*'] + %w(CHANGELOG.rdoc init.rb LICENSE Rakefile README.rdoc) - FileList['test/app_root/{log,log/*,script,script/*}'] + s.files = FileList['{app,generators,lib,test}/**/*'] + %w(CHANGELOG.rdoc LICENSE Rakefile README.rdoc) - FileList['test/app_root/{log,log/*,script,script/*}'] s.require_path = 'lib' s.has_rdoc = true s.test_files = Dir['test/**/*_test.rb'] - s.author = 'Aaron Pfeifer' + s.authors = ["Aaron Pfeifer", "Jack Dempsey"] s.email = 'aaron@pluginaweek.org' s.homepage = 'http://www.pluginaweek.org' s.rubyforge_project = 'pluginaweek' diff --git a/generators/preferences/preferences_generator.rb b/generators/preferences/preferences_generator.rb deleted file mode 100644 index 6a7f3bf..0000000 --- a/generators/preferences/preferences_generator.rb +++ /dev/null @@ -1,7 +0,0 @@ -class PreferencesGenerator < Rails::Generator::Base - def manifest - record do |m| - m.migration_template '001_create_preferences.rb', 'db/migrate', :migration_file_name => 'create_preferences' - end - end -end diff --git a/init.rb b/init.rb deleted file mode 100644 index 98f262e..0000000 --- a/init.rb +++ /dev/null @@ -1 +0,0 @@ -require 'preferences' diff --git a/generators/preferences/USAGE b/lib/generators/USAGE similarity index 75% rename from generators/preferences/USAGE rename to lib/generators/USAGE index 3b403b3..be44596 100644 --- a/generators/preferences/USAGE +++ b/lib/generators/USAGE @@ -1,5 +1,5 @@ Usage: - script/generate preferences + rails generate preferences This will create a migration that will add the proper table to store preferences. diff --git a/lib/generators/preferences_generator.rb b/lib/generators/preferences_generator.rb new file mode 100644 index 0000000..251872f --- /dev/null +++ b/lib/generators/preferences_generator.rb @@ -0,0 +1,17 @@ +class PreferencesGenerator < Rails::Generators::Base + include Rails::Generators::Migration + + source_root File.expand_path("../templates", __FILE__) + + def self.next_migration_number(dirname) + if ActiveRecord::Base.timestamped_migrations + Time.now.utc.strftime("%Y%m%d%H%M%S") + else + "%.3d" % (current_migration_number(dirname) + 1) + end + end + + def create_migration_file + migration_template 'create_preferences.rb', "db/migrate/create_preferences.rb" + end +end diff --git a/generators/preferences/templates/001_create_preferences.rb b/lib/generators/templates/create_preferences.rb similarity index 87% rename from generators/preferences/templates/001_create_preferences.rb rename to lib/generators/templates/create_preferences.rb index a26adfc..eaf8b4f 100644 --- a/generators/preferences/templates/001_create_preferences.rb +++ b/lib/generators/templates/create_preferences.rb @@ -1,5 +1,5 @@ class CreatePreferences < ActiveRecord::Migration - def self.up + def change create_table :preferences do |t| t.string :name, :null => false t.references :owner, :polymorphic => true, :null => false @@ -9,8 +9,4 @@ def self.up end add_index :preferences, [:owner_id, :owner_type, :name, :group_id, :group_type], :unique => true, :name => 'index_preferences_on_owner_and_name_and_preference' end - - def self.down - drop_table :preferences - end end diff --git a/lib/preferences.rb b/lib/preferences.rb index 23ae075..e7711d5 100644 --- a/lib/preferences.rb +++ b/lib/preferences.rb @@ -1,3 +1,4 @@ +require 'preferences/engine' require 'preferences/preference_definition' # Adds support for defining preferences on ActiveRecord models. @@ -160,8 +161,8 @@ def preference(name, *args) after_save :update_preferences # Named scopes - named_scope :with_preferences, lambda {|preferences| build_preference_scope(preferences)} - named_scope :without_preferences, lambda {|preferences| build_preference_scope(preferences, true)} + scope :with_preferences, lambda {|preferences| build_preference_scope(preferences)} + scope :without_preferences, lambda {|preferences| build_preference_scope(preferences, true)} extend Preferences::ClassMethods include Preferences::InstanceMethods diff --git a/lib/preferences/engine.rb b/lib/preferences/engine.rb new file mode 100644 index 0000000..c1dcc53 --- /dev/null +++ b/lib/preferences/engine.rb @@ -0,0 +1,4 @@ +module Preferences + class Engine < Rails::Engine + end +end diff --git a/preferences.gemspec b/preferences.gemspec index 4e20fad..7b5be14 100644 --- a/preferences.gemspec +++ b/preferences.gemspec @@ -2,26 +2,25 @@ Gem::Specification.new do |s| s.name = %q{preferences} - s.version = "0.4.2" + s.version = "0.5.0" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= - s.authors = ["Aaron Pfeifer"] - s.date = %q{2010-04-17} + s.authors = ["Aaron Pfeifer", "Jack Dempsey"] + s.date = %q{2011-05-19} s.description = %q{Adds support for easily creating custom preferences for ActiveRecord models} s.email = %q{aaron@pluginaweek.org} - s.files = ["app/models", "app/models/preference.rb", "generators/preferences", "generators/preferences/USAGE", "generators/preferences/preferences_generator.rb", "generators/preferences/templates", "generators/preferences/templates/001_create_preferences.rb", "lib/preferences", "lib/preferences/preference_definition.rb", "lib/preferences.rb", "test/unit", "test/unit/preference_test.rb", "test/unit/preference_definition_test.rb", "test/app_root", "test/app_root/db", "test/app_root/db/migrate", "test/app_root/db/migrate/003_create_employees.rb", "test/app_root/db/migrate/004_migrate_preferences_to_version_1.rb", "test/app_root/db/migrate/002_create_cars.rb", "test/app_root/db/migrate/001_create_users.rb", "test/app_root/app", "test/app_root/app/models", "test/app_root/app/models/car.rb", "test/app_root/app/models/employee.rb", "test/app_root/app/models/user.rb", "test/app_root/app/models/manager.rb", "test/test_helper.rb", "test/factory.rb", "test/functional", "test/functional/preferences_test.rb", "CHANGELOG.rdoc", "init.rb", "LICENSE", "Rakefile", "README.rdoc"] + s.files = ["app/models", "app/models/preference.rb", "lib/generators", "lib/generators/preferences_generator.rb", "lib/generators/templates", "lib/generators/templates/create_preferences.rb", "lib/generators/USAGE", "lib/preferences", "lib/preferences/engine.rb", "lib/preferences/preference_definition.rb", "lib/preferences.rb", "test/app_root", "test/app_root/app", "test/app_root/app/models", "test/app_root/app/models/car.rb", "test/app_root/app/models/employee.rb", "test/app_root/app/models/manager.rb", "test/app_root/app/models/user.rb", "test/app_root/db", "test/app_root/db/migrate", "test/app_root/db/migrate/001_create_users.rb", "test/app_root/db/migrate/002_create_cars.rb", "test/app_root/db/migrate/003_create_employees.rb", "test/app_root/db/migrate/004_migrate_preferences_to_version_1.rb", "test/factory.rb", "test/functional", "test/functional/preferences_test.rb", "test/test_helper.rb", "test/unit", "test/unit/preference_definition_test.rb", "test/unit/preference_test.rb", "CHANGELOG.rdoc", "LICENSE", "Rakefile", "README.rdoc"] s.homepage = %q{http://www.pluginaweek.org} s.require_paths = ["lib"] s.rubyforge_project = %q{pluginaweek} - s.rubygems_version = %q{1.3.5} + s.rubygems_version = %q{1.5.2} s.summary = %q{Adds support for easily creating custom preferences for ActiveRecord models} - s.test_files = ["test/unit/preference_test.rb", "test/unit/preference_definition_test.rb", "test/functional/preferences_test.rb"] + s.test_files = ["test/functional/preferences_test.rb", "test/unit/preference_definition_test.rb", "test/unit/preference_test.rb"] if s.respond_to? :specification_version then - current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION s.specification_version = 3 - if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then + if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then else end else