Class: DevelopWithPassion::Expander::Expansion

Inherits:
Object
  • Object
show all
Defined in:
lib/developwithpassion_expander/expansion.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeExpansion

Returns a new instance of Expansion.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/developwithpassion_expander/expansion.rb', line 6

def initialize
  initialize_hashes :files_to_merge,:copies

  @globber = lambda{|path| return glob(path)}

  array :cleanup_items do|a| 
    a.readable
    a.process_using :run_cleanup,:call 
  end

  array :setup_items do|a| 
    a.readable
    a.process_using :run_setup_items,:call 
  end

  array :executable_files do|a|
    a.mutator :register_executable
    a.process_using :mark_files_executable,ShellActionAgainstFile.new("chmod +x")
  end

  array :files_with_line_endings_to_fix do|a|
    a.mutator :fix_line_endings_for
    a.process_using :fix_line_endings,ShellActionAgainstFile.new("d2u")
  end

  array :folders_to_purge do|a|
    a.mutator :register_folder_to_purge
    a.process_using :purge_targets,ShellActionAgainstFile.new("rm -rf")
  end
end

Instance Attribute Details

#copiesObject

Returns the value of attribute copies.



4
5
6
# File 'lib/developwithpassion_expander/expansion.rb', line 4

def copies
  @copies
end

#files_to_mergeObject

Returns the value of attribute files_to_merge.



4
5
6
# File 'lib/developwithpassion_expander/expansion.rb', line 4

def files_to_merge
  @files_to_merge
end

#globberObject

Returns the value of attribute globber.



4
5
6
# File 'lib/developwithpassion_expander/expansion.rb', line 4

def globber
  @globber
end

Instance Method Details

#before(&block) ⇒ Object



53
54
55
# File 'lib/developwithpassion_expander/expansion.rb', line 53

def before(&block)
  @setup_items << block
end

#cleanup(&block) ⇒ Object



49
50
51
# File 'lib/developwithpassion_expander/expansion.rb', line 49

def cleanup(&block)
  @cleanup_items << block
end

#copy_to(target, &block) ⇒ Object



37
38
39
# File 'lib/developwithpassion_expander/expansion.rb', line 37

def copy_to target,&block
  hash_process(target,@copies,lambda{|key| return Copy.new(CopyToTarget.new(key))},&block)
end

#expand_itemsObject



73
74
75
# File 'lib/developwithpassion_expander/expansion.rb', line 73

def expand_items
  @copies.process_all_values_using{|copy| copy.run}
end

#hash_process(target, hash, factory, &block) ⇒ Object



68
69
70
71
72
# File 'lib/developwithpassion_expander/expansion.rb', line 68

def hash_process(target,hash,factory,&block)
  symbol = target.to_sym
  hash[symbol] = factory.call(target) unless hash.has_key?(symbol)
  hash[symbol].instance_eval(&block)
end

#look_for_templates_in(path) ⇒ Object



45
46
47
# File 'lib/developwithpassion_expander/expansion.rb', line 45

def look_for_templates_in(path)
  @globber.call(path).process_all_items_using(TemplateVisitor.instance)
end

#merge_itemsObject



76
77
78
# File 'lib/developwithpassion_expander/expansion.rb', line 76

def merge_items
  @files_to_merge.process_all_values_using{|merge| merge.run}
end

#merge_to(target, &block) ⇒ Object



41
42
43
# File 'lib/developwithpassion_expander/expansion.rb', line 41

def merge_to target,&block
  hash_process(target,@files_to_merge,lambda{|key| return FileMerge.new(key)},&block)
end

#runObject



57
58
59
60
61
62
63
64
65
# File 'lib/developwithpassion_expander/expansion.rb', line 57

def run
  run_setup_items
  purge_targets
  expand_items
  merge_items
  run_cleanup
  fix_line_endings 
  mark_files_executable
end