Class: RokuBuilder::Scripter

Inherits:
Object
  • Object
show all
Extended by:
Plugin
Defined in:
lib/roku_builder/plugins/scripter.rb

Overview

Helper for extending for scripting

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Plugin

commands, dependencies, parse_options, validate

Constructor Details

#initialize(config:) ⇒ Scripter

Returns a new instance of Scripter.



20
21
22
# File 'lib/roku_builder/plugins/scripter.rb', line 20

def initialize(config:)
  @config = config
end

Class Method Details

.commandsObject



9
10
11
# File 'lib/roku_builder/plugins/scripter.rb', line 9

def self.commands
  {print: {source: true, stage: true}}
end

.parse_options(parser:, options:) ⇒ Object



13
14
15
16
17
18
# File 'lib/roku_builder/plugins/scripter.rb', line 13

def self.parse_options(parser:, options:)
  parser.separator("Commands:")
  parser.on("--print ATTRIBUTE", "Print attribute for scripting") do |a|
    options[:print] = a.to_sym
  end
end

Instance Method Details



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/roku_builder/plugins/scripter.rb', line 24

def print(options:)
  manifest = Manifest.new(config: @config)

  case options[:print]
  when :root_dir
    printf "%s", @config.project[:directory]
  when :app_name
    printf "%s", @config.project[:app_name]
  when :title
    printf "%s", manifest.title
  when :build_version
    printf "%s", manifest.build_version
  when :app_version
    major = manifest.major_version
    minor = manifest.minor_version
    printf "%s.%s", major, minor
  else
    if manifest.send(options[:print])
      printf manifest.send(options[:print])
    else
      raise ExecutionError, "Unknown attribute: #{options[:print]}"
    end
  end
end