Class: CodelessCode::Options
- Inherits:
-
Object
- Object
- CodelessCode::Options
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/codeless_code/options.rb
Overview
Adapter class for ARGV which exposes the command-line arguments as data types.
Constant Summary collapse
- MAX_ARGS =
–number flag may be passed as argument cmd 3 vs cmd -N 3
1
Instance Method Summary collapse
- #args ⇒ Object
-
#data_dir ⇒ Pathname
Where on the file system to search for fables.
-
#help ⇒ String
A description of the supported command-line options.
-
#initialize(command_name, argv) ⇒ Options
constructor
A new instance of Options.
- #key?(key) ⇒ Boolean
- #opts ⇒ Object
Constructor Details
#initialize(command_name, argv) ⇒ Options
Returns a new instance of Options.
33 34 35 36 |
# File 'lib/codeless_code/options.rb', line 33 def initialize(command_name, argv) @command_name = command_name @argv = argv end |
Instance Method Details
#args ⇒ Object
42 43 44 |
# File 'lib/codeless_code/options.rb', line 42 def args opts.arguments[1..-1] end |
#data_dir ⇒ Pathname
Returns Where on the file system to search for fables. Will default to DEFAULT_DATA if unspecified.
52 53 54 |
# File 'lib/codeless_code/options.rb', line 52 def data_dir @data_dir ||= self[:path] ? Pathname.new(self[:path]) : DEFAULT_DATA end |
#help ⇒ String
Returns a description of the supported command-line options.
57 58 59 |
# File 'lib/codeless_code/options.rb', line 57 def help parse_opts(suppress_errors: true).to_s end |
#key?(key) ⇒ Boolean
46 47 48 |
# File 'lib/codeless_code/options.rb', line 46 def key?(key) !!self[key] end |
#opts ⇒ Object
38 39 40 |
# File 'lib/codeless_code/options.rb', line 38 def opts @opts ||= parse_opts(suppress_errors: false) end |