Sha256: 843d4e2cf0227eaf5abe5fb9975dd57b038b06efe9bc1faee5c13971a3094be7

Contents?: true

Size: 1.31 KB

Versions: 1

Compression:

Stored size: 1.31 KB

Contents

module ActiveScaffold
  module Bridges
    def self.bridge(name, &block)
      ActiveScaffold::Bridges::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::Bridges::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
        self.bridges.each(&:run) unless self.bridges_run
        self.bridges_run = true
      end
    end
  end
end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
active_scaffold-3.0.5 lib/active_scaffold/bridges/bridge.rb