Class: Aruba::BasicConfiguration
- Inherits:
-
Object
- Object
- Aruba::BasicConfiguration
- Includes:
- Contracts
- Defined in:
- lib/aruba/basic_configuration.rb,
lib/aruba/basic_configuration/option.rb
Overview
Basic Configuration
Direct Known Subclasses
Defined Under Namespace
Classes: Option
Instance Attribute Summary collapse
-
#hooks ⇒ Object
readonly
Get access to hooks.
Class Method Summary collapse
- .known_options ⇒ Object
-
.option_accessor(name, opts = {}) ⇒ Object
Define an option reader and writer.
-
.option_reader(name, opts = {}) ⇒ Object
Define an option reader.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#after(name, context = proc {}, *args) { ... } ⇒ Object
Define or run after-hook.
-
#after?(name) ⇒ Boolean
Check if after-hook
is defined. -
#before(name, context = proc {}, *args) { ... } ⇒ Object
Define or run before-hook.
-
#before?(name) ⇒ Boolean
Check if before-hook
is defined. - #before_cmd(&block) ⇒ Object deprecated Deprecated.
- #configure {|Configuration| ... } ⇒ Object
-
#initialize ⇒ BasicConfiguration
constructor
Create configuration.
-
#make_copy ⇒ Object
Make deep dup copy of configuration.
-
#option?(name) ⇒ Boolean
Check if
is option. -
#reset ⇒ Object
Reset configuration.
-
#set_if_option(name, *args) ⇒ Object
Set if name is option.
Constructor Details
#initialize ⇒ BasicConfiguration
Create configuration
101 102 103 |
# File 'lib/aruba/basic_configuration.rb', line 101 def initialize initialize_configuration end |
Instance Attribute Details
#hooks ⇒ Object
Get access to hooks
127 128 129 130 131 132 133 |
# File 'lib/aruba/basic_configuration.rb', line 127 def hooks # rubocop:disable Metrics/LineLength Aruba.platform.deprecated 'The use of the "#aruba.config.hooks" is deprecated. Please use "#aruba.config.before(:name) {}" to define and "#aruba.config.before(:name, *args)" to run a hook. This method will become private in the next major version.' # rubocop:enable Metrics/LineLength @hooks end |
Class Method Details
.known_options ⇒ Object
14 15 16 |
# File 'lib/aruba/basic_configuration.rb', line 14 def @known_options ||= {} end |
.option_accessor(name, opts = {}) ⇒ Object
Define an option reader and writer
rubocop:disable Metrics/CyclomaticComplexity
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/aruba/basic_configuration.rb', line 61 def option_accessor(name, opts = {}) contract = opts[:contract] default = opts[:default] fail ArgumentError, 'Either use block or default value' if block_given? && default # fail ArgumentError, 'Either use block or default value' if !block_given? && default.nil? && default.to_s.empty? fail ArgumentError, 'contract-options is required' if contract.nil? # Add writer add_option(name, block_given? ? yield(InConfigWrapper.new()) : default) Contract contract define_method("#{name}=") { |v| find_option(name).value = v } # Add reader option_reader name, :contract => { None => contract.values.first } end |
.option_reader(name, opts = {}) ⇒ Object
Define an option reader
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/aruba/basic_configuration.rb', line 31 def option_reader(name, opts = {}) contract = opts[:contract] default = opts[:default] fail ArgumentError, 'Either use block or default value' if block_given? && default fail ArgumentError, 'contract-options is required' if contract.nil? Contract contract add_option(name, block_given? ? yield(InConfigWrapper.new()) : default) define_method(name) { find_option(name).value } self end |
Instance Method Details
#==(other) ⇒ Object
214 215 216 |
# File 'lib/aruba/basic_configuration.rb', line 214 def ==(other) .values.map(&:value) == other..values.map(&:value) end |
#after(name, context = proc {}, *args) { ... } ⇒ Object
Define or run after-hook
180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/aruba/basic_configuration.rb', line 180 def after(name, context = proc {}, *args, &block) name = format('%s_%s', 'after_', name.to_s).to_sym if block_given? @hooks.append(name, block) self else @hooks.execute(name, context, *args) end end |
#after?(name) ⇒ Boolean
Check if after-hook
200 201 202 203 204 |
# File 'lib/aruba/basic_configuration.rb', line 200 def after?(name) name = format('%s_%s', 'after_', name.to_s).to_sym @hooks.exist? name end |
#before(name, context = proc {}, *args) { ... } ⇒ Object
Define or run before-hook
155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/aruba/basic_configuration.rb', line 155 def before(name, context = proc {}, *args, &block) name = format('%s_%s', 'before_', name.to_s).to_sym if block_given? @hooks.append(name, block) self else @hooks.execute(name, context, *args) end end |
#before?(name) ⇒ Boolean
Check if before-hook
193 194 195 196 197 |
# File 'lib/aruba/basic_configuration.rb', line 193 def before?(name) name = format('%s_%s', 'before_', name.to_s).to_sym @hooks.exist? name end |
#before_cmd(&block) ⇒ Object
Deprecated.
136 137 138 139 140 |
# File 'lib/aruba/basic_configuration.rb', line 136 def before_cmd(&block) Aruba.platform.deprecated 'The use of the "#before_cmd"-hook is deprecated. Please define with "#before(:command) {}" instead' before(:command, &block) end |
#configure {|Configuration| ... } ⇒ Object
108 109 110 |
# File 'lib/aruba/basic_configuration.rb', line 108 def configure yield self if block_given? end |
#make_copy ⇒ Object
Make deep dup copy of configuration
118 119 120 121 122 123 124 |
# File 'lib/aruba/basic_configuration.rb', line 118 def make_copy obj = self.dup obj. = Marshal.load(Marshal.dump()) obj.hooks = @hooks obj end |
#option?(name) ⇒ Boolean
Check if
210 211 212 |
# File 'lib/aruba/basic_configuration.rb', line 210 def option?(name) .any? { |_, v| v.name == name.to_sym } end |
#reset ⇒ Object
Reset configuration
113 114 115 |
# File 'lib/aruba/basic_configuration.rb', line 113 def reset initialize_configuration end |
#set_if_option(name, *args) ⇒ Object
Set if name is option
219 220 221 222 223 224 225 |
# File 'lib/aruba/basic_configuration.rb', line 219 def set_if_option(name, *args) if RUBY_VERSION < '1.9' send("#{name}=".to_sym, *args) if option? name else public_send("#{name}=".to_sym, *args) if option? name end end |