Class: PuppetX::Relay::Agent::Model::Scope

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet_x/relay/agent/model/scope.rb

Direct Known Subclasses

Application, NodeGroup, Nodes, Query

Defined Under Namespace

Classes: Application, InvalidDefinitionError, NodeGroup, Nodes, NotFoundError, Query

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Scope

Returns a new instance of Scope.



42
43
44
# File 'lib/puppet_x/relay/agent/model/scope.rb', line 42

def initialize(value)
  @value = value
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



40
41
42
# File 'lib/puppet_x/relay/agent/model/scope.rb', line 40

def value
  @value
end

Class Method Details

.from_h(hsh) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/puppet_x/relay/agent/model/scope.rb', line 30

def from_h(hsh)
  raise InvalidDefinitionError, 'Scope must have exactly one item' unless hsh.length == 1

  key, value = hsh.shift
  raise NotFoundError, "Scope #{key.inspect} does not exist" unless @descendants.key? key

  @descendants[key].new value
end

.inherited(klass) ⇒ Object



26
27
28
# File 'lib/puppet_x/relay/agent/model/scope.rb', line 26

def inherited(klass)
  @descendants[klass.key] = klass
end

.keyObject



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/puppet_x/relay/agent/model/scope.rb', line 14

def key
  name
    .split('::')[-1]
    .gsub(%r{(^|[^A-Z])([A-Z]+)}) do
      if Regexp.last_match(1).empty?
        Regexp.last_match(2).downcase
      else
        "#{Regexp.last_match(1)}_#{Regexp.last_match(2).downcase}"
      end
    end
end

Instance Method Details

#to_json(*args) ⇒ Object



46
47
48
# File 'lib/puppet_x/relay/agent/model/scope.rb', line 46

def to_json(*args)
  { self.class.key => value }.to_json(*args)
end