Module: Accessible
- Included in:
- Commit, Repository, Request, User
- Defined in:
- lib/mixins/accessible.rb
Instance Method Summary collapse
-
#[](key) ⇒ Object
Provide access to instance variables like a hash with indifferent access.
-
#[]=(key, value) ⇒ Object
Provide access to instance variables like a hash with indifferent access.
-
#accessible? ⇒ Boolean
Setup simple exit criteria for recursion.
-
#initialize(attributes_hash = {}) ⇒ Object
Allow to set instance variables on initialization.
-
#update_attributes(attributes_hash) ⇒ Object
Allow to set all attributes by assigning a hash.
Instance Method Details
#[](key) ⇒ Object
Provide access to instance variables like a hash with indifferent access.
14 15 16 |
# File 'lib/mixins/accessible.rb', line 14 def [](key) self.instance_variable_get "@#{key}".to_sym end |
#[]=(key, value) ⇒ Object
Provide access to instance variables like a hash with indifferent access.
19 20 21 |
# File 'lib/mixins/accessible.rb', line 19 def []=(key, value) self.instance_variable_set "@#{key}".to_sym, value end |
#accessible? ⇒ Boolean
Setup simple exit criteria for recursion.
4 5 6 |
# File 'lib/mixins/accessible.rb', line 4 def accessible? true end |
#initialize(attributes_hash = {}) ⇒ Object
Allow to set instance variables on initialization.
9 10 11 |
# File 'lib/mixins/accessible.rb', line 9 def initialize(attributes_hash = {}) self.update_attributes attributes_hash end |
#update_attributes(attributes_hash) ⇒ Object
Allow to set all attributes by assigning a hash.
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/mixins/accessible.rb', line 24 def update_attributes(attributes_hash) attributes_hash.each do |key, value| attribute = self[key] if attribute.respond_to? :accessible? attribute.update_attributes(value) else self[key] = value end end end |