Class: Licensed::Commands::Command
- Inherits:
-
Object
- Object
- Licensed::Commands::Command
- Defined in:
- lib/licensed/commands/command.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#reporter ⇒ Object
readonly
Returns the value of attribute reporter.
Instance Method Summary collapse
-
#create_reporter(options) ⇒ Object
Creates a reporter to use during a command run.
-
#default_reporter(options) ⇒ Object
Returns the default reporter to use during the command run.
-
#initialize(config:) ⇒ Command
constructor
A new instance of Command.
-
#run(**options) ⇒ Object
Run the command.
Constructor Details
#initialize(config:) ⇒ Command
Returns a new instance of Command.
9 10 11 |
# File 'lib/licensed/commands/command.rb', line 9 def initialize(config:) @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
5 6 7 |
# File 'lib/licensed/commands/command.rb', line 5 def config @config end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/licensed/commands/command.rb', line 7 def @options end |
#reporter ⇒ Object (readonly)
Returns the value of attribute reporter.
6 7 8 |
# File 'lib/licensed/commands/command.rb', line 6 def reporter @reporter end |
Instance Method Details
#create_reporter(options) ⇒ Object
Creates a reporter to use during a command run
options - The options the command was run with
Returns the reporter to use during the command run
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/licensed/commands/command.rb', line 45 def create_reporter() return [:reporter] if [:reporter].is_a?(Licensed::Reporters::Reporter) if [:reporter].is_a?(String) klass = "#{[:reporter].capitalize}Reporter" return Licensed::Reporters.const_get(klass).new if Licensed::Reporters.const_defined?(klass) end default_reporter() end |
#default_reporter(options) ⇒ Object
Returns the default reporter to use during the command run
options - The options the command was run with
Raises an error
61 62 63 |
# File 'lib/licensed/commands/command.rb', line 61 def default_reporter() raise "`default_reporter` must be implemented by commands" end |
#run(**options) ⇒ Object
Run the command
options - Options to run the command with
Returns whether the command was a success
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/licensed/commands/command.rb', line 18 def run(**) @options = @reporter = create_reporter() begin result = reporter.report_run(self) do |report| # allow additional report data to be given by commands if block_given? next true if (yield report) == :skip end config.apps.sort_by { |app| app["name"] } .map { |app| run_app(app) } .all? end ensure @options = nil @reporter = nil end result end |