Class: Xpub::CallBook::CallBuilder
- Inherits:
-
Object
- Object
- Xpub::CallBook::CallBuilder
show all
- Defined in:
- lib/xpub/dsl/builder.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(name, book) ⇒ CallBuilder
Returns a new instance of CallBuilder.
8
9
10
11
|
# File 'lib/xpub/dsl/builder.rb', line 8
def initialize(name, book)
@name = name
@book = book
end
|
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
4
5
6
|
# File 'lib/xpub/dsl/builder.rb', line 4
def name
@name
end
|
Instance Method Details
#build ⇒ Object
13
14
15
|
# File 'lib/xpub/dsl/builder.rb', line 13
def build
raise 'This method is not implement.'
end
|
#cmd_exec(cmd, args, option) ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/xpub/dsl/builder.rb', line 45
def cmd_exec(cmd, args, option)
cmd_line = cmd + ' ' + args.map do |arg|
Shellwords.shellescape(arg)
end.join(' ')
puts cmd_line.color :cyan
stdout, stderr, status = Open3.capture3 cmd_line
puts stdout.color :green if option[:v] || status != 0
if status != 0
puts stderr.color :red
puts 'error!'.color :red
exit
end
end
|
#copy_to_tmp(files) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/xpub/dsl/builder.rb', line 33
def copy_to_tmp(files)
files.each do |file|
pn = Pathname.new tmp_path(file.file)
FileUtils.mkdir_p(pn.dirname) unless FileTest.exist?(pn.dirname)
unless FileTest.exist?(tmp_path(file.file)) && File.mtime(src_path(file.file)) <= File.mtime(tmp_path(file.file))
puts "copy #{file.file} to tmp/".color :white
FileUtils.copy_entry(src_path(file.file), tmp_path(file.file))
end
end
end
|
#output_path(file) ⇒ Object
29
30
31
|
# File 'lib/xpub/dsl/builder.rb', line 29
def output_path(file)
"#{Dir.getwd}/output/#{file}"
end
|
#src_path(file) ⇒ Object
21
22
23
|
# File 'lib/xpub/dsl/builder.rb', line 21
def src_path(file)
"#{Dir.getwd}/src/#{file}"
end
|
#tmp_path(file) ⇒ Object
25
26
27
|
# File 'lib/xpub/dsl/builder.rb', line 25
def tmp_path(file)
"#{Dir.getwd}/tmp/#{@book.name}/#{file}"
end
|
#validate ⇒ Object
17
18
19
|
# File 'lib/xpub/dsl/builder.rb', line 17
def validate
raise 'src_file is empty.' if @book.src_files.count == 0
end
|