Sha256: 0829ce23bf436323b8761fee04406edc67102249c2f755d536b4e4a49aa21250

Contents?: true

Size: 1.14 KB

Versions: 44

Compression:

Stored size: 1.14 KB

Contents

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

    def self.home_apps_path
      Brief.home.join("apps")
    end

    def self.search_paths
      paths = [default_path]

      paths << home_apps_path if home_apps_path.exist?

      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

44 entries across 44 versions & 1 rubygems

Version Path
brief-1.17.14 lib/brief/apps.rb
brief-1.17.13 lib/brief/apps.rb
brief-1.17.12 lib/brief/apps.rb
brief-1.17.11 lib/brief/apps.rb
brief-1.17.10 lib/brief/apps.rb
brief-1.17.9 lib/brief/apps.rb
brief-1.17.8 lib/brief/apps.rb
brief-1.17.7 lib/brief/apps.rb
brief-1.17.5 lib/brief/apps.rb
brief-1.17.4 lib/brief/apps.rb
brief-1.17.3 lib/brief/apps.rb
brief-1.17.2 lib/brief/apps.rb
brief-1.17.1 lib/brief/apps.rb
brief-1.17.0 lib/brief/apps.rb
brief-1.16.2 lib/brief/apps.rb
brief-1.16.1 lib/brief/apps.rb
brief-1.16.0 lib/brief/apps.rb
brief-1.15.5 lib/brief/apps.rb
brief-1.15.4 lib/brief/apps.rb
brief-1.15.3 lib/brief/apps.rb