Module: Cms::Behaviors::DynamicAttributes::InstanceMethods

Defined in:
lib/cms/behaviors/dynamic_attributes.rb

Instance Method Summary collapse

Instance Method Details

#dynamic_attributes(model) ⇒ Object

Return a list of valid dynamic 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.



217
# File 'lib/cms/behaviors/dynamic_attributes.rb', line 217

def dynamic_attributes(model); nil end

#is_dynamic_attribute?(attr, model) ⇒ Boolean

Will determine if the given attribute is a dynamic attribute on the given model. Override this in your class to provide custom logic if the #dynamic_attributes method or the :fields option are not flexible enough. If you override this method :fields and #dynamic_attributes will not apply at all unless you implement them yourself.

Returns:

  • (Boolean)


204
205
206
207
208
209
210
211
# File 'lib/cms/behaviors/dynamic_attributes.rb', line 204

def is_dynamic_attribute?(attr, model)
  attr = attr.to_s
  return dynamic_options[model.name][:fields].include?(attr) unless
    dynamic_options[model.name][:fields].nil?
  return dynamic_attributes(model).collect {|f| f.to_s}.include?(attr) unless
    dynamic_attributes(model).nil?
  true
end