Class: Cog::Helpers::CascadingSet

Inherits:
Object
  • Object
show all
Defined in:
lib/cog/helpers/cascading_set.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCascadingSet

Returns a new instance of CascadingSet.



59
60
61
# File 'lib/cog/helpers/cascading_set.rb', line 59

def initialize
  @info = {}
end

Class Method Details

.process_paths(paths, opt = {}) ⇒ Array<String>

Look for sources in each of the given paths

Parameters:

  • paths (Array<String>)

    a list of file system paths containing sources

  • opt (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opt):

  • :ext (String)

    File extension of sources to glob for in each path

Returns:



67
68
69
70
71
72
73
74
75
76
# 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

Instance Method Details

#add_plugin(plugin, opt = {}) ⇒ Object

Parameters:

  • plugin (Plugin)

    name of the plugin



91
92
93
94
95
# 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 = {}) ⇒ Object

Parameters:

  • opt (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opt):

  • :source (String) — default: nil

    the name of the source

  • :type (Symbol) — default: nil

    must be one of :built_in, :user, :plugin, or :project

  • :root_dir (String) — default: nil

    directory in which to look for sources



81
82
83
84
85
86
87
88
# 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_aObject



97
98
99
100
# 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