Module: Resourced::Attributes::InstanceMethods
- Included in:
- Resourced::Attributes
- Defined in:
- lib/resourced/attributes.rb
Instance Attribute Summary collapse
-
#attr_body ⇒ Object
readonly
Returns the value of attribute attr_body.
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Instance Method Summary collapse
-
#erase(*keys) ⇒ Object
Erase existing params.
- #initialize(params, scope) ⇒ Object
-
#set(params = {}) ⇒ Object
Set additional params.
Instance Attribute Details
#attr_body ⇒ Object (readonly)
Returns the value of attribute attr_body.
11 12 13 |
# File 'lib/resourced/attributes.rb', line 11 def attr_body @attr_body end |
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
11 12 13 |
# File 'lib/resourced/attributes.rb', line 11 def attributes @attributes end |
Instance Method Details
#erase(*keys) ⇒ Object
Erase existing params
Params:
-
params Hash List of param keys to be erased
Examples:
resource = UserResource.new(params, scope)
resource.erase(:password, :auth_token)
47 48 49 50 51 52 53 |
# File 'lib/resourced/attributes.rb', line 47 def erase(*keys) keys.each do |key| @attributes.delete(key.to_sym) end self end |
#initialize(params, scope) ⇒ Object
7 8 9 10 |
# File 'lib/resourced/attributes.rb', line 7 def initialize(params, scope) @attr_body = self.class.body set(@attr_body ? params[@attr_body] : params) end |
#set(params = {}) ⇒ Object
Set additional params
Params:
-
params Hash List of params to be assigned
Examples:
resource = UserResource.new(params, scope)
resource.set(role: "guest")
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/resourced/attributes.rb', line 24 def set(params={}) sanitized = self.class._attributes_obj.sanitize_params(self, params) if @attributes @attributes.merge(sanitized) else @attributes = sanitized end self end |