Module: ActiveDynamic::HasDynamicAttributes

Extended by:
ActiveSupport::Concern
Defined in:
lib/active_dynamic/has_dynamic_attributes.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *arguments, &block) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/active_dynamic/has_dynamic_attributes.rb', line 35

def method_missing(method_name, *arguments, &block)
  if dynamic_attributes_loaded?
    super
  else
    load_dynamic_attributes
    send(method_name, *arguments, &block)
  end
end

Instance Method Details

#dynamic_attributesObject



14
15
16
17
18
19
20
# File 'lib/active_dynamic/has_dynamic_attributes.rb', line 14

def dynamic_attributes
  if persisted? && any_dynamic_attributes?
    should_resolve_persisted? ? resolve_combined : resolve_from_db
  else
    resolve_from_provider
  end
end

#dynamic_attributes_loaded?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/active_dynamic/has_dynamic_attributes.rb', line 22

def dynamic_attributes_loaded?
  @dynamic_attributes_loaded ||= false
end

#respond_to?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
29
30
31
32
33
# File 'lib/active_dynamic/has_dynamic_attributes.rb', line 26

def respond_to?(method_name, include_private = false)
  if super
    true
  else
    load_dynamic_attributes unless dynamic_attributes_loaded?
    dynamic_attributes.find { |attr| attr.name == method_name.to_s.delete('=') }.present?
  end
end