Class: Embulk::PackageData

Inherits:
Object
  • Object
show all
Defined in:
lib/embulk/data/package_data.rb

Instance Method Summary collapse

Constructor Details

#initialize(base_name, dest_dir, erb_binding = nil) ⇒ PackageData

Returns a new instance of PackageData.



4
5
6
7
8
9
# File 'lib/embulk/data/package_data.rb', line 4

def initialize(base_name, dest_dir, erb_binding=nil)
  require 'fileutils'
  @base_name = base_name
  @dest_dir = dest_dir
  @erb_binding = erb_binding
end

Instance Method Details

#content(src) ⇒ Object



15
16
17
# File 'lib/embulk/data/package_data.rb', line 15

def content(src)
  File.read(path(src))
end

#cp(src, dest_name) ⇒ Object



24
25
26
27
# File 'lib/embulk/data/package_data.rb', line 24

def cp(src, dest_name)
  path = dest_path_message(dest_name)
  FileUtils.cp path(src), path
end

#cp_erb(src, dest_name) ⇒ Object



29
30
31
32
# File 'lib/embulk/data/package_data.rb', line 29

def cp_erb(src, dest_name)
  path = dest_path_message(dest_name)
  File.open(path, "w") {|f| f.write erb(src) }
end

#dest_path(dest_name) ⇒ Object



34
35
36
# File 'lib/embulk/data/package_data.rb', line 34

def dest_path(dest_name)
  File.join(@dest_dir, *dest_name.split('/'))
end

#dest_path_message(dest_name) ⇒ Object



38
39
40
41
42
43
# File 'lib/embulk/data/package_data.rb', line 38

def dest_path_message(dest_name)
  path = dest_path(dest_name)
  puts "  Creating #{path}"
  FileUtils.mkdir_p File.dirname(path)
  path
end

#erb(src) ⇒ Object



19
20
21
22
# File 'lib/embulk/data/package_data.rb', line 19

def erb(src)
  require 'erb'
  ERB.new(content(src), nil, '%').result(@erb_binding)
end

#path(src) ⇒ Object



11
12
13
# File 'lib/embulk/data/package_data.rb', line 11

def path(src)
  Embulk.lib_path("embulk/data/#{@base_name}/#{src}")
end

#set_executable(dest_name) ⇒ Object



45
46
47
# File 'lib/embulk/data/package_data.rb', line 45

def set_executable(dest_name)
  File.chmod(0755, dest_path(dest_name))
end