class Classifile::State
Class that manages the current state. The DSL code will be executed on an instance of this class A State
is created for each dir and group.
Attributes
additional_filename[RW]
after_save_syms[RW]
empty[RW]
empty?[RW]
file[RW]
gotcha[R]
save_name[RW]
to_path[RW]
Public Class Methods
new(file)
click to toggle source
Calls superclass method
# File lib/classifile/state.rb, line 23 def initialize(file) @file = file @empty = false @extname = @file.extname @name = @file.basename @gotcha = nil super() end
Public Instance Methods
after_save(method_name)
click to toggle source
# File lib/classifile/state.rb, line 57 def after_save(method_name) @after_save_syms << method_name end
dir(dir_name, &block)
click to toggle source
# File lib/classifile/state.rb, line 32 def dir(dir_name, &block) return if @gotcha child = make_child dir_name child.instance_exec(@file, &block) if child.gotcha @gotcha = child.gotcha else raise Failed if dir_name.empty? || child.empty? gotcha_child(child) end rescue Failed # Ignored end
empty_dir!()
click to toggle source
# File lib/classifile/state.rb, line 53 def empty_dir! @empty = true end
group(_group_name = "", &block)
click to toggle source
# File lib/classifile/state.rb, line 49 def group(_group_name = "", &block) dir("", &block) end
Private Instance Methods
gotcha_child(child)
click to toggle source
# File lib/classifile/state.rb, line 63 def gotcha_child(child) @gotcha = FromTo.new(File.expand_path(@file.full_path), File.expand_path(File.join(child.to_path, child.save_name))) child.after_save_syms.each do |sym| @gotcha.after_save_procs << child.method(sym) end end
make_child(dir_name)
click to toggle source
# File lib/classifile/state.rb, line 71 def make_child(dir_name) child = clone child.to_path = File.join(@to_path, dir_name) child.file.to_path = File.join(child.to_path, child.file.basename) child.empty = false child.after_save_syms = [] child end