Class: AMA::Entity::Mapper::Context
- Inherits:
-
Object
- Object
- AMA::Entity::Mapper::Context
- Includes:
- Mixin::Reflection
- Defined in:
- lib/ama-entity-mapper/context.rb
Overview
Base class for various contexts, created to define common ground for any traversal operations
Instance Attribute Summary collapse
-
#include_sensitive_attributes ⇒ Object
readonly
Returns the value of attribute include_sensitive_attributes.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#strict ⇒ Object
readonly
Returns the value of attribute strict.
Instance Method Summary collapse
-
#advance(segment) ⇒ AMA::Entity::Mapper::Context
Creates new context, resembling traversal to specified segment.
- #defaults ⇒ Object
-
#initialize(**options) ⇒ Context
constructor
A new instance of Context.
- #to_h ⇒ Object
Methods included from Mixin::Reflection
#install_object_method, #method_object, #object_variable, #object_variable_exists, #object_variables, #set_object_attribute
Methods included from Mixin::Errors
#compliance_error, #mapping_error, #raise_if_internal, #validation_error
Constructor Details
#initialize(**options) ⇒ Context
Returns a new instance of Context.
30 31 32 33 34 35 36 37 38 |
# File 'lib/ama-entity-mapper/context.rb', line 30 def initialize(**) defaults = respond_to?(:defaults) ? self.defaults : {} = defaults.merge() defaults.keys.each do |key| instance_variable_set("@#{key}", [key]) end @logger = @logger.clone @logger.progname = "#{Mapper} #{path}" end |
Instance Attribute Details
#include_sensitive_attributes ⇒ Object (readonly)
Returns the value of attribute include_sensitive_attributes.
28 29 30 |
# File 'lib/ama-entity-mapper/context.rb', line 28 def include_sensitive_attributes @include_sensitive_attributes end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
22 23 24 |
# File 'lib/ama-entity-mapper/context.rb', line 22 def logger @logger end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
19 20 21 |
# File 'lib/ama-entity-mapper/context.rb', line 19 def path @path end |
#strict ⇒ Object (readonly)
Returns the value of attribute strict.
25 26 27 |
# File 'lib/ama-entity-mapper/context.rb', line 25 def strict @strict end |
Instance Method Details
#advance(segment) ⇒ AMA::Entity::Mapper::Context
Creates new context, resembling traversal to specified segment
54 55 56 57 58 |
# File 'lib/ama-entity-mapper/context.rb', line 54 def advance(segment) return self if segment.nil? data = to_h.merge(path: path.push(segment)) self.class.new(**data) end |
#defaults ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/ama-entity-mapper/context.rb', line 40 def defaults { path: Path.new, logger: Logger.new(Aux::NullStream::INSTANCE), strict: true, # Unstable feature, most likely it's name will change include_sensitive_attributes: false } end |
#to_h ⇒ Object
60 61 62 |
# File 'lib/ama-entity-mapper/context.rb', line 60 def to_h object_variables(self) end |