Class: Itamae::Resource::Base::EvalContext

Inherits:
Object
  • Object
show all
Defined in:
lib/itamae/resource/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource) ⇒ EvalContext

Returns a new instance of EvalContext.



16
17
18
19
20
21
22
23
# File 'lib/itamae/resource/base.rb', line 16

def initialize(resource)
  @resource = resource

  @attributes = Hashie::Mash.new
  @notifications = []
  @subscriptions = []
  @verify_commands = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/itamae/resource/base.rb', line 29

def method_missing(method, *args, &block)
  if @resource.class.defined_attributes[method]
    if args.size == 1
      return @attributes[method] = args.first
    elsif args.size == 0 && block_given?
      return @attributes[method] = block
    elsif args.size == 0
      return @attributes[method]
    end
  end

  super
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



9
10
11
# File 'lib/itamae/resource/base.rb', line 9

def attributes
  @attributes
end

#not_if_commandObject (readonly)

Returns the value of attribute not_if_command.



14
15
16
# File 'lib/itamae/resource/base.rb', line 14

def not_if_command
  @not_if_command
end

#notificationsObject (readonly)

Returns the value of attribute notifications.



10
11
12
# File 'lib/itamae/resource/base.rb', line 10

def notifications
  @notifications
end

#only_if_commandObject (readonly)

Returns the value of attribute only_if_command.



13
14
15
# File 'lib/itamae/resource/base.rb', line 13

def only_if_command
  @only_if_command
end

#subscriptionsObject (readonly)

Returns the value of attribute subscriptions.



11
12
13
# File 'lib/itamae/resource/base.rb', line 11

def subscriptions
  @subscriptions
end

#verify_commandsObject (readonly)

Returns the value of attribute verify_commands.



12
13
14
# File 'lib/itamae/resource/base.rb', line 12

def verify_commands
  @verify_commands
end

Instance Method Details

#nodeObject



59
60
61
# File 'lib/itamae/resource/base.rb', line 59

def node
  @resource.recipe.runner.node
end

#not_if(command) ⇒ Object



55
56
57
# File 'lib/itamae/resource/base.rb', line 55

def not_if(command)
  @not_if_command = command
end

#notifies(action, resource_desc, timing = :delay) ⇒ Object



43
44
45
# File 'lib/itamae/resource/base.rb', line 43

def notifies(action, resource_desc, timing = :delay)
  @notifications << Notification.create(@resource, action, resource_desc, timing)
end

#only_if(command) ⇒ Object



51
52
53
# File 'lib/itamae/resource/base.rb', line 51

def only_if(command)
  @only_if_command = command
end

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

Returns:

  • (Boolean)


25
26
27
# File 'lib/itamae/resource/base.rb', line 25

def respond_to_missing?(method, include_private = false)
  @resource.class.defined_attributes.has_key?(method) || super
end

#run_command(*args) ⇒ Object



63
64
65
# File 'lib/itamae/resource/base.rb', line 63

def run_command(*args)
  @resource.recipe.runner.backend.run_command(*args)
end

#subscribes(action, resource_desc, timing = :delay) ⇒ Object



47
48
49
# File 'lib/itamae/resource/base.rb', line 47

def subscribes(action, resource_desc, timing = :delay)
  @subscriptions << Subscription.create(@resource, action, resource_desc, timing)
end

#verify(command) ⇒ Object

Experimental



68
69
70
# File 'lib/itamae/resource/base.rb', line 68

def verify(command)
  @verify_commands << command
end