class Ruhoh::Cascade
Attributes
base[RW]
config[R]
system[RW]
theme[RW]
Public Class Methods
new(config)
click to toggle source
# File lib/ruhoh/cascade.rb, line 7 def initialize(config) @config = config config.add_observer(self) end
Public Instance Methods
_all_files()
click to toggle source
Collect all files from the base cascade directories. @return dictionary of file pointers
# File lib/ruhoh/cascade.rb, line 45 def _all_files dict = {} paths.map{ |a| a['path'] }.each do |path| FileUtils.cd(path) { Dir["*"].each { |id| next unless File.exist?(id) && FileTest.file?(id) dict[id] = { "id" => id, "realpath" => File.realpath(id), } } } end dict end
find_file(key)
click to toggle source
Find a file in the base cascade directories @return[Hash, nil] a single file pointer
# File lib/ruhoh/cascade.rb, line 14 def find_file(key) dict = _all_files dict[key] || dict.values.find{ |a| key == a['id'].gsub(/.[^.]+$/, '') } end
merge_data_file(key)
click to toggle source
# File lib/ruhoh/cascade.rb, line 19 def merge_data_file(key) realpaths = [] paths.map{ |a| a['path'] }.each do |path| FileUtils.cd(path) { match = Dir["*"].find { |id| File.exist?(id) && FileTest.file?(id) && id.gsub(/.[^.]+$/, '') == key } next unless match realpaths << File.realpath(match) } end return nil unless realpaths && !realpaths.empty? data = {} realpaths.each do |path| data = Ruhoh::Utils.deep_merge(data, (Ruhoh::Parse.data_file(path) || {})) end data end
paths()
click to toggle source
Default paths to the 3 levels of the cascade.
# File lib/ruhoh/cascade.rb, line 70 def paths a = [ { "name" => "system", "path" => system }, { "name" => "base", "path" => base } ] a << { "name" => "theme", "path" => theme } if theme a end
update(config_data)
click to toggle source
When config is updated
# File lib/ruhoh/cascade.rb, line 63 def update(config_data) if config_data['_theme_collection'] @theme = File.join(base, config_data['_theme_collection']) end end