Sha256: 6dc0fd25141380c4158f09fe5963d095db86788c49b2af5194f8dcb6097f8af2

Contents?: true

Size: 1.26 KB

Versions: 103

Compression:

Stored size: 1.26 KB

Contents

module ActiveScaffold
  def self.bridge(name, &block)
    ActiveScaffold::Bridge.new(name, &block)
  end
  
  class Bridge
    attr_accessor :name
    cattr_accessor :bridges
    cattr_accessor :bridges_run
    self.bridges = []
    
    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::Bridge.bridges << self
    end
    
    # Set the install block
    def install(&block)
      @install = block
    end
    
    # Set the install_if block (to check to see whether or not to install the block)
    def install?(&block)
      @install_if = block
    end
    
    
    def run
      raise(ArgumentError, "install and install? not defined for bridge #{name}" ) unless @install && @install_if
      @install.call if @install_if.call
    end
    
    def self.run_all
      return false if self.bridges_run
      ActiveScaffold::Bridge.bridges.each{|bridge|
        bridge.run
      }
      
      
      self.bridges_run=true
    end
  end
end

Dir[File.join(File.dirname(__FILE__), "*/bridge.rb")].each{|bridge_require|
  require bridge_require
} 

Version data entries

103 entries across 103 versions & 4 rubygems

Version Path
brisk-bills-0.8.2 vendor/plugins/active_scaffold/lib/bridges/bridge.rb
brisk-bills-0.8.1 vendor/plugins/active_scaffold/lib/bridges/bridge.rb
six-updater-web-0.24.15 lib/six-updater-web/vendor/plugins/active_scaffold/lib/bridges/bridge.rb
six-updater-web-0.24.14 lib/six-updater-web/vendor/plugins/active_scaffold/lib/bridges/bridge.rb
six-updater-web-0.24.13 lib/six-updater-web/vendor/plugins/active_scaffold/lib/bridges/bridge.rb
six-updater-web-0.24.12 lib/six-updater-web/vendor/plugins/active_scaffold/lib/bridges/bridge.rb
six-updater-web-0.24.11 lib/six-updater-web/vendor/plugins/active_scaffold/lib/bridges/bridge.rb
six-updater-web-0.24.10 lib/six-updater-web/vendor/plugins/active_scaffold/lib/bridges/bridge.rb
six-updater-web-0.24.9 lib/six-updater-web/vendor/plugins/active_scaffold/lib/bridges/bridge.rb
six-updater-web-0.24.8 lib/six-updater-web/vendor/plugins/active_scaffold/lib/bridges/bridge.rb
six-updater-web-0.24.7 lib/six-updater-web/vendor/plugins/active_scaffold/lib/bridges/bridge.rb
six-updater-web-0.24.6 lib/six-updater-web/vendor/plugins/active_scaffold/lib/bridges/bridge.rb
six-updater-web-0.24.5 lib/six-updater-web/vendor/plugins/active_scaffold/lib/bridges/bridge.rb
brisk-bills-0.7.0 vendor/plugins/active_scaffold/lib/bridges/bridge.rb
six-updater-web-0.24.4 lib/six-updater-web/vendor/plugins/active_scaffold/lib/bridges/bridge.rb
six-updater-web-0.24.3 lib/six-updater-web/vendor/plugins/active_scaffold/lib/bridges/bridge.rb
six-updater-web-0.24.2 lib/six-updater-web/vendor/plugins/active_scaffold/lib/bridges/bridge.rb
six-updater-web-0.24.1 lib/six-updater-web/vendor/plugins/active_scaffold/lib/bridges/bridge.rb
six-updater-web-0.24.0 lib/six-updater-web/vendor/plugins/active_scaffold/lib/bridges/bridge.rb
six-updater-web-0.23.7 lib/six-updater-web/vendor/plugins/active_scaffold/lib/bridges/bridge.rb