Class: Eco::API::Common::Loaders::Parser::RequiredAttrs

Inherits:
Struct
  • Object
show all
Defined in:
lib/eco/api/common/loaders/parser.rb

Overview

Helper class to scope what required attributes it depends on

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#attrObject

Returns the value of attribute attr

Returns:

  • (Object)

    the current value of attr



7
8
9
# File 'lib/eco/api/common/loaders/parser.rb', line 7

def attr
  @attr
end

#attrsObject

Returns the value of attribute attrs

Returns:

  • (Object)

    the current value of attrs



7
8
9
# File 'lib/eco/api/common/loaders/parser.rb', line 7

def attrs
  @attrs
end

#typeObject

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



7
8
9
# File 'lib/eco/api/common/loaders/parser.rb', line 7

def type
  @type
end

Instance Method Details

#active?(*input_attrs) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/eco/api/common/loaders/parser.rb', line 8

def active?(*input_attrs)
  missing(*input_attrs).empty?
end

#dependant?(attr) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/eco/api/common/loaders/parser.rb', line 12

def dependant?(attr)
  attrs.include?(attr)
end

#missing(*input_attrs) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/eco/api/common/loaders/parser.rb', line 16

def missing(*input_attrs)
  return [] if input_attrs.include?(attr)

  match = input_attrs & attrs
  miss  = attrs - match
  return []    if miss.empty?
  return attrs if match.empty?
  return miss  if type == :all
  []
end