Module: Toybox
- Defined in:
- lib/toybox.rb,
lib/toybox/exefile.rb,
lib/toybox/txtfile.rb,
lib/toybox/linkfile.rb,
lib/generators/toybox.rb,
lib/toybox/configfile.rb,
lib/generators/toybox/install_generator.rb
Defined Under Namespace
Modules: Generators
Classes: Configfile, Exefile, Linkfile, ToyboxTask, Txtfile
Constant Summary
collapse
- @@config_data =
{}
Class Method Summary
collapse
Class Method Details
.app_fakeroot ⇒ Object
18
19
20
|
# File 'lib/toybox.rb', line 18
def self.app_fakeroot
"$(FAKEROOT)/#{Toybox.config[:app_root]}"
end
|
.config ⇒ Object
32
33
34
|
# File 'lib/toybox.rb', line 32
def self.config
@@config_data
end
|
22
23
24
25
26
27
28
29
30
|
# File 'lib/toybox.rb', line 22
def self.configure(config = nil, &block)
if config.is_a?(String) && config =~ /\S+\..yml/i then
@@config_data = YAML::load_file(File.join(Rails.root, config)).freeze
else
@@config_data = (yield).freeze
end
end
|
.debian_package(clog) ⇒ Object
111
112
113
|
# File 'lib/toybox.rb', line 111
def self.debian_package(clog)
"#{clog.join('_')}.deb"
end
|
.dpkg_find(&block) ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/toybox.rb', line 75
def self.dpkg_find(&block)
Toybox.config[:directories].map { |dir|
f = []
Find.find(dir) do |path|
if Toybox.config[:prune_dirs].member? File.basename(path) and not path_contains(path, Toybox.config[:ignore_dirs]) then
Find.prune
elsif Toybox.config[:files].member? File.basename(path) then
next
elsif Toybox.config[:other_files].member? File.basename(path) then
next
elsif File.basename(path) =~ /^ruby_sess.*/ then
next
else
x = yield(path)
f << x
end
end
f.compact
}.flatten.compact
end
|
.files ⇒ Object
96
97
98
99
100
101
102
103
104
|
# File 'lib/toybox.rb', line 96
def self.files()
dpkg_find do |path|
if path =~ /\.log$/ then
nil
else
filetype(path)
end
end
end
|
.filetype(path) ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/toybox.rb', line 45
def self.filetype(path)
return nil if Kernel.test('d', path) and not Kernel.test('l', path)
return nil if Toybox.config[:other_files].member? path
return nil if Toybox.config[:files].member? path
if Toybox.config[:use_production_yamls] then
if is_non_production_yaml?(path) then
STDERR.puts "skipping file: #{path}"
return nil
end
end
return nil if path =~ /config.database.yml$/
return nil if path =~ /config.ldap.yml$/
if Kernel.test('l', path) then
Linkfile.new(path)
elsif Kernel.test('x',path) then
Exefile.new(path)
elsif path =~ %r{^[\.\/]+config/} then
Configfile.new(path)
else
Txtfile.new(path)
end
end
|
.is_non_production_yaml?(path) ⇒ Boolean
36
37
38
39
40
41
42
43
|
# File 'lib/toybox.rb', line 36
def self.is_non_production_yaml?(path)
return false unless path =~ /\/config\/\w+\.yml$/
if path =~ /\/config\/\w+_production\.yml$/ then
false
else
true
end
end
|
.package_version ⇒ Object
114
115
116
117
|
# File 'lib/toybox.rb', line 114
def self.package_version
clog = parsechangelog
clog[1]
end
|
.parsechangelog ⇒ Object
105
106
107
108
109
110
|
# File 'lib/toybox.rb', line 105
def self.parsechangelog
changelog = %x{dpkg-parsechangelog}
package, version = changelog.split("\n")[0,2].map{|x| x.split.last }
arch = %x{dpkg-architecture -qDEB_HOST_ARCH}.chomp
[ package, version, arch ]
end
|
.path_contains(path, arg) ⇒ Object
68
69
70
71
72
73
|
# File 'lib/toybox.rb', line 68
def self.path_contains(path, arg)
arg.each do |s|
return true if path =~ Regexp.new(s)
end
false
end
|