Class: Dappgen::Machines::DryRunMachine
- Inherits:
-
Object
- Object
- Dappgen::Machines::DryRunMachine
- Defined in:
- lib/dappgen/machines/dry_run_machine.rb
Instance Method Summary collapse
- #arrayize(hash) ⇒ Object
- #cleanup(_) ⇒ Object
- #copy_base(source) ⇒ Object
- #generate(name, opts) ⇒ Object
- #remove(name) ⇒ Object
- #set_thing(thing, opts) ⇒ Object
- #setdir(name) ⇒ Object
Instance Method Details
#arrayize(hash) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/dappgen/machines/dry_run_machine.rb', line 96 def arrayize(hash) result = [] hash.each do |k, v| if v.empty? result << k else result << { k => arrayize(v) } end end result.sort_by do |x| if x.is_a? Hash -x.length else 0 end end end |
#cleanup(_) ⇒ Object
91 92 93 94 |
# File 'lib/dappgen/machines/dry_run_machine.rb', line 91 def cleanup(_) puts "The following is a #{@thing} that would be generated" puts arrayize(@tree).to_yaml end |
#copy_base(source) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/dappgen/machines/dry_run_machine.rb', line 23 def copy_base(source) if source.nil? Dir["#{@static_files_dir}/**/*"].each do |object| rel_path = object.sub(%r{^#{@static_files_dir}/}, '') branch = @tree[@cur_dir_name] levels = rel_path.split('/') levels[0..-1].each do |level| branch[level] = {} if branch[level].nil? branch = branch[level] end end else `rm -rf .tmp` `git clone #{source} .tmp` Dir[".tmp/**/*"].each do |object| rel_path = object.sub(%r{^.tmp/}, '') branch = @tree[@cur_dir_name] levels = rel_path.split('/') levels[0..-1].each do |level| branch[level] = {} if branch[level].nil? branch = branch[level] end end `rm -rf .tmp` end Dir["#{@replacer_files_dir}/**/*"].each do |object| rel_path = object.sub(%r{^#{@replacer_files_dir}/}, '').sub(/.erb$/, '') branch = @tree[@cur_dir_name] levels = rel_path.split('/') levels[0..-1].each do |level| branch[level] = {} if branch[level].nil? branch = branch[level] end end end |
#generate(name, opts) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/dappgen/machines/dry_run_machine.rb', line 79 def generate(name, opts) rel_path = File.join @cur_dir_name, name branch = @tree levels = rel_path.split('/') levels[0..-1].each do |level| branch[level] = {} if branch[level].nil? branch = branch[level] end end |
#remove(name) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/dappgen/machines/dry_run_machine.rb', line 66 def remove(name) rel_path = File.join @cur_dir_name, name branch = @tree levels = rel_path.split('/') levels[0..-2].each do |level| branch = branch[level] end branch.delete(levels[-1]) end |
#set_thing(thing, opts) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/dappgen/machines/dry_run_machine.rb', line 8 def set_thing(thing, opts) @tree = {} @thing = thing @opts = Hashie::Mash.new(opts[:opts]) @base_data_dir = File.join(Gem.loaded_specs['dappgen'].full_gem_path, 'data', 'dappgen', 'generators', thing) @static_files_dir = File.join(@base_data_dir, 'base') @replacer_files_dir = File.join(@base_data_dir, 'replacers') @template_files_dir = File.join(@base_data_dir, 'templates') end |
#setdir(name) ⇒ Object
18 19 20 21 |
# File 'lib/dappgen/machines/dry_run_machine.rb', line 18 def setdir(name) @tree[name] = {} @cur_dir_name = name end |