module RokuBuilder

********** Copyright Viacom, Inc. Apache 2.0 **********

********** Copyright Viacom, Inc. Apache 2.0 **********

********** Copyright Viacom, Inc. Apache 2.0 **********

********** Copyright Viacom, Inc. Apache 2.0 **********

********** Copyright Viacom, Inc. Apache 2.0 **********

********** Copyright Viacom, Inc. Apache 2.0 **********

********** Copyright Viacom, Inc. Apache 2.0 **********

********** Copyright Viacom, Inc. Apache 2.0 **********

********** Copyright Viacom, Inc. Apache 2.0 **********

********** Copyright Viacom, Inc. Apache 2.0 **********

********** Copyright Viacom, Inc. Apache 2.0 **********

********** Copyright Viacom, Inc. Apache 2.0 **********

********** Copyright Viacom, Inc. Apache 2.0 **********

********** Copyright Viacom, Inc. Apache 2.0 **********

********** Copyright Viacom, Inc. Apache 2.0 **********

********** Copyright Viacom, Inc. Apache 2.0 **********

********** Copyright Viacom, Inc. Apache 2.0 **********

********** Copyright Viacom, Inc. Apache 2.0 **********

********** Copyright Viacom, Inc. Apache 2.0 **********

********** Copyright Viacom, Inc. Apache 2.0 **********

********** Copyright Viacom, Inc. Apache 2.0 **********

********** Copyright Viacom, Inc. Apache 2.0 **********

********** Copyright Viacom, Inc. Apache 2.0 **********

********** Copyright Viacom, Inc. Apache 2.0 **********

Constants

VERSION

Version of the RokuBuilder Gem

Public Class Methods

check_devices() click to toggle source
# File lib/roku_builder.rb, line 174
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() click to toggle source
# File lib/roku_builder.rb, line 69
def self.execute
  load_config
  check_devices
  execute_command
end
execute_command() click to toggle source
# File lib/roku_builder.rb, line 194
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() click to toggle source
# File lib/roku_builder.rb, line 154
def self.initialize_logger
  if @@options[:debug]
    Logger.set_debug
  elsif @@options[:verbose]
    Logger.set_info
  else
    Logger.set_warn
  end
end
load_config() click to toggle source
# File lib/roku_builder.rb, line 164
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() click to toggle source
# File lib/roku_builder.rb, line 110
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", "*.rb")).each do |path|
      require path
    end
    Dir.glob(File.join(dev_path, "lib", "roku_builder", "plugins", "*")).each do |path|
      require path
    end
    @@dev = false
  end
end
load_plugins() click to toggle source
# File lib/roku_builder.rb, line 92
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:) click to toggle source

Parses a string into and options hash @param options [String] string of options in the format “a:b, c:d” @return [Hash] Options hash generated

# File lib/roku_builder.rb, line 212
def self.options_parse(options:)
  parsed = {}
  opts = options.split(/,\s*/)
  opts.each do |opt|
    opt = opt.split(":")
    key = opt.shift.strip.to_sym
    value = opt.join(":").strip
    parsed[key] = value
  end
  parsed
end
plugins() click to toggle source
# File lib/roku_builder.rb, line 75
def self.plugins
  @@plugins ||= []
end
process_hook(hook:, params:) click to toggle source
# File lib/roku_builder.rb, line 224
def self.process_hook(hook:, params:)
  @@plugins.each do |plugin|
    if plugin.respond_to?("#{hook}_hook".to_sym)
      plugin.send("#{hook}_hook", **params)
    end
  end
end
process_plugins() click to toggle source
# File lib/roku_builder.rb, line 131
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) click to toggle source
# File lib/roku_builder.rb, line 79
def self.register_plugin(plugin)
  @@dev ||= false
  @@plugins ||= []
  @@plugins.delete(plugin) if @@dev
  @@plugins << plugin
end
run(options: nil) click to toggle source

Run the builder @param options [Hash] The options hash

# File lib/roku_builder.rb, line 39
def self.run(options: nil)
  @@options = nil
  @@testing ||= false
  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}"
      exit false unless @@testing
    end
  end
end
set_testing() click to toggle source
# File lib/roku_builder.rb, line 239
def self.set_testing
  @@testing = true
  Logger.set_testing
end
setup_options(options:) click to toggle source
# File lib/roku_builder.rb, line 58
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() click to toggle source
# File lib/roku_builder.rb, line 86
def self.setup_plugins
  load_plugins
  process_plugins
  validate_plugins
end
system(command:) click to toggle source

Run a system command @param command [String] The command to be run @return [String] The output of the command

# File lib/roku_builder.rb, line 235
def self.system(command:)
  `#{command}`.chomp
end
validate_plugins() click to toggle source
# File lib/roku_builder.rb, line 148
def self.validate_plugins
  @@plugins.each do |plugin|
    plugin.validate
  end
end