Module: Kumi::Core::Compiler::Accessors::Base
- Included in:
- EachIndexedAccessor, MaterializeAccessor, RavelAccessor, ReadAccessor
- Defined in:
- lib/kumi/core/compiler/accessors/base.rb
Constant Summary collapse
- MISSING =
:__missing__
Instance Method Summary collapse
- #assert_array!(node, path_key, mode) ⇒ Object
-
#assert_hash!(node, path_key, mode) ⇒ Object
——– assertions ——–.
-
#fetch_key(hash, key, policy) ⇒ Object
——– key fetch with policy ——–.
- #missing_array_action(policy) ⇒ Object
- #missing_key_action(policy) ⇒ Object
-
#next_enters_array?(operations, pc) ⇒ Boolean
——– op helpers ——–.
- #warn_mismatch(node, path_key) ⇒ Object
Instance Method Details
#assert_array!(node, path_key, mode) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/kumi/core/compiler/accessors/base.rb', line 15 def assert_array!(node, path_key, mode) return if node.is_a?(Array) warn_mismatch(node, path_key) if ENV["DEBUG_ACCESS_BUILDER"] raise TypeError, "Expected Array at '#{path_key}' (#{mode}); got #{node.class}" end |
#assert_hash!(node, path_key, mode) ⇒ Object
——– assertions ——–
11 12 13 |
# File 'lib/kumi/core/compiler/accessors/base.rb', line 11 def assert_hash!(node, path_key, mode) raise TypeError, "Expected Hash at '#{path_key}' (#{mode})" unless node.is_a?(Hash) end |
#fetch_key(hash, key, policy) ⇒ Object
——– key fetch with policy ——–
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/kumi/core/compiler/accessors/base.rb', line 27 def fetch_key(hash, key, policy) case policy when :indifferent return hash[key] if hash.key?(key) return hash[key.to_sym] if hash.key?(key.to_sym) return hash[key.to_s] if hash.key?(key.to_s) MISSING when :string hash.key?(key.to_s) ? hash[key.to_s] : MISSING when :symbol hash.key?(key.to_sym) ? hash[key.to_sym] : MISSING else hash.key?(key) ? hash[key] : MISSING end end |
#missing_array_action(policy) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/kumi/core/compiler/accessors/base.rb', line 58 def missing_array_action(policy) if policy == :nil :yield_nil else (policy == :skip ? :skip : :raise) end end |
#missing_key_action(policy) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/kumi/core/compiler/accessors/base.rb', line 50 def missing_key_action(policy) if policy == :nil :yield_nil else (policy == :skip ? :skip : :raise) end end |
#next_enters_array?(operations, pc) ⇒ Boolean
——– op helpers ——–
45 46 47 48 |
# File 'lib/kumi/core/compiler/accessors/base.rb', line 45 def next_enters_array?(operations, pc) nxt = operations[pc + 1] nxt && nxt[:type] == :enter_array end |
#warn_mismatch(node, path_key) ⇒ Object
22 23 24 |
# File 'lib/kumi/core/compiler/accessors/base.rb', line 22 def warn_mismatch(node, path_key) puts "DEBUG AccessBuilder error at #{path_key}: got #{node.class}, value=#{node.inspect}" end |