Class: AttributesMapper::Builder
- Inherits:
-
Object
- Object
- AttributesMapper::Builder
- Includes:
- HasAttributes
- Defined in:
- lib/attributes-mapper/builder.rb
Constant Summary
Constants included from HasAttributes
HasAttributes::ALLOWED_PARAMETERS, HasAttributes::SCOPE
Instance Attribute Summary collapse
-
#input ⇒ Object
readonly
Returns the value of attribute input.
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(input) ⇒ Builder
constructor
A new instance of Builder.
- #paths_builder ⇒ Object
- #to_h ⇒ Object
Methods included from HasAttributes
Constructor Details
#initialize(input) ⇒ Builder
Returns a new instance of Builder.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/attributes-mapper/builder.rb', line 7 def initialize(input) transformed_input = if configuration.apply_input_data_transform? configuration.apply_input_data_transform_proc.call(input) else input end @input = Rordash::HashUtil.deep_symbolize_keys(transformed_input) @mapped_input = {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *arguments, &block) ⇒ Object (private)
57 58 59 60 61 |
# File 'lib/attributes-mapper/builder.rb', line 57 def method_missing(method_name, *arguments, &block) return @mapped_input[method_name] if @mapped_input.key?(method_name) super end |
Instance Attribute Details
#input ⇒ Object (readonly)
Returns the value of attribute input.
5 6 7 |
# File 'lib/attributes-mapper/builder.rb', line 5 def input @input end |
Instance Method Details
#build ⇒ Object
18 19 20 21 |
# File 'lib/attributes-mapper/builder.rb', line 18 def build @mapped_input = paths_builder.build_for(input).deep_symbolize_keys self end |
#paths_builder ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/attributes-mapper/builder.rb', line 27 def paths_builder @paths_builder ||= begin builder = JsonPath::Builder.new if configuration.source_data_wrapper_class? builder.with_wrapped_data_class(configuration.source_data_wrapper_class) end add_paths_to_builder(builder) builder end end |
#to_h ⇒ Object
23 24 25 |
# File 'lib/attributes-mapper/builder.rb', line 23 def to_h @mapped_input end |