Sha256: aeed851f25a39ddb8110d22975c6d13b37ba172882d4699f89ab8c5a54f6b1f5

Contents?: true

Size: 1.01 KB

Versions: 3

Compression:

Stored size: 1.01 KB

Contents

require 'active_support/core_ext'
require 'rails/initializable'

class Jax::Plugin < Jax::Engine
  autoload :Manifest, 'jax/plugin/manifest'
  
  attr_reader :relative_path
  
  class << self
    def all(list, paths)
      plugins = []
      paths.each do |path|
        Dir["#{path}/*"].each do |plugin_path|
          plugin = new(plugin_path)
          next unless list.include?(plugin.name) || list.include?(:all)
          plugins << plugin
        end
      end

      plugins.sort_by do |p|
        [list.index(p.name) || list.index(:all), p.name.to_s]
      end
    end
  end
  
  def initialize(path)
    super()
    @relative_path = path.sub(/^#{Regexp::escape Jax.root.to_s}\/?/, '')
  end
  
  def manifest
    @manifest ||= begin
      manifest = Jax::Plugin::Manifest.new(name)
      manifest.load
    end
  end
  
  def full_path
    File.expand_path(relative_path, Jax.root)
  end
  
  def name
    File.basename(relative_path)
  end
  
  def config
    @config ||= Jax::Engine::Configuration.new(full_path)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
jax-1.1.1 lib/jax/plugin.rb
jax-1.1.0 lib/jax/plugin.rb
jax-1.1.0.rc1 lib/jax/plugin.rb