Module: SoftAttributes::Base::InstanceMethods

Defined in:
lib/soft_attributes/base.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_symbol, *parameters) ⇒ Object (private)

:nodoc:



60
61
62
63
64
65
66
67
68
69
# File 'lib/soft_attributes/base.rb', line 60

def method_missing(method_symbol, *parameters) #:nodoc:
  if respond_to?(method_symbol) && !method_symbol.to_s.end_with?("=") #getter
    attr_name = extract_attr_name_without_equals(method_symbol)
    if self.soft_attributes.has_key?(attr_name)
      value = self.soft_attributes[attr_name][:value]
      return value.is_a?(Proc) ? value.call(self) : value
    end
  end
  super
end

Instance Method Details

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

:nodoc:

Returns:

  • (Boolean)


54
55
56
57
# File 'lib/soft_attributes/base.rb', line 54

def respond_to?(method_symbol, include_private = false) #:nodoc:
  attr_name = extract_attr_name_without_equals(method_symbol)
  self.soft_attributes.has_key?(attr_name) || super
end

#soft_attributesObject



43
44
45
46
47
# File 'lib/soft_attributes/base.rb', line 43

def soft_attributes
  @soft_attributes ||= self.class.soft_attributes.clone
  @soft_attributes.stringify_keys!
  @soft_attributes
end

#soft_attributes=(new_value) ⇒ Object



49
50
51
52
# File 'lib/soft_attributes/base.rb', line 49

def soft_attributes=(new_value)
  soft_attributes.merge!(new_value)
  soft_attributes   # return the merged hash
end