Module: AlphaCard::Attribute::InstanceMethods
- Defined in:
- lib/alpha_card/attribute.rb
Overview
Attributes class methods
* initialize
* attributes
* []
Instance Method Summary collapse
-
#[](name) ⇒ Object
Returns attribute value by it’s name.
-
#attributes ⇒ Hash
Returns class instance attributes.
-
#initialize(attributes = {}) ⇒ Object
Constructor supports setting attributes when creating a new instance of the class.
-
#required_attributes ⇒ Array
Returns names of the attributes that was marked as :required.
-
#required_attributes? ⇒ Bool
Indicates if all the attributes with option required: true are filled with non-nil value.
Instance Method Details
#[](name) ⇒ Object
Returns attribute value by it’s name.
255 256 257 |
# File 'lib/alpha_card/attribute.rb', line 255 def [](name) __send__(name) end |
#attributes ⇒ Hash
Returns class instance attributes.
232 233 234 235 236 |
# File 'lib/alpha_card/attribute.rb', line 232 def attributes self.class.attributes_set.each_with_object({}) do |(name, _), attributes| attributes[name] = __send__(name) end end |
#initialize(attributes = {}) ⇒ Object
Constructor supports setting attributes when creating a new instance of the class. Sets default values for the attributes if they are present.
209 210 211 212 213 214 215 |
# File 'lib/alpha_card/attribute.rb', line 209 def initialize(attributes = {}) set_attributes_defaults! attributes.each do |name, value| set_attribute_safely(name, value) end end |
#required_attributes ⇒ Array
Returns names of the attributes that was marked as :required.
276 277 278 |
# File 'lib/alpha_card/attribute.rb', line 276 def required_attributes self.class.attributes_set.select { |_, | [:required] }.keys end |
#required_attributes? ⇒ Bool
Indicates if all the attributes with option required: true are filled with non-nil value.
301 302 303 |
# File 'lib/alpha_card/attribute.rb', line 301 def required_attributes? required_attributes.all? { |attr| !self[attr].nil? } end |