class Cog::Helpers::CascadingSet
@api developer
Public Class Methods
new()
click to toggle source
# File lib/cog/helpers/cascading_set.rb, line 59 def initialize @info = {} end
process_paths(paths, opt={})
click to toggle source
Look for sources in each of the given paths @param paths [Array<String>] a list of file system paths containing sources @option opt [String] :ext File extension of sources to glob for in each path @return [Array<String>] formatted listing of the sources
# File lib/cog/helpers/cascading_set.rb, line 67 def self.process_paths(paths, opt={}) cs = Helpers::CascadingSet.new paths.each_with_cog_source do |source, type, path| opt[:source] = source opt[:type] = type opt[:root_dir] = path cs.add_sources opt end cs.to_a end
Public Instance Methods
add_plugin(plugin, opt={})
click to toggle source
@param plugin [Plugin] name of the plugin
# File lib/cog/helpers/cascading_set.rb, line 91 def add_plugin(plugin, opt={}) @info[plugin.name] ||= SourceInfo.new plugin.name @info[plugin.name].path = plugin.path if Cog.show_fullpaths? @info[plugin.name].add_source *plugin.path.cog_source_and_type end
add_sources(opt={})
click to toggle source
@option opt [String] :source (nil) the name of the source @option opt [Symbol] :type (nil) must be one of :built_in
, :user
, :plugin
, or :project
@option opt [String] :root_dir (nil) directory in which to look for sources
# File lib/cog/helpers/cascading_set.rb, line 81 def add_sources(opt={}) Dir.glob("#{opt[:root_dir]}/**/*.#{opt[:ext]}") do |path| name = path.relative_to(opt[:root_dir]).slice(0..-(2 + opt[:ext].length)) @info[name] ||= SourceInfo.new name @info[name].path = path if Cog.show_fullpaths? @info[name].add_source opt[:source], opt[:type] end end
to_a()
click to toggle source
# File lib/cog/helpers/cascading_set.rb, line 97 def to_a w = @info.values.collect {|t| t.override_s.length}.max @info.values.sort.collect {|t| t.to_s(w)} end