Class: MxxRu::Cpp::GlobalSingleValueOption
- Inherits:
-
Object
- Object
- MxxRu::Cpp::GlobalSingleValueOption
- Defined in:
- lib/mxx_ru/cpp/target.rb
Overview
Auxiliary class, intended to store objects like runtime_mode, rtl_mode, etc, with information about who has set this or that mode.
Instance Attribute Summary collapse
-
#default_value ⇒ Object
readonly
Returns the value of attribute default_value.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
-
#who ⇒ Object
readonly
Returns the value of attribute who.
Instance Method Summary collapse
-
#change(a_value, a_who) ⇒ Object
Value change.
-
#change_default(a_value, a_who) ⇒ Object
Change default value.
-
#initialize(a_name, a_default_value, a_available_values) ⇒ GlobalSingleValueOption
constructor
- a_name
-
Name.
Constructor Details
#initialize(a_name, a_default_value, a_available_values) ⇒ GlobalSingleValueOption
- a_name
-
Name.
- a_default_value
-
Default value.
- a_available_values
-
Available values. Array of String.
102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/mxx_ru/cpp/target.rb', line 102 def initialize( a_name, a_default_value, a_available_values ) @name = a_name @default_value = a_default_value @default_value_changer = nil @available_values = a_available_values @value = @default_value @who = "n/a" end |
Instance Attribute Details
#default_value ⇒ Object (readonly)
Returns the value of attribute default_value.
95 96 97 |
# File 'lib/mxx_ru/cpp/target.rb', line 95 def default_value @default_value end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
94 95 96 |
# File 'lib/mxx_ru/cpp/target.rb', line 94 def name @name end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
96 97 98 |
# File 'lib/mxx_ru/cpp/target.rb', line 96 def value @value end |
#who ⇒ Object (readonly)
Returns the value of attribute who.
97 98 99 |
# File 'lib/mxx_ru/cpp/target.rb', line 97 def who @who end |
Instance Method Details
#change(a_value, a_who) ⇒ Object
Value change. If new value is the same as default, value change try is ignored.
- a_value
-
New value.
- a_who
-
Who tries to change value.
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/mxx_ru/cpp/target.rb', line 141 def change( a_value, a_who ) if a_value != @default_value check_value( a_value, a_who ) if @value == @default_value # Value did not change till now. @value = a_value @who = a_who else # Value is already changed. It is necessary to be convinced, # that values are the same. Otherwise there is a conflict. if a_value != @value raise MxxRu::GlobalOptionConflictEx.new( @name, @value, @who, a_value, a_who ) end end end end |
#change_default(a_value, a_who) ⇒ Object
Change default value.
Description of this change is printed to standard output.
- a_value
-
new default value.
- a_who
-
who tries to change value.
121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/mxx_ru/cpp/target.rb', line 121 def change_default( a_value, a_who ) check_value( a_value, a_who ) if nil == @default_value_changer need_change_current = ( @value == @default_value ) @default_value = a_value @default_value_changer = a_who @value = @default_value if need_change_current elsif a_value != @default_value puts "WARNING: ignoring change default value for '#{@name}' to " + "'#{a_value}' by '#{a_who}'; default value already changed by " + "'#{@default_value_changer}'" end end |