class HashMap::Base
Attributes
options[R]
original[R]
Public Class Methods
inherited(subclass)
click to toggle source
# File lib/hash_map/base.rb, line 9 def self.inherited(subclass) subclass.extend ToDSL return unless self < HashMap::Base unless dsl.attributes.empty? subclass._set_attributes_from_inheritance(attributes.deep_dup) end end
map(*args)
click to toggle source
# File lib/hash_map/base.rb, line 4 def self.map(*args) new(*args).output end
new(original, options = {})
click to toggle source
# File lib/hash_map/base.rb, line 24 def initialize(original, options = {}) @original = _transforms_input(prepare_input(original)) @options = options end
only_provided_call(*args)
click to toggle source
# File lib/hash_map/base.rb, line 17 def self.only_provided_call(*args) Class.new(self) do only_provided_keys end.call(*args) end
Public Instance Methods
[](key)
click to toggle source
# File lib/hash_map/base.rb, line 42 def [](key) output[key] end
mapper()
click to toggle source
# File lib/hash_map/base.rb, line 29 def mapper @mapper ||= Mapper.new(original, self) end
output()
click to toggle source
# File lib/hash_map/base.rb, line 33 def output @output ||= _transforms_output(mapper.output) end
Private Instance Methods
_transforms_input(input)
click to toggle source
# File lib/hash_map/base.rb, line 53 def _transforms_input(input) middlewares = self.class.dsl.instance_variable_get(:@transform_input) run_middlewares(middlewares, input) end
_transforms_output(output)
click to toggle source
# File lib/hash_map/base.rb, line 48 def _transforms_output(output) middlewares = self.class.dsl.instance_variable_get(:@transform_output) run_middlewares(middlewares, output) end
prepare_input(input)
click to toggle source
# File lib/hash_map/base.rb, line 58 def prepare_input(input) case input when ->(str) { str.class <= String } JSONAdapter.call(input) else input end end
run_middlewares(middlewares, input)
click to toggle source
# File lib/hash_map/base.rb, line 67 def run_middlewares(middlewares, input) if middlewares middlewares.inject(input) do |out, proccess| proccess.call(out) end else input end end