Class: Yutani::Provider

Inherits:
Object
  • Object
show all
Includes:
Hiera
Defined in:
lib/yutani/provider.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Hiera

#hiera, init_hiera, lookup, pop, push, scope

Constructor Details

#initialize(provider_name, **scope, &block) ⇒ Provider

Returns a new instance of Provider.



7
8
9
10
11
12
13
# File 'lib/yutani/provider.rb', line 7

def initialize(provider_name, **scope, &block)
  @provider_name      = provider_name
  @scope              = scope
  @fields             = {}

  Docile.dsl_eval(self, &block) if block_given?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/yutani/provider.rb', line 29

def method_missing(name, *args, &block)
  if block_given?
    raise StandardError,
      "provider properties do not accept blocks as parameters"
  else
    @fields[name] = args.first
  end
end

Instance Attribute Details

#fieldsObject

Returns the value of attribute fields.



5
6
7
# File 'lib/yutani/provider.rb', line 5

def fields
  @fields
end

#provider_nameObject

Returns the value of attribute provider_name.



5
6
7
# File 'lib/yutani/provider.rb', line 5

def provider_name
  @provider_name
end

Instance Method Details

#[]=(k, v) ⇒ Object



15
16
17
# File 'lib/yutani/provider.rb', line 15

def []=(k,v)
  @fields[k] = v
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/yutani/provider.rb', line 25

def respond_to_missing?(method_name, include_private = false)
  true
end

#to_hObject



19
20
21
22
23
# File 'lib/yutani/provider.rb', line 19

def to_h
  {
    @provider_name => @fields
  }
end