Class: Inprovise::Script

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

Overview

Script base class for Inprovise

Author

Martin Corino

License

Distributes under the same license as Ruby

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.



7
8
9
# File 'lib/inprovise/script.rb', line 7

def actions
  @actions
end

#childrenObject (readonly)

Returns the value of attribute children.



7
8
9
# File 'lib/inprovise/script.rb', line 7

def children
  @children
end

#configurationObject (readonly)

Returns the value of attribute configuration.



7
8
9
# File 'lib/inprovise/script.rb', line 7

def configuration
  @configuration
end

#dependenciesObject (readonly)

Returns the value of attribute dependencies.



7
8
9
# File 'lib/inprovise/script.rb', line 7

def dependencies
  @dependencies
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/inprovise/script.rb', line 7

def name
  @name
end

#userObject (readonly)

Returns the value of attribute user.



7
8
9
# File 'lib/inprovise/script.rb', line 7

def user
  @user
end

Instance Method Details

#action(name, &definition) ⇒ Object



117
118
119
# File 'lib/inprovise/script.rb', line 117

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

#apply(&definition) ⇒ Object



105
106
107
# File 'lib/inprovise/script.rb', line 105

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

#as(user) ⇒ Object



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

def as(user)
  @user = user
end

#command(name, &definition) ⇒ Object



121
122
123
124
125
126
127
# File 'lib/inprovise/script.rb', line 121

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

#configure(cfg = nil, &definition) ⇒ Object



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

def configure(cfg=nil, &definition)
  @configuration = Inprovise::Config.new.merge!(cfg) if cfg
  command(:configure, &definition)
  @configuration
end

#depends_on(*scr_names) ⇒ Object



89
90
91
92
93
# File 'lib/inprovise/script.rb', line 89

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

#provides_command?(name) ⇒ Boolean

Returns:

  • (Boolean)


129
130
131
# File 'lib/inprovise/script.rb', line 129

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

#revert(&definition) ⇒ Object



109
110
111
# File 'lib/inprovise/script.rb', line 109

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

#to_sObject



133
134
135
# File 'lib/inprovise/script.rb', line 133

def to_s
  self.name
end

#triggers(*scr_names) ⇒ Object



95
96
97
98
99
# File 'lib/inprovise/script.rb', line 95

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

#update_configuration(context) ⇒ Object



82
83
84
85
86
87
# File 'lib/inprovise/script.rb', line 82

def update_configuration(context)
  context.config[self.name.to_sym] ||= Inprovise::Config.new
  if @configuration
    context.config[self.name.to_sym].update!(@configuration)
  end
end

#validate(&definition) ⇒ Object



101
102
103
# File 'lib/inprovise/script.rb', line 101

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