Class: Sqrbl::StepPair

Inherits:
Object show all
Includes:
ExpectsBlockWithNew, HasTodos, MethodMissingDelegation
Defined in:
lib/sqrbl/step_pair.rb

Overview

Like the Group class, StepPair doesn’t do much on its own. It’s basically a container for two Step objects, which are created using up and down. These two steps will usually, but not always, have a one-to-one correspondence in their actions. (For example, a temp table may take a number of actions to create and populate, but removing it just takes a “DROP TABLE” statement.)

  • The up_step describes the actions necessary to move the source data one step closer to the target format.

  • The down_step describes the actions necessary to undo the actions taken by the up_step.

StepPair delegates method_missing calls to its group object. For more information, see MethodMissingDelegation.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HasTodos

#todo, #todos, #warning

Methods included from MethodMissingDelegation

included

Constructor Details

#initialize(group, description, options = {}, &block) ⇒ StepPair

Returns a new instance of StepPair.



29
30
31
32
33
34
35
# File 'lib/sqrbl/step_pair.rb', line 29

def initialize(group, description, options = {}, &block)
  @group       = group
  @description = description
  @block       = lambda(&block)

  eval_block_on_initialize(options)
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



21
22
23
# File 'lib/sqrbl/step_pair.rb', line 21

def block
  @block
end

#descriptionObject (readonly)

Returns the value of attribute description.



21
22
23
# File 'lib/sqrbl/step_pair.rb', line 21

def description
  @description
end

#down_stepObject (readonly)

Returns the value of attribute down_step.



22
23
24
# File 'lib/sqrbl/step_pair.rb', line 22

def down_step
  @down_step
end

#groupObject (readonly)

Returns the value of attribute group.



21
22
23
# File 'lib/sqrbl/step_pair.rb', line 21

def group
  @group
end

#up_stepObject (readonly)

Returns the value of attribute up_step.



22
23
24
# File 'lib/sqrbl/step_pair.rb', line 22

def up_step
  @up_step
end

Instance Method Details

#down(&block) ⇒ Object

Create a Step object, passing it the block.



43
44
45
# File 'lib/sqrbl/step_pair.rb', line 43

def down(&block)
  @down_step = Step.new(self, &block)
end

#unix_nameObject



52
53
54
# File 'lib/sqrbl/step_pair.rb', line 52

def unix_name
  Sqrbl.calculate_unix_name(description)
end

#up(&block) ⇒ Object

Create a Step object, passing it the block.



38
39
40
# File 'lib/sqrbl/step_pair.rb', line 38

def up(&block)
  @up_step = Step.new(self, &block)
end

#valid?Boolean

A StepPair is valid if both the up_step and the down_step have been created as Step objects.

Returns:

  • (Boolean)


48
49
50
# File 'lib/sqrbl/step_pair.rb', line 48

def valid?
  [up_step, down_step].all? { |step| step.kind_of?(Step) }
end