Class: CapUtil::FakeCap

Inherits:
Object
  • Object
show all
Defined in:
lib/cap-util/fake_cap.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ FakeCap

Returns a new instance of FakeCap.



9
10
11
12
13
# File 'lib/cap-util/fake_cap.rb', line 9

def initialize(*args)
  @struct = OpenStruct.new
  @roles = []
  @cmds_run = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



15
16
17
# File 'lib/cap-util/fake_cap.rb', line 15

def method_missing(method, *args, &block)
  @struct.send(method, *args, &block)
end

Instance Attribute Details

#cmds_runObject (readonly)

Returns the value of attribute cmds_run.



7
8
9
# File 'lib/cap-util/fake_cap.rb', line 7

def cmds_run
  @cmds_run
end

#rolesObject (readonly)

Returns the value of attribute roles.



7
8
9
# File 'lib/cap-util/fake_cap.rb', line 7

def roles
  @roles
end

Instance Method Details

#fetch(var_name) ⇒ Object



31
32
33
# File 'lib/cap-util/fake_cap.rb', line 31

def fetch(var_name)
  self.send("fetch_#{var_name}")
end

#respond_to?(method) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/cap-util/fake_cap.rb', line 19

def respond_to?(method)
  @struct.respond_to?(method) ? true : super
end

#role(name, hostname, opts) ⇒ Object



35
36
37
# File 'lib/cap-util/fake_cap.rb', line 35

def role(name, hostname, opts)
  @roles << [name, hostname, opts]
end

#run(cmd, *args) ⇒ Object



23
24
25
# File 'lib/cap-util/fake_cap.rb', line 23

def run(cmd, *args)
  @cmds_run << cmd
end

#sudo(cmd, *args) ⇒ Object



27
28
29
# File 'lib/cap-util/fake_cap.rb', line 27

def sudo(cmd, *args)
  run("sudo #{cmd}", *args)
end