Class: Expansions::Expansion
- Inherits:
-
Object
- Object
- Expansions::Expansion
show all
- Includes:
- ArrayFu, Expansions
- Defined in:
- lib/expansions/expansion.rb
Constant Summary
Constants included
from Expansions
VERSION
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Expansions
#configure, #delayed, #disable_logging, #dynamic, #enable_logging, #expand, #glob, #log, #settings
Constructor Details
Returns a new instance of Expansion.
38
39
40
41
42
43
44
45
46
|
# File 'lib/expansions/expansion.rb', line 38
def initialize
super
initialize_hashes :files_to_merge,:copies
@globber = Proc.new do |path, exclude|
glob(path, exclude)
end
end
|
Instance Attribute Details
#copies ⇒ Object
Returns the value of attribute copies.
6
7
8
|
# File 'lib/expansions/expansion.rb', line 6
def copies
@copies
end
|
#files_to_merge ⇒ Object
Returns the value of attribute files_to_merge.
7
8
9
|
# File 'lib/expansions/expansion.rb', line 7
def files_to_merge
@files_to_merge
end
|
#globber ⇒ Object
Returns the value of attribute globber.
8
9
10
|
# File 'lib/expansions/expansion.rb', line 8
def globber
@globber
end
|
Instance Method Details
#before(&block) ⇒ Object
72
73
74
|
# File 'lib/expansions/expansion.rb', line 72
def before(&block)
setup_items << block
end
|
#cleanup(&block) ⇒ Object
68
69
70
|
# File 'lib/expansions/expansion.rb', line 68
def cleanup(&block)
cleanup_items << block
end
|
#copy_to(target, &block) ⇒ Object
48
49
50
51
52
53
|
# File 'lib/expansions/expansion.rb', line 48
def copy_to(target, &block)
copy_proc = Proc.new do |key|
Copy.new(CopyToTarget.new(key))
end
hash_process(target, copies, copy_proc, &block)
end
|
#expand_items ⇒ Object
92
93
94
95
96
|
# File 'lib/expansions/expansion.rb', line 92
def expand_items
copies.process_all_values_using do |copy|
copy.run
end
end
|
#hash_process(target, hash, factory, &block) ⇒ Object
86
87
88
89
90
|
# File 'lib/expansions/expansion.rb', line 86
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, options = Hash.new(nil)) ⇒ Object
62
63
64
65
66
|
# File 'lib/expansions/expansion.rb', line 62
def look_for_templates_in(path, options=Hash.new(nil))
exclude = options.fetch(:exclude, -> (file) { false })
globber.call(path, exclude).process_all_items_using(TemplateVisitor.instance)
end
|
#merge_items ⇒ Object
98
99
100
101
102
|
# File 'lib/expansions/expansion.rb', line 98
def merge_items
files_to_merge.process_all_values_using do |merge|
merge.run
end
end
|
#merge_to(target, &block) ⇒ Object
55
56
57
58
59
60
|
# File 'lib/expansions/expansion.rb', line 55
def merge_to(target, &block)
merge_proc = Proc.new do |key|
FileMerge.new(key)
end
hash_process(target, files_to_merge, merge_proc, &block)
end
|
#run ⇒ Object
76
77
78
79
80
81
82
83
84
|
# File 'lib/expansions/expansion.rb', line 76
def run
run_setup_items
purge_targets
expand_items
merge_items
run_cleanup
fix_line_endings
mark_files_executable
end
|