Class: ActiveScaffold::Bridges::Bridge

Inherits:
Object
  • Object
show all
Defined in:
lib/active_scaffold/bridges/bridge.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, &block) ⇒ Bridge

Returns a new instance of Bridge.



13
14
15
16
17
18
19
20
21
# File 'lib/active_scaffold/bridges/bridge.rb', line 13

def initialize(name, &block)
  self.name = name
  @install = nil
  # by convention and default, use the bridge name as the required constant for installation
  @install_if = lambda { Object.const_defined?(name) }
  self.instance_eval(&block)
  
  ActiveScaffold::Bridges::Bridge.bridges << self
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



8
9
10
# File 'lib/active_scaffold/bridges/bridge.rb', line 8

def name
  @name
end

Class Method Details

.run_allObject



39
40
41
42
43
44
45
# File 'lib/active_scaffold/bridges/bridge.rb', line 39

def self.run_all
  return false if self.bridges_run
  ActiveScaffold::Bridges::Bridge.bridges.each{|bridge|
    bridge.run
  }
  self.bridges_run=true
end

Instance Method Details

#install(&block) ⇒ Object

Set the install block



24
25
26
# File 'lib/active_scaffold/bridges/bridge.rb', line 24

def install(&block)
  @install = block
end

#install?(&block) ⇒ Boolean

Set the install_if block (to check to see whether or not to install the block)

Returns:

  • (Boolean)


29
30
31
# File 'lib/active_scaffold/bridges/bridge.rb', line 29

def install?(&block)
  @install_if = block
end

#runObject

Raises:

  • (ArgumentError)


34
35
36
37
# File 'lib/active_scaffold/bridges/bridge.rb', line 34

def run
  raise(ArgumentError, "install and install? not defined for bridge #{name}" ) unless @install && @install_if
  @install.call if @install_if.call
end