Class: Inprovise::Script

Inherits:
Object
  • Object
show all
Defined in:
lib/inprovise/script.rb

Defined Under Namespace

Classes: DSL

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Script

Returns a new instance of Script.



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/inprovise/script.rb', line 53

def initialize(name)
  @name = name
  @description = nil
  @configuration = nil
  @user = nil
  @dependencies = []
  @children = []
  @actions = {}
  @commands = {}
  @remove = nil
end

Instance Attribute Details

#actionsObject (readonly)

Returns the value of attribute actions.



9
10
11
# File 'lib/inprovise/script.rb', line 9

def actions
  @actions
end

#childrenObject (readonly)

Returns the value of attribute children.



9
10
11
# File 'lib/inprovise/script.rb', line 9

def children
  @children
end

#dependenciesObject (readonly)

Returns the value of attribute dependencies.



9
10
11
# File 'lib/inprovise/script.rb', line 9

def dependencies
  @dependencies
end

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/inprovise/script.rb', line 9

def name
  @name
end

#userObject (readonly)

Returns the value of attribute user.



9
10
11
# File 'lib/inprovise/script.rb', line 9

def user
  @user
end

Instance Method Details

#action(name, &definition) ⇒ Object



147
148
149
# File 'lib/inprovise/script.rb', line 147

def action(name, &definition)
  @actions[name] = definition
end

#apply(&definition) ⇒ Object



135
136
137
# File 'lib/inprovise/script.rb', line 135

def apply(&definition)
  command(:apply, &definition)
end

#as(user) ⇒ Object



143
144
145
# File 'lib/inprovise/script.rb', line 143

def as(user)
  @user = user
end

#command(name, &definition) ⇒ Object



151
152
153
154
155
156
157
# File 'lib/inprovise/script.rb', line 151

def command(name, &definition)
  if block_given?
    (@commands[name.to_sym] ||= []) << definition
  else
    @commands[name.to_sym] ||= []
  end
end

#configuration(cfg = nil) ⇒ Object



76
77
78
79
# File 'lib/inprovise/script.rb', line 76

def configuration(cfg=nil)
  @configuration = cfg if cfg
  @configuration
end

#depends_on(*scr_names) ⇒ Object



119
120
121
122
123
# File 'lib/inprovise/script.rb', line 119

def depends_on(*scr_names)
  scr_names.each do |scr_name|
    @dependencies << scr_name
  end
end

#describeObject



70
71
72
73
74
# File 'lib/inprovise/script.rb', line 70

def describe
  return [self.name] unless self.description
  nm = [self.name]
  self.description.split("\n").collect {|ld| "#{"%-25s" % nm.shift.to_s}\t#{ld.strip}"}
end

#description(desc = nil) ⇒ Object



65
66
67
68
# File 'lib/inprovise/script.rb', line 65

def description(desc=nil)
  @description = desc if desc
  @description
end

#merge_configuration(config) ⇒ Object



113
114
115
116
117
# File 'lib/inprovise/script.rb', line 113

def merge_configuration(config)
  return unless self.configuration
  script_cfg = copy_config(self.configuration)
  config[self.name.to_sym] = merge_config(config[self.name.to_sym], script_cfg)
end

#provides_command?(name) ⇒ Boolean

Returns:

  • (Boolean)


159
160
161
# File 'lib/inprovise/script.rb', line 159

def provides_command?(name)
  @commands.has_key?(name.to_sym)
end

#revert(&definition) ⇒ Object



139
140
141
# File 'lib/inprovise/script.rb', line 139

def revert(&definition)
  command(:revert, &definition)
end

#to_sObject



163
164
165
# File 'lib/inprovise/script.rb', line 163

def to_s
  self.name
end

#triggers(*scr_names) ⇒ Object



125
126
127
128
129
# File 'lib/inprovise/script.rb', line 125

def triggers(*scr_names)
  scr_names.each do |scr_name|
    @children << scr_name
  end
end

#validate(&definition) ⇒ Object



131
132
133
# File 'lib/inprovise/script.rb', line 131

def validate(&definition)
  command(:validate, &definition)
end