Class: Smith::Tool::ArgumentContainerReader
- Inherits:
-
Object
- Object
- Smith::Tool::ArgumentContainerReader
- Extended by:
- Dry::Initializer
- Defined in:
- lib/smith/tool/argument_container_reader.rb
Instance Method Summary collapse
- #append_children(pending:, source:, target:, depth:, metrics:) ⇒ Object
- #size(source, type) ⇒ Object
- #snapshot(source, type) ⇒ Object
- #target(type, size) ⇒ Object
- #type(value) ⇒ Object
Instance Method Details
#append_children(pending:, source:, target:, depth:, metrics:) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/smith/tool/argument_container_reader.rb', line 44 def append_children(pending:, source:, target:, depth:, metrics:) if type(source) == :hash append_hash_children(pending, source, target, depth, metrics) else append_array_children(pending, source, target, depth, metrics) end end |
#size(source, type) ⇒ Object
31 32 33 |
# File 'lib/smith/tool/argument_container_reader.rb', line 31 def size(source, type) type == :hash ? HASH_LENGTH.bind_call(source) : ARRAY_LENGTH.bind_call(source) end |
#snapshot(source, type) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/smith/tool/argument_container_reader.rb', line 35 def snapshot(source, type) target = type == :hash ? Hash.allocate : Array.allocate initializer = type == :hash ? HASH_INITIALIZE_COPY : ARRAY_INITIALIZE_COPY initializer.bind_call(target, source) target.freeze end |
#target(type, size) ⇒ Object
42 |
# File 'lib/smith/tool/argument_container_reader.rb', line 42 def target(type, size) = type == :hash ? {} : Array.new(size) |
#type(value) ⇒ Object
25 26 27 28 29 |
# File 'lib/smith/tool/argument_container_reader.rb', line 25 def type(value) return :hash if MODULE_MATCH.bind_call(Hash, value) :array if MODULE_MATCH.bind_call(Array, value) end |