Sha256: c38cf13b1d7e07573a90b1954a8497a0362365be4697f0871cd09a28b5f2be24

Contents?: true

Size: 1.87 KB

Versions: 24

Compression:

Stored size: 1.87 KB

Contents

module ActiveScaffold
  module Bridges
    ActiveScaffold.autoload_subdir('bridges', self)
    module Shared
      autoload :DateBridge, 'active_scaffold/bridges/shared/date_bridge'
    end

    mattr_accessor :bridges
    mattr_accessor :bridges_run
    mattr_accessor :bridges_prepared
    self.bridges = {}

    def self.register(file)
      match = file.match(%r{(active_scaffold/bridges/(.*))\.rb\Z})
      bridges[match[2].to_sym] = match[1] if match
    end

    def self.load(bridge_name)
      bridge = bridges[bridge_name.to_sym]
      if bridge.is_a? String
        if ActiveScaffold.exclude_bridges.exclude? bridge_name.to_sym
          bridge = bridge.camelize.constantize
          bridges[bridge_name.to_sym] = bridge
        else
          bridges.delete bridge_name
          bridge = nil
        end
      end
      bridge
    end
    class << self
      alias [] load
    end

    def self.run_all
      return false if bridges_run
      bridges.each_key do |bridge_name|
        self[bridge_name]&.run
      end
      ActiveScaffold::Config::Core.freeze if ActiveScaffold.threadsafe
      self.bridges_run = true
    end

    def self.prepare_all
      return false if bridges_prepared
      bridges.each_key do |bridge_name|
        bridge = self[bridge_name]
        bridge.prepare if bridge&.install?
      end
      self.bridges_prepared = true
    end

    def self.all_stylesheets
      bridges.keys.collect do |bridge_name|
        bridge = self[bridge_name]
        bridge.stylesheets if bridge&.install?
      end.compact.flatten
    end

    def self.all_javascripts
      bridges.keys.collect do |bridge_name|
        bridge = self[bridge_name]
        bridge.javascripts if bridge&.install?
      end.compact.flatten
    end
  end
end

Dir[File.join(File.dirname(__FILE__), 'bridges/*.rb')].each do |bridge|
  ActiveScaffold::Bridges.register bridge unless bridge == __FILE__
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
active_scaffold-3.7.0 lib/active_scaffold/bridges.rb
active_scaffold-3.6.20 lib/active_scaffold/bridges.rb
active_scaffold-3.6.19 lib/active_scaffold/bridges.rb
active_scaffold-3.6.17 lib/active_scaffold/bridges.rb
active_scaffold-3.6.15 lib/active_scaffold/bridges.rb
active_scaffold-3.6.14 lib/active_scaffold/bridges.rb
active_scaffold-3.6.13 lib/active_scaffold/bridges.rb
active_scaffold-3.6.12 lib/active_scaffold/bridges.rb
active_scaffold-3.6.11.1 lib/active_scaffold/bridges.rb
active_scaffold-3.6.11 lib/active_scaffold/bridges.rb
active_scaffold-3.6.10 lib/active_scaffold/bridges.rb
active_scaffold-3.6.9 lib/active_scaffold/bridges.rb
active_scaffold-3.6.8 lib/active_scaffold/bridges.rb
active_scaffold-3.6.6 lib/active_scaffold/bridges.rb
active_scaffold-3.6.5 lib/active_scaffold/bridges.rb
active_scaffold-3.6.4.1 lib/active_scaffold/bridges.rb
active_scaffold-3.6.4 lib/active_scaffold/bridges.rb
active_scaffold-3.6.3 lib/active_scaffold/bridges.rb
active_scaffold-3.6.2 lib/active_scaffold/bridges.rb
active_scaffold-3.6.1 lib/active_scaffold/bridges.rb