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, guard_protected_attrs = true) ⇒ 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
91 92 93 94 |
# File 'lib/ripple/attribute_methods.rb', line 91 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.
61 62 63 64 65 66 |
# File 'lib/ripple/attribute_methods.rb', line 61 def attributes self.class.properties.values.inject(@attributes.with_indifferent_access) do |hash, prop| hash[prop.key] = attribute(prop.key) hash end end |
#attributes=(attrs, guard_protected_attrs = true) ⇒ Object
Mass assign the document’s attributes.
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/ripple/attribute_methods.rb', line 70 def attributes=(attrs, guard_protected_attrs = true) raise ArgumentError, t('attribute_hash') unless Hash === attrs (guard_protected_attrs ? sanitize_for_mass_assignment(attrs) : 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
83 84 85 86 87 88 |
# File 'lib/ripple/attribute_methods.rb', line 83 def initialize(attrs={}) super() @attributes = attributes_from_property_defaults self.attributes = attrs yield self if block_given? end |
#respond_to?(*args) ⇒ Boolean
97 98 99 100 |
# File 'lib/ripple/attribute_methods.rb', line 97 def respond_to?(*args) self.class.define_attribute_methods super end |