Skip to content

Commit

Permalink
[#556 state:resolved] ignore hobo_model's without fields in migration…
Browse files Browse the repository at this point in the history
… generator
  • Loading branch information
bryanlarsen committed Nov 28, 2009
1 parent 12d197e commit 4e9891b
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 8 deletions.
14 changes: 12 additions & 2 deletions hobo/CHANGES.txt
Expand Up @@ -27,15 +27,25 @@ 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
$ gem tumble

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:

Expand Down
1 change: 1 addition & 0 deletions hobo/doctest/scopes.rdoctest
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions hobo/lib/hobo/model.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions hobofields/lib/hobo_fields/fields_declaration.rb
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion hobofields/lib/hobo_fields/migration_generator.rb
Expand Up @@ -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]
Expand Down
3 changes: 3 additions & 0 deletions hobofields/lib/hobo_fields/model_extensions.rb
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions hobofields/test/migration_generator.rdoctest
Expand Up @@ -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

Expand Down

0 comments on commit 4e9891b

Please sign in to comment.