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.
31 32 33 34 |
# File 'lib/codeless_code/options.rb', line 31 def initialize(command_name, argv) @command_name = command_name @argv = argv end |
Instance Method Details
#args ⇒ Object
40 41 42 |
# File 'lib/codeless_code/options.rb', line 40 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.
50 51 52 |
# File 'lib/codeless_code/options.rb', line 50 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.
55 56 57 |
# File 'lib/codeless_code/options.rb', line 55 def help parse_opts(suppress_errors: true).to_s end |
#key?(key) ⇒ Boolean
44 45 46 |
# File 'lib/codeless_code/options.rb', line 44 def key?(key) !!self[key] end |
#opts ⇒ Object
36 37 38 |
# File 'lib/codeless_code/options.rb', line 36 def opts @opts ||= parse_opts(suppress_errors: false) end |