Sha256: bde77f8152ddc68ddf66479852edd7b49989599c83212a8be569ffb238ed5008

Contents?: true

Size: 1.02 KB

Versions: 24

Compression:

Stored size: 1.02 KB

Contents

module Brief
  class Apps
    def self.default_path
      Brief.lib_root.join("..","apps")
    end

    def self.search_paths
      paths = [default_path]

      if custom_path = ENV['BRIEF_APPS_PATH']
        custom_path = custom_path.to_s.to_pathname
        paths << custom_path if (custom_path.exist? rescue nil)
      end

      paths
    end

    def self.app_paths
      search_paths.map do |base|
        base.children.select do |child|
          child.join("config.rb").exist?
        end
      end.flatten
    end

    def self.available?(app_name)
      available_apps.include?(app_name.to_s)
    end

    def self.path_for(app_name)
      app_paths.detect {|b| b.basename.to_s == app_name }
    end

    def self.available_apps
      app_paths.map(&:basename).map(&:to_s)
    end

    def self.create_namespaces
      available_apps.map(&:camelize).each do |namespace|
        const_set(namespace, Module.new)
      end
    end

    def self.find_namespace(app_name)
      Brief::Apps.const_get(app_name.to_s.camelize)
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
brief-1.11.3 lib/brief/apps.rb
brief-1.11.2 lib/brief/apps.rb
brief-1.11.1 lib/brief/apps.rb
brief-1.11.0 lib/brief/apps.rb
brief-1.10.1 lib/brief/apps.rb
brief-1.10.0 lib/brief/apps.rb
brief-1.9.14 lib/brief/apps.rb
brief-1.9.13 lib/brief/apps.rb
brief-1.9.12 lib/brief/apps.rb
brief-1.9.11 lib/brief/apps.rb
brief-1.9.9 lib/brief/apps.rb
brief-1.9.8 lib/brief/apps.rb
brief-1.9.7 lib/brief/apps.rb
brief-1.9.6 lib/brief/apps.rb
brief-1.9.4 lib/brief/apps.rb
brief-1.9.3 lib/brief/apps.rb
brief-1.9.2 lib/brief/apps.rb
brief-1.9.1 lib/brief/apps.rb
brief-1.9.0 lib/brief/apps.rb
brief-1.8.12 lib/brief/apps.rb