Class: Arachni::Component::Options::Base Abstract
- Defined in:
- lib/arachni/component/options/base.rb
Overview
The base class for all options.
Instance Attribute Summary collapse
-
#default ⇒ Object
readonly
Default value.
-
#description ⇒ String
readonly
Description.
-
#name ⇒ Symbol
readonly
Name.
-
#value ⇒ Object
Assigned value.
Class Method Summary collapse
Instance Method Summary collapse
- #==(option) ⇒ Object
- #effective_value ⇒ Object
-
#for_component ⇒ Hash
#name => #normalize.
- #hash ⇒ Object
-
#initialize(name, options = {}) ⇒ Base
constructor
Initializes a named option with the supplied attribute array.
-
#missing_value? ⇒ Bool
`true` if the option is #required? but has no #value, `false` otherwise.
-
#normalize ⇒ Object
abstract
Convert the user-provided #value (which will usually be a user-supplied String) to the desired Ruby type.
-
#required? ⇒ Bool
Returns true if this is a required option.
- #to_h ⇒ Hash (also: #to_hash)
-
#to_rpc_data ⇒ Hash
Data representing this instance that are suitable the RPC transmission.
-
#type ⇒ Symbol
abstract
Type identifying the option.
-
#valid? ⇒ Bool
`true` if the option value is valid, `false` otherwise.
Constructor Details
#initialize(name, options = {}) ⇒ Base
Initializes a named option with the supplied attribute array. The array is composed of three values.
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/arachni/component/options/base.rb', line 44 def initialize( name, = {} ) = .dup @name = name.to_sym @required = !!.delete(:required) @description = .delete(:description) @default = .delete(:default) @value = .delete(:value) return if .empty? fail ArgumentError, "Unknown options: #{.keys.join( ', ' )}" end |
Instance Attribute Details
#default ⇒ Object (readonly)
Returns Default value.
22 23 24 |
# File 'lib/arachni/component/options/base.rb', line 22 def default @default end |
#description ⇒ String (readonly)
Returns Description.
19 20 21 |
# File 'lib/arachni/component/options/base.rb', line 19 def description @description end |
#name ⇒ Symbol (readonly)
Returns Name.
16 17 18 |
# File 'lib/arachni/component/options/base.rb', line 16 def name @name end |
#value ⇒ Object
Returns Assigned value.
25 26 27 |
# File 'lib/arachni/component/options/base.rb', line 25 def value @value end |
Class Method Details
.from_rpc_data(data) ⇒ Base
125 126 127 128 129 130 131 |
# File 'lib/arachni/component/options/base.rb', line 125 def self.from_rpc_data( data ) data.delete('type') data.delete('class') name = data.delete('name') new name, data.my_symbolize_keys(false) end |
Instance Method Details
#==(option) ⇒ Object
133 134 135 |
# File 'lib/arachni/component/options/base.rb', line 133 def ==( option ) hash == option.hash end |
#effective_value ⇒ Object
89 90 91 |
# File 'lib/arachni/component/options/base.rb', line 89 def effective_value @value || @default end |
#for_component ⇒ Hash
Returns #name => #normalize.
103 104 105 |
# File 'lib/arachni/component/options/base.rb', line 103 def for_component { name => normalize } end |
#hash ⇒ Object
137 138 139 |
# File 'lib/arachni/component/options/base.rb', line 137 def hash to_h.hash end |
#missing_value? ⇒ Bool
Returns `true` if the option is #required? but has no #value, `false` otherwise.
74 75 76 |
# File 'lib/arachni/component/options/base.rb', line 74 def missing_value? required? && effective_value.nil? end |
#normalize ⇒ Object
Returns Convert the user-provided #value (which will usually be a user-supplied String) to the desired Ruby type.
83 84 85 |
# File 'lib/arachni/component/options/base.rb', line 83 def normalize effective_value end |
#required? ⇒ Bool
Returns true if this is a required option.
61 62 63 |
# File 'lib/arachni/component/options/base.rb', line 61 def required? @required end |
#to_h ⇒ Hash Also known as: to_hash
108 109 110 111 112 113 114 |
# File 'lib/arachni/component/options/base.rb', line 108 def to_h hash = {} instance_variables.each do |var| hash[var.to_s.gsub( /@/, '' ).to_sym] = instance_variable_get( var ) end hash.merge( type: type ) end |
#to_rpc_data ⇒ Hash
Returns Data representing this instance that are suitable the RPC transmission.
119 120 121 |
# File 'lib/arachni/component/options/base.rb', line 119 def to_rpc_data to_h.merge( class: self.class.to_s ).my_stringify_keys end |
#type ⇒ Symbol
Returns Type identifying the option.
97 98 99 |
# File 'lib/arachni/component/options/base.rb', line 97 def type :abstract end |
#valid? ⇒ Bool
Returns `true` if the option value is valid, `false` otherwise.
67 68 69 |
# File 'lib/arachni/component/options/base.rb', line 67 def valid? !missing_value? end |