Class: Cukedep::ActionTriplet

Inherits:
Object
  • Object
show all
Defined in:
lib/cukedep/file-action.rb

Overview

An (file) action triplet combines three FileActions that are executed in sequence.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(theActionSettings) ⇒ ActionTriplet

[theActionSettings] An object that responds to the [] operator. The argument of the operator must be: :save_patterns, :save_subdir, :delete_patterns, :delete_subdir, :copy_patterns, :copy_subdir



154
155
156
157
158
159
160
161
# File 'lib/cukedep/file-action.rb', line 154

def initialize(theActionSettings)
  @save_action = CopyAction.new(theActionSettings[:save_patterns],
                                theActionSettings[:save_subdir])
  @delete_action = DeleteAction.new(theActionSettings[:delete_patterns],
                                    theActionSettings[:delete_subdir])
  @copy_action = CopyAction.new(theActionSettings[:copy_patterns],
                                theActionSettings[:copy_subdir])
end

Instance Attribute Details

#copy_actionObject (readonly)

Returns the value of attribute copy_action.



148
149
150
# File 'lib/cukedep/file-action.rb', line 148

def copy_action
  @copy_action
end

#delete_actionObject (readonly)

Returns the value of attribute delete_action.



147
148
149
# File 'lib/cukedep/file-action.rb', line 147

def delete_action
  @delete_action
end

#save_actionObject (readonly)

Returns the value of attribute save_action.



146
147
148
# File 'lib/cukedep/file-action.rb', line 146

def save_action
  @save_action
end

Class Method Details

.builtin(anEvent) ⇒ Object

Retrieve the 'built-in' action triplet associated with the given event. Return nil if no triplet was found for the event.



180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/cukedep/file-action.rb', line 180

def self.builtin(anEvent)
  @@builtin_actions ||= {
    before_each: ActionTriplet.new(
      save_patterns: [],
      save_subdir: '',
      delete_patterns: ['*.feature'],
      delete_subdir: './features',
      copy_patterns: [],
      copy_subdir: './features'
    ),
    after_each: ActionTriplet.new(
      save_patterns: [],
      save_subdir: '',
      delete_patterns: ['*.feature'], # Remove feature files after the run
      delete_subdir: './features',
      copy_patterns: [],
      copy_subdir: ''
    )
  }

  return @@builtin_actions.fetch(anEvent, nil)
end

Instance Method Details

#==(other) ⇒ Object



163
164
165
166
167
168
169
# File 'lib/cukedep/file-action.rb', line 163

def ==(other)
  return true if object_id == other.object_id

  return (save_action == other.save_action) &&
         (delete_action == other.delete_action) &&
         (copy_action == other.copy_action)
end

#run!(currentDir, projectDir) ⇒ Object

Launch the file actions in sequence.



172
173
174
175
176
# File 'lib/cukedep/file-action.rb', line 172

def run!(currentDir, projectDir)
  save_action.run!(projectDir, currentDir)
  delete_action.run!(projectDir)
  copy_action.run!(currentDir, projectDir)
end