Module: Yt::Associations::HasAttribute::ClassMethods
- Defined in:
- lib/yt/associations/has_attribute.rb
Instance Method Summary collapse
Instance Method Details
#has_attribute(attribute, options = {}, &block) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/yt/associations/has_attribute.rb', line 23 def has_attribute(attribute, = {}, &block) define_memoized_method(attribute) do field = .fetch(:from, attribute).to_s field = field.camelize(:lower) if .fetch(:camelize, true) value = @data.fetch field, [:default] value = type_cast value, [:type] if [:type] block_given? ? instance_exec(value, &block) : value end end |