Module: VR
- Defined in:
- lib/DragDrop.rb,
lib/Alert.rb,
lib/Tools.rb,
lib/SavableClass.rb,
lib/treeview/TreeView.rb,
lib/treeview/ListView.rb,
lib/treeview/ViewCommon.rb,
lib/treeview/FileTreeView.rb
Overview
The main namespace for visualruby.
Defined Under Namespace
Modules: Col, Draggable, Droppable, ObjectInspector, ViewCommon Classes: Alert, FileTreeView, ListView, TreeView
Class Method Summary collapse
- .copy_recursively(from, out_dir) ⇒ Object
-
.load_yaml(klass, file_name, *args) ⇒ Object
Loads or creates a yaml file with a given object type (class).
-
.save_yaml(obj, file_name = nil) ⇒ Object
Saves an object likely loaded with #load_yaml to disk.
Class Method Details
.copy_recursively(from, out_dir) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/Tools.rb', line 3 def VR.copy_recursively(from, out_dir) Find.find(from) do |path| next if path == from rel_path = path.gsub(from, "") if File.directory?(path) FileUtils.makedirs(out_dir + rel_path) else if not File.directory?(out_dir + File.dirname(rel_path)) FileUtils.makedirs(out_dir + File.dirname(rel_path)) end FileUtils.copy(path, out_dir + rel_path) end end end |
.load_yaml(klass, file_name, *args) ⇒ Object
Loads or creates a yaml file with a given object type (class). If the file exists already, the object will be returned. If not, a new instance will be returned, and the file will instantly be saved.
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/SavableClass.rb', line 10 def self.load_yaml(klass, file_name, *args) me = nil if File.file?(file_name) me = YAML.load(File.open(file_name).read) else me = klass.new(*args) end file_name = File.(file_name) me.instance_variable_set(:@vr_yaml_file, file_name) me.defaults() if me.respond_to?(:defaults) VR::save_yaml(me) return me end |
.save_yaml(obj, file_name = nil) ⇒ Object
Saves an object likely loaded with #load_yaml to disk.
29 30 31 32 33 34 35 36 37 |
# File 'lib/SavableClass.rb', line 29 def self.save_yaml(obj, file_name = nil) file_name ||= obj.instance_variable_get(:@vr_yaml_file) @vr_yaml_file = file_name dir = File.dirname(file_name) unless File.directory?(dir) FileUtils.mkdir_p(dir) end File.open(file_name, "w") {|f| f.puts(obj.to_yaml)} end |