Class: Cuboid::OptionGroup
Overview
Direct Known Subclasses
Cuboid::OptionGroups::Agent, Cuboid::OptionGroups::Datastore, Cuboid::OptionGroups::Output, Cuboid::OptionGroups::Paths, Cuboid::OptionGroups::RPC, Cuboid::OptionGroups::Report, Cuboid::OptionGroups::Scheduler, Cuboid::OptionGroups::System
Defined Under Namespace
Classes: Error
Class Method Summary collapse
- .attr_accessor(*vars) ⇒ Object
- .attributes ⇒ Object
-
.defaults ⇒ Hash
Specified default values for attribute readers.
- .inherited(child) ⇒ Object
-
.set_defaults(default_values) ⇒ Object
Sets default values for attribute readers, when an attribute reader returns ‘nil` the default values will be returned instead.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #attributes ⇒ Object
-
#defaults ⇒ Hash
Specified default values for attribute readers.
- #hash ⇒ Object
-
#initialize ⇒ OptionGroup
constructor
A new instance of OptionGroup.
-
#merge(other) ⇒ OptionGroup
‘self`.
-
#to_h ⇒ Hash
Values for all attribute accessors which aren’t the defaults.
- #to_hash ⇒ Object
- #to_rpc_data ⇒ Object
-
#update(options) ⇒ OptionGroup
‘self`.
-
#validate ⇒ Hash
abstract
Hash of errors with the name of the invalid options as the keys.
Constructor Details
#initialize ⇒ OptionGroup
Returns a new instance of OptionGroup.
42 43 44 45 46 |
# File 'lib/cuboid/option_group.rb', line 42 def initialize defaults.each do |k, v| send "#{k}=", v end end |
Class Method Details
.attr_accessor(*vars) ⇒ Object
110 111 112 113 |
# File 'lib/cuboid/option_group.rb', line 110 def self.attr_accessor( *vars ) attributes.concat( vars ) super( *vars ) end |
.attributes ⇒ Object
115 116 117 |
# File 'lib/cuboid/option_group.rb', line 115 def self.attributes @attributes ||= [] end |
.defaults ⇒ Hash
Returns Specified default values for attribute readers.
14 15 16 |
# File 'lib/cuboid/option_group.rb', line 14 def defaults @defaults ||= {} end |
.inherited(child) ⇒ Object
37 38 39 |
# File 'lib/cuboid/option_group.rb', line 37 def inherited( child ) Options.register_group child end |
.set_defaults(default_values) ⇒ Object
Sets default values for attribute readers, when an attribute reader returns ‘nil` the default values will be returned instead.
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/cuboid/option_group.rb', line 23 def set_defaults( default_values ) defaults.merge! default_values # Set the specified default values as overrides to the attribute # readers. defaults.each do |ivar, value| define_method "#{ivar}=" do |v| instance_variable_set( "@#{ivar}".to_sym, v.nil? ? value : v) end end defaults end |
Instance Method Details
#==(other) ⇒ Object
79 80 81 |
# File 'lib/cuboid/option_group.rb', line 79 def ==( other ) hash == other.hash end |
#attributes ⇒ Object
119 120 121 |
# File 'lib/cuboid/option_group.rb', line 119 def attributes self.class.attributes end |
#defaults ⇒ Hash
Returns Specified default values for attribute readers.
106 107 108 |
# File 'lib/cuboid/option_group.rb', line 106 def defaults self.class.defaults end |
#hash ⇒ Object
83 84 85 |
# File 'lib/cuboid/option_group.rb', line 83 def hash to_h.hash end |
#merge(other) ⇒ OptionGroup
Returns ‘self`.
101 102 103 |
# File 'lib/cuboid/option_group.rb', line 101 def merge( other ) update( other.to_h ) end |
#to_h ⇒ Hash
Returns Values for all attribute accessors which aren’t the defaults.
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/cuboid/option_group.rb', line 54 def to_h h = {} instance_variables.each do |ivar| method = normalize_ivar( ivar ) sym = method.to_sym value = instance_variable_get( ivar ) next if !respond_to?( "#{method}=" ) h[sym] = value end h end |
#to_hash ⇒ Object
67 68 69 |
# File 'lib/cuboid/option_group.rb', line 67 def to_hash to_h end |
#to_rpc_data ⇒ Object
48 49 50 |
# File 'lib/cuboid/option_group.rb', line 48 def to_rpc_data to_h.my_stringify_keys(false) end |
#update(options) ⇒ OptionGroup
Returns ‘self`.
92 93 94 95 |
# File 'lib/cuboid/option_group.rb', line 92 def update( ) .to_hash.each { |k, v| send( "#{k}=", v ) } self end |
#validate ⇒ Hash
Returns Hash of errors with the name of the invalid options as the keys.
75 76 77 |
# File 'lib/cuboid/option_group.rb', line 75 def validate {} end |