diff --git a/hobo/CHANGES.txt b/hobo/CHANGES.txt index 1400ee7c3..4d10c89c5 100644 --- a/hobo/CHANGES.txt +++ b/hobo/CHANGES.txt @@ -27,7 +27,7 @@ Deletions: `hobo_do_signup`. - Github no longer updates its gem repository. The canonical source - for Mislav's will\_paginate, which is a Hobo dependency is now + for Mislav's will\_paginate, a Hobo dependency, is now gemcutter.org. To add gemcutter.org to your gem source list: $ gem install gemcutter @@ -35,7 +35,17 @@ Deletions: Note that `gem tumble` is a toggle, so if you've already added `gemcutter` to your sources list, the above commands will have - removed it! Simply run `gem tumble` again to add it back in. + removed it! Simply run `gem tumble` again to add it back in. In + fact, sometimes the first command does the tumble automatically, so + it's worth double checking. + + - The fix for + [#556](https://hobo.lighthouseapp.com/projects/8324-hobo/tickets/556) + means that the migration generator now ignores all models that have + a `hobo_model` declaration but not a `fields` declaration. If you + have any models that do not have a fields declaration (join + tables, for example), you may wish to add a blank fields + declaration. Major enhancements: diff --git a/hobo/doctest/scopes.rdoctest b/hobo/doctest/scopes.rdoctest index e672cc7ad..87394bef2 100644 --- a/hobo/doctest/scopes.rdoctest +++ b/hobo/doctest/scopes.rdoctest @@ -107,6 +107,7 @@ Let's set up a few models for our testing: >> class Friendship < ActiveRecord::Base hobo_model + fields belongs_to :person belongs_to :friend, :class_name => "Person" end diff --git a/hobo/lib/hobo/model.rb b/hobo/lib/hobo/model.rb index 0e41fd205..c998c3647 100644 --- a/hobo/lib/hobo/model.rb +++ b/hobo/lib/hobo/model.rb @@ -36,14 +36,14 @@ class << base def inherited(klass) super - fields do + fields(false) do Hobo.register_model(klass) field(klass.inheritance_column, :string) end end end - base.fields # force hobofields to load + base.fields(false) # force hobofields to load included_in_class_callbacks(base) end @@ -122,7 +122,7 @@ def self.enable ActiveRecord::Base.class_eval do def self.hobo_model include Hobo::Model - fields # force hobofields to load + fields(false) # force hobofields to load end def self.hobo_user_model include Hobo::Model diff --git a/hobofields/lib/hobo_fields/fields_declaration.rb b/hobofields/lib/hobo_fields/fields_declaration.rb index 38be7d59c..fcd1c6a14 100644 --- a/hobofields/lib/hobo_fields/fields_declaration.rb +++ b/hobofields/lib/hobo_fields/fields_declaration.rb @@ -2,10 +2,12 @@ module HoboFields FieldsDeclaration = classy_module do - def self.fields(&b) + def self.fields(include_in_migration = true, &b) # Any model that calls 'fields' gets a bunch of other - # functionality included automatically, but make sure we only include it once + # functionality included automatically, but make sure we only + # include it once include HoboFields::ModelExtensions unless HoboFields::ModelExtensions.in?(included_modules) + @include_in_migration ||= include_in_migration if b dsl = HoboFields::FieldDeclarationDsl.new(self) diff --git a/hobofields/lib/hobo_fields/migration_generator.rb b/hobofields/lib/hobo_fields/migration_generator.rb index d89a43be1..7a3c9ecc6 100644 --- a/hobofields/lib/hobo_fields/migration_generator.rb +++ b/hobofields/lib/hobo_fields/migration_generator.rb @@ -115,7 +115,7 @@ def habtm_tables def models_and_tables ignore_model_names = MigrationGenerator.ignore_models.*.to_s.*.underscore all_models = table_model_classes - hobo_models = all_models.select { |m| m < HoboFields::ModelExtensions && m.name.underscore.not_in?(ignore_model_names) } + hobo_models = all_models.select { |m| m.try.include_in_migration && m.name.underscore.not_in?(ignore_model_names) } non_hobo_models = all_models - hobo_models db_tables = connection.tables - MigrationGenerator.ignore_tables.*.to_s - non_hobo_models.*.table_name [hobo_models, db_tables] diff --git a/hobofields/lib/hobo_fields/model_extensions.rb b/hobofields/lib/hobo_fields/model_extensions.rb index 31d2230b7..9c234f2ac 100644 --- a/hobofields/lib/hobo_fields/model_extensions.rb +++ b/hobofields/lib/hobo_fields/model_extensions.rb @@ -2,6 +2,9 @@ module HoboFields ModelExtensions = classy_module do + # ignore the model in the migration until somebody sets + # @include_in_migration via the fields declaration + inheriting_cattr_reader :include_in_migration => false # attr_types holds the type class for any attribute reader (i.e. getter # method) that returns rich-types diff --git a/hobofields/test/migration_generator.rdoctest b/hobofields/test/migration_generator.rdoctest index 6c03f1075..1c121e5e1 100644 --- a/hobofields/test/migration_generator.rdoctest +++ b/hobofields/test/migration_generator.rdoctest @@ -70,6 +70,9 @@ The migration generator only takes into account classes that use HoboFields, i.e >> HoboFields::MigrationGenerator.run => ["", ""] +You can also tell HoboFields to ignore additional tables. You can place this command in your environment.rb or elsewhere: + + >> HoboFields::MigrationGenerator.ignore_tables = ["green_fishes"] ### Create the table