Class: Plz::CommandBuilder
- Inherits:
-
Object
- Object
- Plz::CommandBuilder
- Defined in:
- lib/plz/command_builder.rb
Constant Summary collapse
- SCHEMA_FILE_PATH_PATTERN =
"schema.{json,yml}"
Class Method Summary collapse
-
.call(arguments) ⇒ Plz::Command, Plz::ErrorCommand
Builds callable command object from given ARGV.
Instance Method Summary collapse
-
#call ⇒ Plz::Command
Callable command object.
-
#initialize(argv) ⇒ CommandBuilder
constructor
A new instance of CommandBuilder.
Constructor Details
#initialize(argv) ⇒ CommandBuilder
Returns a new instance of CommandBuilder.
24 25 26 |
# File 'lib/plz/command_builder.rb', line 24 def initialize(argv) @argv = argv end |
Class Method Details
.call(arguments) ⇒ Plz::Command, Plz::ErrorCommand
Note:
This is a shortcut for #call method
Builds callable command object from given ARGV
10 11 12 |
# File 'lib/plz/command_builder.rb', line 10 def self.call(arguments) new(arguments).call end |
Instance Method Details
#call ⇒ Plz::Command
Returns Callable command object.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/plz/command_builder.rb', line 29 def call case when !has_schema_file? Commands::SchemaFileNotFound.new when !has_decodable_schema_file? Commands::UndecodableSchemaFile.new(pathname: schema_file_pathname) when !has_valid_schema_file? Commands::InvalidSchema.new(pathname: schema_file_pathname, error: @json_schema_error) when !has_base_url? Commands::BaseUrlNotFound.new(pathname: schema_file_pathname) when has_help? Commands::Help.new(options: , schema: json_schema) when !has_action_name? Commands::NoActionName.new when !has_target_name? Commands::NoTargetName.new when !has_link? Commands::LinkNotFound.new( pathname: schema_file_pathname, action_name: nil, target_name: nil ) when has_invalid_json_input? Commands::InvalidJsonFromStdin.new when has_unparsable_json_param? Commands::UnparsableJsonParam.new(error: @json_parse_error) else Commands::Request.new( method: method, base_url: base_url, path: path, headers: headers, params: request_params, options: , ) end end |