Module: RokuBuilder
- Defined in:
- lib/roku_builder/util.rb,
lib/roku_builder.rb,
lib/roku_builder/config.rb,
lib/roku_builder/errors.rb,
lib/roku_builder/logger.rb,
lib/roku_builder/plugin.rb,
lib/roku_builder/stager.rb,
lib/roku_builder/options.rb,
lib/roku_builder/version.rb,
lib/roku_builder/manifest.rb,
lib/roku_builder/plugins/core.rb,
lib/roku_builder/config_parser.rb,
lib/roku_builder/plugins/linker.rb,
lib/roku_builder/plugins/loader.rb,
lib/roku_builder/plugins/tester.rb,
lib/roku_builder/plugins/monitor.rb,
lib/roku_builder/config_validator.rb,
lib/roku_builder/plugins/packager.rb,
lib/roku_builder/plugins/profiler.rb,
lib/roku_builder/plugins/scripter.rb,
lib/roku_builder/plugins/inspector.rb,
lib/roku_builder/plugins/navigator.rb
Overview
********** Copyright Viacom, Inc. Apache 2.0 **********
Defined Under Namespace
Modules: Plugin
Classes: Config, ConfigParser, ConfigValidator, Core, DeviceError, ExecutionError, ImplementationError, Inspector, InvalidConfig, InvalidOptions, Linker, Loader, Logger, Manifest, ManifestError, Monitor, Navigator, Options, Packager, ParseError, Profiler, Scripter, Stager, Tester, Util
Constant Summary
collapse
- VERSION =
Version of the RokuBuilder Gem
"4.6.0"
Class Method Summary
collapse
Class Method Details
.check_devices ⇒ Object
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
# File 'lib/roku_builder.rb', line 161
def self.check_devices
if @@options.device_command?
ping = Net::Ping::External.new
host = @@config.parsed[:device_config][:ip]
return if ping.ping? host, 1, 0.2, 1
raise DeviceError, "Device not online" if @@options[:device_given]
@@config.raw[:devices].each_pair {|key, value|
unless key == :default
host = value[:ip]
if ping.ping? host, 1, 0.2, 1
@@config.parsed[:device_config] = value
Logger.instance.warn("Default device offline, choosing Alternate")
return
end
end
}
raise DeviceError, "No devices found"
end
end
|
.execute ⇒ Object
66
67
68
69
70
|
# File 'lib/roku_builder.rb', line 66
def self.execute
load_config
check_devices
execute_command
end
|
.execute_command ⇒ Object
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
# File 'lib/roku_builder.rb', line 181
def self.execute_command
@@plugins.each do |plugin|
if plugin.commands.keys.include?(@@options.command)
stager = nil
if plugin.commands[@@options.command][:stage]
stager = Stager.new(config: @@config, options: @@options)
stager.stage
end
instance = plugin.new(config: @@config)
instance.send(@@options.command, {options: @@options})
stager.unstage if stager
end
end
end
|
.initialize_logger ⇒ Object
.load_config ⇒ Object
151
152
153
154
155
156
157
158
159
|
# File 'lib/roku_builder.rb', line 151
def self.load_config
@@config = Config.new(options: @@options)
@@config.configure
unless @@options[:configure] and not @@options[:edit_params]
@@config.load
@@config.validate
@@config.parse
end
end
|
.load_dev_plugin ⇒ Object
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
# File 'lib/roku_builder.rb', line 106
def self.load_dev_plugin
dev_path = nil
ARGV.each_index do |i|
if ARGV[i] == "--dev-plugin"
dev_path = ARGV[i+1]
2.times {ARGV.delete_at(i)}
break
end
end
if dev_path
@@dev = true
Dir.glob(File.join(dev_path, "lib", "roku_builder", "plugins", "*")).each do |path|
require path
end
@@dev = false
end
end
|
.load_plugins ⇒ Object
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/roku_builder.rb', line 88
def self.load_plugins
Dir.glob(File.join(File.dirname(__FILE__), "roku_builder", "plugins", "*.rb")).each do |path|
file = "roku_builder/plugins/"+File.basename(path, ".rb")
require file
end
gem_versions = Gem::Specification.sort_by {|g| [g.name.downcase, g.version]}.group_by {|g| g.name}
gems = []
gem_versions.each {|v| gems.push(v.last.last)}
gems.each do |gem|
unless gem.name == "roku_builder"
Dir.glob(File.join(gem.full_gem_path, "lib", "roku_builder", "plugins", "*")).each do |path|
require path
end
end
end
load_dev_plugin
end
|
.options_parse(options:) ⇒ Hash
Parses a string into and options hash
199
200
201
202
203
204
205
206
207
208
209
|
# File 'lib/roku_builder.rb', line 199
def self.options_parse(options:)
parsed = {}
opts = options.split(/,\s*/)
opts.each do |opt|
opt = opt.split(":")
key = opt.shift.to_sym
value = opt.join(":")
parsed[key] = value
end
parsed
end
|
.plugins ⇒ Object
72
73
74
|
# File 'lib/roku_builder.rb', line 72
def self.plugins
@@plugins ||= []
end
|
.process_plugins ⇒ Object
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
# File 'lib/roku_builder.rb', line 124
def self.process_plugins
@@plugins ||= []
@@plugins.sort! {|a,b| a.to_s <=> b.to_s}
unless @@plugins.count == @@plugins.uniq.count
duplicates = @@plugins.select{ |e| @@plugins.count(e) > 1 }.uniq
raise ImplementationError, "Duplicate plugins: #{duplicates.join(", ")}"
end
@@plugins.each do |plugin|
plugin.dependencies.each do |dependency|
raise ImplementationError, "Missing dependency: #{dependency}" unless @@plugins.include?(dependency)
end
plugin.commands.keys.each do |command|
raise ImplementationError, "Missing command method '#{command}' in #{plugin}" unless plugin.instance_methods.include?(command)
end
end
end
|
.register_plugin(plugin) ⇒ Object
76
77
78
79
80
81
|
# File 'lib/roku_builder.rb', line 76
def self.register_plugin(plugin)
@@dev ||= false
@@plugins ||= []
@@plugins.delete(plugin) if @@dev
@@plugins << plugin
end
|
.run(options: nil) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/roku_builder.rb', line 38
def self.run(options: nil)
@@options = nil
setup_plugins
setup_options(options: options)
return unless @@options
initialize_logger
if @@options[:debug]
execute
else
begin
execute
rescue StandardError => e
Logger.instance.fatal "#{e.class}: #{e.message}"
end
end
end
|
.setup_options(options:) ⇒ Object
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/roku_builder.rb', line 55
def self.setup_options(options:)
begin
@@options = Options.new(options: options)
@@options.validate
rescue InvalidOptions => e
Logger.instance.fatal "#{e.class}: #{e.message}"
@@options = nil
return
end
end
|
.setup_plugins ⇒ Object
83
84
85
86
|
# File 'lib/roku_builder.rb', line 83
def self.setup_plugins
load_plugins
process_plugins
end
|
.system(command:) ⇒ String
214
215
216
|
# File 'lib/roku_builder.rb', line 214
def self.system(command:)
`#{command}`.chomp
end
|