Module: ActiveRecord::Acts::EavModel::InstanceMethods
- Defined in:
- lib/acts_as_eav_model.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
-
.included(base) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#eav_attributes(model) ⇒ Object
Return a list of valid eav attributes for the given model.
-
#is_eav_attribute?(attribute_name, model) ⇒ Boolean
Will determine if the given attribute is a eav attribute on the given model.
-
#respond_to_with_eav_behavior?(method_id, include_private = false) ⇒ Boolean
CLK added a respond_to? implementation so that ActiveRecord AssociationProxy (polymorphic relationships) does not mask the method_missing implementation here.
Class Method Details
.included(base) ⇒ Object
:nodoc:
288 289 290 |
# File 'lib/acts_as_eav_model.rb', line 288 def self.included(base) # :nodoc: base.extend ClassMethods end |
Instance Method Details
#eav_attributes(model) ⇒ Object
Return a list of valid eav attributes for the given model. Return nil if any field is allowed. If you want to say no field is allowed then return an empty array. If you just have a static list the :fields option is most likely easier.
353 |
# File 'lib/acts_as_eav_model.rb', line 353 def eav_attributes(model); nil end |
#is_eav_attribute?(attribute_name, model) ⇒ Boolean
Will determine if the given attribute is a eav attribute on the given model. Override this in your class to provide custom logic if the #eav_attributes method or the :fields option are not flexible enough. If you override this method :fields and #eav_attributes will not apply at all unless you implement them yourself.
338 339 340 341 342 343 344 345 |
# File 'lib/acts_as_eav_model.rb', line 338 def is_eav_attribute?(attribute_name, model) attribute_name = attribute_name.to_s = [model.name] return [:fields].include?(attribute_name) unless [:fields].nil? return eav_attributes(model).collect {|field| field.to_s}.include?(attribute_name) unless eav_attributes(model).nil? true end |
#respond_to_with_eav_behavior?(method_id, include_private = false) ⇒ Boolean
CLK added a respond_to? implementation so that ActiveRecord AssociationProxy (polymorphic relationships) does not mask the method_missing implementation here. See: rails.lighthouseapp.com/projects/8994/tickets/2378-associationproxymethod_missing-masks-method_missing-in-models Updated when certain magic fields (like timestamp columns) were interfering with saves, etc. oldwiki.rubyonrails.org/rails/pages/MagicFieldNames
362 363 364 365 366 367 368 |
# File 'lib/acts_as_eav_model.rb', line 362 def respond_to_with_eav_behavior?(method_id, include_private = false) if MAGIC_FIELD_NAMES.include?(method_id.to_sym) respond_to_without_eav_behavior?(method_id, include_private) else true end end |