Module: Ripple::AttributeMethods::InstanceMethods
- Defined in:
- lib/ripple/attribute_methods.rb
Instance Method Summary collapse
-
#attributes ⇒ Hash
A copy of the values of all attributes in the Document.
-
#attributes=(attrs) ⇒ Object
Mass assign the document’s attributes.
- #initialize(attrs = {}) {|_self| ... } ⇒ Object
- #method_missing(method, *args, &block) ⇒ Object
- #respond_to?(*args) ⇒ Boolean
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
87 88 89 90 |
# File 'lib/ripple/attribute_methods.rb', line 87 def method_missing(method, *args, &block) self.class.define_attribute_methods super end |
Instance Method Details
#attributes ⇒ Hash
A copy of the values of all attributes in the Document. The result is not memoized, so use sparingly. This does not include associated objects, nor embedded documents.
57 58 59 60 61 62 |
# File 'lib/ripple/attribute_methods.rb', line 57 def attributes self.class.properties.values.inject({}) do |hash, prop| hash[prop.key] = attribute(prop.key) hash end.with_indifferent_access end |
#attributes=(attrs) ⇒ Object
Mass assign the document’s attributes.
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/ripple/attribute_methods.rb', line 66 def attributes=(attrs) raise ArgumentError, t('attribute_hash') unless Hash === attrs sanitize_for_mass_assignment(attrs).each do |k,v| next if k.to_sym == :key if respond_to?("#{k}=") __send__("#{k}=",v) else __send__(:attribute=,k,v) end end end |
#initialize(attrs = {}) {|_self| ... } ⇒ Object
79 80 81 82 83 84 |
# File 'lib/ripple/attribute_methods.rb', line 79 def initialize(attrs={}) super() @attributes = attributes_from_property_defaults self.attributes = attrs yield self if block_given? end |
#respond_to?(*args) ⇒ Boolean
93 94 95 96 |
# File 'lib/ripple/attribute_methods.rb', line 93 def respond_to?(*args) self.class.define_attribute_methods super end |