Class: Tabry::Models::Config

Inherits:
ConfigObject show all
Defined in:
lib/tabry/models/config.rb

Constant Summary collapse

FIELDS =
{
  cmd: :string,
  main: [:object, :Sub],
  option_includes: [:object, :OptionIncludes],
  arg_includes: [:object, :ArgIncludes],
}.freeze

Instance Attribute Summary

Attributes inherited from ConfigObject

#_raw, #_root

Instance Method Summary collapse

Methods inherited from ConfigObject

#as_json, as_json, #assert_of_class, #init_field_boolean, #init_field_list_object, #init_field_object, #init_field_string, #init_field_string_array, #to_s

Constructor Details

#initialize(raw:) ⇒ Config

Returns a new instance of Config.



20
21
22
# File 'lib/tabry/models/config.rb', line 20

def initialize(raw:)
  super(raw: raw, root: self)
end

Instance Method Details

#dig_sub(sub_stack) ⇒ Object



24
25
26
# File 'lib/tabry/models/config.rb', line 24

def dig_sub(sub_stack)
  sub_stack.reduce(main) { |sub, sub_name| sub.subs.by_name[sub_name] }
end

#dig_sub_array(sub_stack) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/tabry/models/config.rb', line 28

def dig_sub_array(sub_stack)
  subs = [main]
  sub_stack.each do |sub_name|
    subs << subs.last.subs.by_name[sub_name]
  end
  subs
end

#inspectObject



36
37
38
39
40
41
# File 'lib/tabry/models/config.rb', line 36

def inspect
  # TODO: remove hack, but make everything in models have a hack so _root is not shown
  return "#<Tabry::Config>" if caller.any? { |c| c.include?("in `inspect'") }

  super
end