Class: Translatomatic::Option
- Inherits:
-
Object
- Object
- Translatomatic::Option
- Defined in:
- lib/translatomatic/option.rb
Overview
Stores details about command line and object constructor options
Instance Attribute Summary collapse
-
#command_line_only ⇒ boolean
readonly
True if this option can only be set on the command line.
-
#default ⇒ Object
readonly
The default value for this option.
-
#description ⇒ String
readonly
Description of the option.
-
#env_name ⇒ String
readonly
If set, the name of the environment variable that can be used to set this option in the environment.
-
#hidden ⇒ boolean
readonly
If true, the option does not appear on the command line but it can be used in configuration settings.
-
#name ⇒ String
readonly
Name of the option.
-
#required ⇒ boolean
readonly
True if this option is required.
-
#type ⇒ Symbol
readonly
Type of option, one of: :string, :hash, :array, :numeric, or :boolean.
-
#user_context_only ⇒ boolean
readonly
True if this option can only be set in user context.
Class Method Summary collapse
-
.options_from_object(object) ⇒ Array<Translatomatic::Option>
Retrieve all options from an object or list of objects.
Instance Method Summary collapse
-
#initialize(data = {}) ⇒ Translatomatic::Option
constructor
Create a new option.
- #to_thor ⇒ Object
Constructor Details
#initialize(data = {}) ⇒ Translatomatic::Option
Create a new option
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/translatomatic/option.rb', line 37 def initialize(data = {}) @name = data[:name] @required = data[:required] @description = data[:desc] @use_env = data[:use_env] @hidden = data[:hidden] @type = data[:type] || :string @default = data[:default] @aliases = data[:aliases] @enum = data[:enum] @user_context_only = data[:user_context_only] @command_line_only = data[:command_line_only] @env_name = data[:env_name] || (@use_env ? @name.to_s.upcase : nil) end |
Instance Attribute Details
#command_line_only ⇒ boolean (readonly)
Returns True if this option can only be set on the command line.
29 30 31 |
# File 'lib/translatomatic/option.rb', line 29 def command_line_only @command_line_only end |
#default ⇒ Object (readonly)
Returns The default value for this option.
26 27 28 |
# File 'lib/translatomatic/option.rb', line 26 def default @default end |
#description ⇒ String (readonly)
Returns Description of the option.
15 16 17 |
# File 'lib/translatomatic/option.rb', line 15 def description @description end |
#env_name ⇒ String (readonly)
Returns If set, the name of the environment variable that can be used to set this option in the environment.
12 13 14 |
# File 'lib/translatomatic/option.rb', line 12 def env_name @env_name end |
#hidden ⇒ boolean (readonly)
Returns If true, the option does not appear on the command line but it can be used in configuration settings.
19 20 21 |
# File 'lib/translatomatic/option.rb', line 19 def hidden @hidden end |
#name ⇒ String (readonly)
Returns Name of the option.
5 6 7 |
# File 'lib/translatomatic/option.rb', line 5 def name @name end |
#required ⇒ boolean (readonly)
Returns True if this option is required.
8 9 10 |
# File 'lib/translatomatic/option.rb', line 8 def required @required end |
#type ⇒ Symbol (readonly)
Returns Type of option, one of: :string, :hash, :array, :numeric, or :boolean.
23 24 25 |
# File 'lib/translatomatic/option.rb', line 23 def type @type end |
#user_context_only ⇒ boolean (readonly)
Returns True if this option can only be set in user context.
32 33 34 |
# File 'lib/translatomatic/option.rb', line 32 def user_context_only @user_context_only end |
Class Method Details
.options_from_object(object) ⇒ Array<Translatomatic::Option>
Retrieve all options from an object or list of objects.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/translatomatic/option.rb', line 69 def self.(object) = [] if object.respond_to?(:options) += (object.) elsif object.kind_of?(Array) object.each do |item| if item.kind_of?(Translatomatic::Option) << item elsif item.respond_to?(:options) += (item.) end end end end |
Instance Method Details
#to_thor ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/translatomatic/option.rb', line 52 def to_thor # use internal ',' splitting for array types on command line type = @type == :array ? :string : @type { name: @name, required: @required, type: type, desc: @description, default: @default, aliases: @aliases, enum: @enum ? @enum.collect { |i| i.to_s } : nil } end |