Class: TRMNLP::Commands::Base
- Inherits:
-
Object
- Object
- TRMNLP::Commands::Base
- Defined in:
- lib/trmnlp/commands/base.rb
Class Method Summary collapse
-
.options_from(input) ⇒ Object
NOTE: Thor only includes flags the user actually passed, but Data.define requires every member.
- .run(input) ⇒ Object
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(context:, options:, reporter: nil) ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize(context:, options:, reporter: nil) ⇒ Base
Returns a new instance of Base.
26 27 28 29 30 31 32 |
# File 'lib/trmnlp/commands/base.rb', line 26 def initialize(context:, options:, reporter: nil) raise ArgumentError, "options must be a #{self.class}::Options" unless .is_a?(self.class::Options) @context = context @options = @reporter = reporter || Reporter.new(quiet: .quiet) end |
Class Method Details
.options_from(input) ⇒ Object
NOTE: Thor only includes flags the user actually passed, but Data.define requires every member. We pad missing members with nil so partial Thor hashes round-trip into a fully-populated typed Options struct.
19 20 21 22 23 24 |
# File 'lib/trmnlp/commands/base.rb', line 19 def self.(input) return input if input.is_a?(self::Options) hash = input.to_h.transform_keys(&:to_sym) self::Options.new(**self::Options.members.to_h { [it, hash[it]] }) end |
Instance Method Details
#call ⇒ Object
34 35 36 |
# File 'lib/trmnlp/commands/base.rb', line 34 def call raise NotImplementedError end |