Class: Cog::Helpers::CascadingSet
- Inherits:
-
Object
- Object
- Cog::Helpers::CascadingSet
- Defined in:
- lib/cog/helpers/cascading_set.rb
Class Method Summary collapse
-
.process_paths(paths, opt = {}) ⇒ Array<String>
Look for sources in each of the given paths.
Instance Method Summary collapse
- #add_plugin(plugin, opt = {}) ⇒ Object
- #add_sources(opt = {}) ⇒ Object
-
#initialize ⇒ CascadingSet
constructor
A new instance of CascadingSet.
- #to_a ⇒ Object
Constructor Details
#initialize ⇒ CascadingSet
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
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
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
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_a ⇒ Object
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 |