Module: Shale::Builder::AssignedAttributes
- Extended by:
- T::Helpers, T::Sig
- Defined in:
- lib/shale/builder/assigned_attributes.rb
Overview
Include in a class that already includes ‘Shale::Builder` to add support for getting a list of attributes that have been assigned.
@requires_ancestor: Object
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
-
#__initialized ⇒ Object
readonly
: bool?.
Class Method Summary collapse
-
.included(mod) ⇒ Object
Gets called after including this module in a module or class.
-
.prepare_mod(mod) ⇒ Object
Prepares the received module or class for dynamic method definition.
Instance Method Summary collapse
-
#assigned_attribute_names ⇒ Object
Returns a set of names of assigned shale attributes.
-
#assigned_attributes ⇒ Object
Returns an array of shale attributes that have been assigned.
-
#assigned_values ⇒ Object
Returns an array of shale values that have been assigned.
- #initialize(*args, **kwargs, &block) ⇒ Object
Instance Attribute Details
#__initialized ⇒ Object (readonly)
: bool?
87 88 89 |
# File 'lib/shale/builder/assigned_attributes.rb', line 87 def __initialized @__initialized end |
Class Method Details
.included(mod) ⇒ Object
Gets called after including this module in a module or class. : (Module mod) -> void
22 23 24 25 |
# File 'lib/shale/builder/assigned_attributes.rb', line 22 def included(mod) mod.extend ClassMethods AssignedAttributes.prepare_mod(mod) end |
.prepare_mod(mod) ⇒ Object
Prepares the received module or class for dynamic method definition. : (Module mod) -> void
30 31 32 33 34 |
# File 'lib/shale/builder/assigned_attributes.rb', line 30 def prepare_mod(mod) assigned_attributes_methods_module = ::Module.new mod.instance_variable_set :@assigned_attributes_methods_module, assigned_attributes_methods_module mod.include assigned_attributes_methods_module end |
Instance Method Details
#assigned_attribute_names ⇒ Object
Returns a set of names of assigned shale attributes.
: -> Set
92 93 94 |
# File 'lib/shale/builder/assigned_attributes.rb', line 92 def assigned_attribute_names @assigned_attribute_names ||= Set.new end |
#assigned_attributes ⇒ Object
Returns an array of shale attributes that have been assigned.
: -> Array
100 101 102 103 104 105 |
# File 'lib/shale/builder/assigned_attributes.rb', line 100 def assigned_attributes klass = self.class #: as untyped assigned_attribute_names.map do |name| klass.attributes.fetch(name) end end |
#assigned_values ⇒ Object
Returns an array of shale values that have been assigned.
: -> Array
111 112 113 114 115 116 117 |
# File 'lib/shale/builder/assigned_attributes.rb', line 111 def assigned_values klass = self.class #: as untyped assigned_attribute_names.map do |name| attr = klass.attributes.fetch(name) Shale::Builder::Value.new(attr, public_send(attr.name)) end end |
#initialize(*args, **kwargs, &block) ⇒ Object
81 82 83 84 |
# File 'lib/shale/builder/assigned_attributes.rb', line 81 def initialize(*args, **kwargs, &block) super @__initialized = true end |