Class: Yutani::Provider

Inherits:
DSLEntity show all
Defined in:
lib/yutani/provider.rb

Instance Attribute Summary collapse

Attributes inherited from DSLEntity

#scope

Instance Method Summary collapse

Methods inherited from DSLEntity

#hiera

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              = HashWithIndifferentAccess.new(scope)
  @fields             = {}

  instance_eval &block if block_given?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



25
26
27
28
29
30
31
32
# File 'lib/yutani/provider.rb', line 25

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

#to_hObject



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

def to_h
  {
    @provider_name => @fields
  }
end