Module: Diffable::ClassMethods

Defined in:
lib/diffable.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#conditional_fieldsObject (readonly)

Holds an array of fields which will be added to a modified change Hash (regardless of whether its value has changed or not) unless there are no other changes



253
254
255
# File 'lib/diffable.rb', line 253

def conditional_fields
  @conditional_fields
end

#diffableObject (readonly)

A shortcut, used to quickly check whether a class implements Diffable



257
258
259
# File 'lib/diffable.rb', line 257

def diffable
  @diffable
end

#excluded_fieldsObject (readonly)

Holds an array of excluded fields which will not be used for comparison tests or when copying deleted values



241
242
243
# File 'lib/diffable.rb', line 241

def excluded_fields
  @excluded_fields
end

#unique_within_groupObject (readonly)

String value corresponding to the field that uniquely identifies a child record from among its siblings (should not be id unless id is being generated)



247
248
249
# File 'lib/diffable.rb', line 247

def unique_within_group
  @unique_within_group
end

Instance Method Details

#set_conditional_fields(*h) ⇒ Object

Sets the class’s conditional_fields values.

If required, should be placed in the model definition code:

class ModelA < ActiveRecord::Base
  include Diffable
  set_conditional_fields :meta
end


270
271
272
273
# File 'lib/diffable.rb', line 270

def set_conditional_fields(*h)
  @conditional_fields = []
  h.each { |key| eval(%Q|@conditional_fields << "#{key.to_s}"|) }
end

#set_excluded_fields(*h) ⇒ Object

Sets the class’s excluded_fields values.

If required, should be placed in the model definition code:

class ModelB < ActiveRecord::Base
  include Diffable
  set_excluded_fields :ignore_me, :test
end


284
285
286
287
# File 'lib/diffable.rb', line 284

def set_excluded_fields(*h)
  @excluded_fields = []
  h.each { |key| eval(%Q|@excluded_fields << "#{key.to_s}"|) }
end

#set_unique_within_group(value) ⇒ Object

Sets the class’s unique_within_group value

If required, should be placed in the model definition code:

class ModelC < ActiveRecord::Base
  include Diffable
  set_unique_within_set :generated_identifier
end


298
299
300
# File 'lib/diffable.rb', line 298

def set_unique_within_group(value)
  eval(%Q|@unique_within_group = "#{value.to_s}"|)
end