Class: Tabry::Models::Sub

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

Direct Known Subclasses

ArgInclude

Constant Summary collapse

FIELDS =
{
  aliases: :string_array,
  args: [:list_object, :ArgsList],
  description: :string,
  flags: [:list_object, :FlagsList],
  name: :string,
  subs: [:list_object, :SubsList],
}.freeze

Instance Attribute Summary

Attributes inherited from ConfigObject

#_raw, #_root

Class Method Summary collapse

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, #initialize, #inspect, #to_s

Constructor Details

This class inherits a constructor from Tabry::Models::ConfigObject

Class Method Details

.new(**args) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/tabry/models/sub.rb', line 11

def self.new(**args)
  hash = args[:raw]
  if hash["include"]
    IncludeSub.new(**args)
  else
    super(**args)
  end
end

Instance Method Details

#argsObject



40
41
42
# File 'lib/tabry/models/sub.rb', line 40

def args
  @args ||= ArgsList.new(raw: [], root: _root)
end

#flagsObject



36
37
38
# File 'lib/tabry/models/sub.rb', line 36

def flags
  @flags ||= FlagsList.new(raw: [], root: _root)
end

#flattenObject



44
45
46
# File 'lib/tabry/models/sub.rb', line 44

def flatten
  self
end

#max_argsObject



52
53
54
55
56
# File 'lib/tabry/models/sub.rb', line 52

def max_args
  return Float::INFINITY if args.any?(&:varargs?)

  args.count
end

#min_argsObject



48
49
50
# File 'lib/tabry/models/sub.rb', line 48

def min_args
  args.reject(&:optional).count
end

#subsObject

TODO: put this default stuff into ConfigObject



32
33
34
# File 'lib/tabry/models/sub.rb', line 32

def subs
  @subs ||= SubsList.new(raw: [], root: _root)
end