modalfields 1.5.3 → 1.5.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.5.3
1
+ 1.5.4
@@ -80,7 +80,12 @@ module ModalFields
80
80
  blk[model, column_declaration]
81
81
  }
82
82
  end
83
- # geric filter applied to all the fields (after a specific filter for the type, if there is one)
83
+ def field_migration(type, &blk)
84
+ ModalFields.migration_hooks[type.to_sym] = lambda{|model, column_declaration|
85
+ blk[model, column_declaration]
86
+ }
87
+ end
88
+ # generic filter applied to all the fields (after a specific filter for the type, if there is one)
84
89
  def all_fields(&blk)
85
90
  field_type :all_fields, &blk
86
91
  end
@@ -147,6 +152,7 @@ module ModalFields
147
152
 
148
153
  @show_primary_keys = false
149
154
  @hooks = {}
155
+ @migration_hooks = {}
150
156
  @definitions = {}
151
157
  @column_to_field_declaration_hook = nil
152
158
  @type_aliases = {}
@@ -158,7 +164,7 @@ module ModalFields
158
164
 
159
165
  class <<self
160
166
 
161
- attr_reader :hooks, :definitions
167
+ attr_reader :hooks, :migration_hooks, :definitions
162
168
  # Define declaration of primary keys
163
169
  # ModalFields.show_primary_keys = false # the default: do not show primary keys
164
170
  # ModalFields.show_primary_keys = true # always declare primary keys
@@ -261,7 +267,9 @@ module ModalFields
261
267
  up = ""
262
268
  down = ""
263
269
  dbmodels(dbmodel_options).each do |model, file|
264
- new_fields, modified_fields, deleted_fields, deleted_model = diff(model)
270
+ new_fields, modified_fields, deleted_fields, deleted_model = diff(model).map{|fields|
271
+ fields.kind_of?(Array) ? fields.map{|f| migration_declaration(model, f)} : fields
272
+ }
265
273
  unless new_fields.empty? && modified_fields.empty? && deleted_fields.empty?
266
274
  up << "\n"
267
275
  down << "\n"
@@ -288,6 +296,7 @@ module ModalFields
288
296
  end
289
297
  modified_fields.each do |field|
290
298
  changed = model.fields_info.find{|f| f.name.to_sym==field.name.to_sym}
299
+ changed &&= migration_declaration(model, changed)
291
300
  up << " change_column #{model.table_name.to_sym.inspect}, #{changed.name.inspect}, #{changed.type.inspect}"
292
301
  unless changed.attributes.empty?
293
302
  up << ", " + changed.attributes.inspect.unwrap('{}')
@@ -355,6 +364,7 @@ module ModalFields
355
364
 
356
365
  assoc_cols = []
357
366
  association_fields.each do |assoc, cols|
367
+
358
368
  if options[:associations]
359
369
  if assoc.options[:polymorphic]
360
370
  foreign_table = :polymorphic
@@ -365,6 +375,7 @@ module ModalFields
365
375
  end
366
376
  Array(cols).each do |col|
367
377
  col = existing_fields.find{|f| f.name.to_s==col.to_s}
378
+ next unless col
368
379
  assoc_cols << col
369
380
  if options[:foreign_keys]
370
381
  yield :foreign_key, model.table_name, col.name, field_data(col, :assoc=>assoc)
@@ -405,6 +416,12 @@ module ModalFields
405
416
 
406
417
  private
407
418
 
419
+ def migration_declaration(model, field_declaration)
420
+ hook = ModalFields.migration_hooks[field_declaration.type.to_sym]
421
+ hook[model, field_declaration] if hook
422
+ field_declaration
423
+ end
424
+
408
425
  def field_data(field_info, options={})
409
426
  comments = options[:comments]
410
427
  extra = options[:extra]
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "modalfields"
8
- s.version = "1.5.3"
8
+ s.version = "1.5.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Javier Goizueta"]
12
- s.date = "2012-10-24"
12
+ s.date = "2012-11-03"
13
13
  s.description = "ModelFields is a Rails plugin that adds fields declarations to your models."
14
14
  s.email = "jgoizueta@gmail.com"
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: modalfields
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.3
4
+ version: 1.5.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-24 00:00:00.000000000 Z
12
+ date: 2012-11-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: modalsettings
@@ -233,7 +233,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
233
233
  version: '0'
234
234
  segments:
235
235
  - 0
236
- hash: -498931734787340260
236
+ hash: 1579727335010119279
237
237
  required_rubygems_version: !ruby/object:Gem::Requirement
238
238
  none: false
239
239
  requirements: