Module: Shamu::Attributes::Assignment
- Extended by:
- ActiveSupport::Concern
- Included in:
- Entities::ListScope, JsonApi::Rails::Pagination, Services::Request
- Defined in:
- lib/shamu/attributes/assignment.rb
Overview
Provide a means for defining writable attributes.
Class Method Summary collapse
-
.attribute(name, *args, **options, &block)
Define a new attribute for the class.
Instance Method Summary collapse
- #[]=(name, value) ⇒ Object
-
#assigned?(name) ⇒ Boolean
not just present/memoized.
-
#assigned_attributes ⇒ Array<Symbol>
The attributes that have been assigned.
-
#unassigned_attributes ⇒ Array<Symbol>
The attributes that have not been assigned.
Class Method Details
.attribute(name, *args, **options, &block)
This method returns an undefined value.
Define a new attribute for the class.
68 69 70 71 72 |
# File 'lib/shamu/attributes/assignment.rb', line 68 def attribute( name, *args, **, &block ) super( name, *args, ** ) define_attribute_assignment( name, ** ) define_attribute_writer( name, ** ) end |
Instance Method Details
#[]=(name, value) ⇒ Object
17 18 19 |
# File 'lib/shamu/attributes/assignment.rb', line 17 def []=( name, value ) send :"assign_#{ name }", value if attribute?( name ) end |
#assigned?(name) ⇒ Boolean
not just present/memoized.
33 34 35 |
# File 'lib/shamu/attributes/assignment.rb', line 33 def assigned?( name ) assigned_attributes.include?( name ) end |
#assigned_attributes ⇒ Array<Symbol>
Returns the attributes that have been assigned.
22 23 24 |
# File 'lib/shamu/attributes/assignment.rb', line 22 def assigned_attributes @assigned_attributes.to_a || [] end |
#unassigned_attributes ⇒ Array<Symbol>
Returns the attributes that have not been assigned.
27 28 29 |
# File 'lib/shamu/attributes/assignment.rb', line 27 def unassigned_attributes self.class.attributes.keys - assigned_attributes end |