Class: AutoCounter
- Inherits:
-
Object
- Object
- AutoCounter
- Defined in:
- lib/activefacts/api/numeric.rb
Instance Attribute Summary collapse
-
#place_holder_number ⇒ Object
readonly
Returns the value of attribute place_holder_number.
Class Method Summary collapse
-
.inherited(other) ⇒ Object
extend ActiveFacts::AutoCounterClass.
Instance Method Summary collapse
-
#<=>(o) ⇒ Object
:nodoc:.
-
#assign(i) ⇒ Object
Assign a definite value to an AutoCounter; this may only be done once.
- #clone ⇒ Object
-
#coerce(i) ⇒ Object
Coerce “i” to be of the same type as self.
-
#defined? ⇒ Boolean
Ask whether a definite value has been assigned.
-
#eql?(o) ⇒ Boolean
:nodoc:.
-
#equal?(value) ⇒ Boolean
if the value is unassigned, it equal?(:new).
-
#hash ⇒ Object
:nodoc:.
- #identifying_role_values(klass = nil) ⇒ Object
-
#initialize(i = :new) ⇒ AutoCounter
constructor
A new instance of AutoCounter.
- #inspect ⇒ Object
-
#to_i ⇒ Object
An AutoCounter may only be used in numeric expressions after a definite value has been assigned.
- #to_s ⇒ Object
Constructor Details
#initialize(i = :new) ⇒ AutoCounter
Returns a new instance of AutoCounter.
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/activefacts/api/numeric.rb', line 119 def initialize(i = :new) unless i == :new or i.is_a?(Integer) or i.is_a?(AutoCounter) raise ArgumentError.new("AutoCounter #{self.class} may not be #{i.inspect}") end @@place_holder ||= 0 case i when :new @value = nil @place_holder_number = (@@place_holder+=1) when AutoCounter if i.defined? @value = i.to_i else @place_holder_number = i.place_holder_number @value = nil end else @place_holder_number = @value = i.to_i; end end |
Instance Attribute Details
#place_holder_number ⇒ Object (readonly)
Returns the value of attribute place_holder_number.
118 119 120 |
# File 'lib/activefacts/api/numeric.rb', line 118 def place_holder_number @place_holder_number end |
Class Method Details
.inherited(other) ⇒ Object
extend ActiveFacts::AutoCounterClass
213 214 215 216 217 218 |
# File 'lib/activefacts/api/numeric.rb', line 213 def self.inherited(other) #:nodoc: other.class_eval do extend ActiveFacts::AutoCounterClass end super end |
Instance Method Details
#<=>(o) ⇒ Object
:nodoc:
196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/activefacts/api/numeric.rb', line 196 def <=>(o) #:nodoc: if self.defined? && !o == [] && o.defined? if (c = (self.class <=> o.class.name)) != 0 return c else return to_i <=> o.to_i end else to_s.<=>(o.to_s) end end |
#assign(i) ⇒ Object
Assign a definite value to an AutoCounter; this may only be done once
141 142 143 144 |
# File 'lib/activefacts/api/numeric.rb', line 141 def assign(i) raise ArgumentError, "Illegal attempt to assign integer value of a committed AutoCounter" if @value @value = i.to_i end |
#clone ⇒ Object
220 221 222 |
# File 'lib/activefacts/api/numeric.rb', line 220 def clone raise "Not allowed to clone AutoCounters" end |
#coerce(i) ⇒ Object
Coerce “i” to be of the same type as self
173 174 175 176 177 178 |
# File 'lib/activefacts/api/numeric.rb', line 173 def coerce(i) unless @value raise ArgumentError, "Illegal attempt to use the value of an uncommitted AutoCounter" end [ i.to_i, @value ] end |
#defined? ⇒ Boolean
Ask whether a definite value has been assigned
147 148 149 |
# File 'lib/activefacts/api/numeric.rb', line 147 def defined? !@value.nil? end |
#eql?(o) ⇒ Boolean
:nodoc:
192 193 194 |
# File 'lib/activefacts/api/numeric.rb', line 192 def eql?(o) #:nodoc: to_s.eql?(o.to_s) end |
#equal?(value) ⇒ Boolean
if the value is unassigned, it equal?(:new).
160 161 162 |
# File 'lib/activefacts/api/numeric.rb', line 160 def equal? value value == :new ? @value == nil : super end |
#hash ⇒ Object
:nodoc:
184 185 186 187 188 189 190 |
# File 'lib/activefacts/api/numeric.rb', line 184 def hash #:nodoc: if self.defined? @value.hash else @place_holder_number end end |
#identifying_role_values(klass = nil) ⇒ Object
208 209 210 |
# File 'lib/activefacts/api/numeric.rb', line 208 def klass = nil self end |
#inspect ⇒ Object
180 181 182 |
# File 'lib/activefacts/api/numeric.rb', line 180 def inspect "\#<AutoCounter "+to_s+">" end |
#to_i ⇒ Object
An AutoCounter may only be used in numeric expressions after a definite value has been assigned
165 166 167 168 169 170 |
# File 'lib/activefacts/api/numeric.rb', line 165 def to_i unless @value raise ArgumentError, "Illegal attempt to get integer value of an uncommitted AutoCounter" end @value end |
#to_s ⇒ Object
151 152 153 154 155 156 157 |
# File 'lib/activefacts/api/numeric.rb', line 151 def to_s if self.defined? @value.to_s else "new_#{@place_holder_number}" end end |