Class: Bashly::Script::Base

Inherits:
Object
  • Object
show all
Includes:
Renderable
Defined in:
lib/bashly/script/base.rb

Direct Known Subclasses

Argument, Command, EnvironmentVariable, Flag

Instance Attribute Summary collapse

Attributes included from Renderable

#render_options

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Renderable

#load_user_file, #render, #strings, #user_file_exist?, #user_file_path, #view_marker

Constructor Details

#initialize(options) ⇒ Base

Returns a new instance of Base.

Raises:



14
15
16
17
18
# File 'lib/bashly/script/base.rb', line 14

def initialize(options)
  raise Error, 'Invalid options provided' unless options.respond_to? :keys

  @options = options
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *arguments) ⇒ Object



32
33
34
35
# File 'lib/bashly/script/base.rb', line 32

def method_missing(method_name, *arguments, &)
  key = method_name.to_s
  respond_to?(method_name) ? options[key] : super
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/bashly/script/base.rb', line 6

def options
  @options
end

Class Method Details

.option_keysObject



9
10
11
# File 'lib/bashly/script/base.rb', line 9

def option_keys
  @option_keys ||= []
end

Instance Method Details

#helpObject



28
29
30
# File 'lib/bashly/script/base.rb', line 28

def help
  options['help'] ||= ''
end

#optionalObject



20
21
22
# File 'lib/bashly/script/base.rb', line 20

def optional
  !options['required']
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
40
# File 'lib/bashly/script/base.rb', line 37

def respond_to_missing?(method_name, include_private = false)
  self.class.option_keys.include?(method_name) ||
    method_name.to_s.start_with?('x_') || super
end

#summaryObject



24
25
26
# File 'lib/bashly/script/base.rb', line 24

def summary
  help.empty? ? '' : help.split("\n").first
end