Class: Bashly::Models::Base
- Inherits:
-
Object
- Object
- Bashly::Models::Base
show all
- Includes:
- Renderable
- Defined in:
- lib/bashly/models/base.rb
Constant Summary
collapse
- OPTION_KEYS =
i[
allowed
arg
catch_all
completions
default
dependencies
description
environment_variables
examples
extensible
flags
group
help
long
name
parent_name
required
short
version
]
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Renderable
#render, #strings
Constructor Details
#initialize(options) ⇒ Base
Returns a new instance of Base.
31
32
33
34
35
|
# File 'lib/bashly/models/base.rb', line 31
def initialize(options)
raise Error, "Invalid options provided" unless options.respond_to? :keys
@options = options
verify if respond_to? :verify
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *arguments, &block) ⇒ Object
49
50
51
52
|
# File 'lib/bashly/models/base.rb', line 49
def method_missing(method_name, *arguments, &block)
key = method_name.to_s
respond_to?(method_name) ? options[key] : super
end
|
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
6
7
8
|
# File 'lib/bashly/models/base.rb', line 6
def options
@options
end
|
Instance Method Details
#help ⇒ Object
45
46
47
|
# File 'lib/bashly/models/base.rb', line 45
def help
options['help'] ||= ''
end
|
#optional ⇒ Object
37
38
39
|
# File 'lib/bashly/models/base.rb', line 37
def optional
!required
end
|
#respond_to?(method_name, include_private = false) ⇒ Boolean
54
55
56
|
# File 'lib/bashly/models/base.rb', line 54
def respond_to?(method_name, include_private = false)
OPTION_KEYS.include?(method_name) || super
end
|
#summary ⇒ Object
41
42
43
|
# File 'lib/bashly/models/base.rb', line 41
def summary
help.empty? ? "" : help.split("\n").first
end
|