Class: AutoCounter
- Inherits:
-
Object
- Object
- AutoCounter
- Defined in:
- lib/activefacts/api/numeric.rb
Overview
The AutoCounter class is an integer, but only after the value has been established in the database. Construct it with the value :new to get an uncommitted value. You can use this new instance as a value of any role of this type, including to identify an entity instance. The assigned value will be filled out everywhere it needs to be, upon save.
Direct Known Subclasses
ActiveFacts::Metamodel::ConstraintId, ActiveFacts::Metamodel::FactId, ActiveFacts::Metamodel::FactTypeId, ActiveFacts::Metamodel::InstanceId, ActiveFacts::Metamodel::RoleSequenceId, ActiveFacts::Metamodel::UnitId, ActiveFacts::Metamodel::ValueRestrictionId
Class Method Summary collapse
-
.coerce(i) ⇒ Object
An AutoCounter may only be used in numeric expressions after a definite value has been assigned.
-
.inherited(other) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#assign(i) ⇒ Object
Assign a definite value to an AutoCounter; this may only be done once.
-
#defined? ⇒ Boolean
Ask whether a definite value has been assigned.
-
#eql?(o) ⇒ Boolean
:nodoc:.
-
#hash ⇒ Object
:nodoc:.
-
#initialize(i = :new) ⇒ AutoCounter
constructor
A new instance of AutoCounter.
- #inspect ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(i = :new) ⇒ AutoCounter
Returns a new instance of AutoCounter.
110 111 112 113 114 |
# File 'lib/activefacts/api/numeric.rb', line 110 def initialize(i = :new) raise "AutoCounter #{self.class} may not be #{i.inspect}" unless i == :new or Integer === i # puts "new AutoCounter #{self.class} from\n\t#{caller.select{|s| s !~ %r{rspec}}*"\n\t"}" @value = i == :new ? nil : i end |
Class Method Details
.coerce(i) ⇒ Object
An AutoCounter may only be used in numeric expressions after a definite value has been assigned
136 137 138 139 |
# File 'lib/activefacts/api/numeric.rb', line 136 def self.coerce(i) raise ArgumentError unless @value [ i.to_i, @value ] end |
.inherited(other) ⇒ Object
:nodoc:
153 154 155 156 157 158 159 |
# File 'lib/activefacts/api/numeric.rb', line 153 def self.inherited(other) #:nodoc: def other.(*args) return nil if args == [:new] # A new object has no identifying_role_values return new(*args) end super end |
Instance Method Details
#assign(i) ⇒ Object
Assign a definite value to an AutoCounter; this may only be done once
117 118 119 120 |
# File 'lib/activefacts/api/numeric.rb', line 117 def assign(i) raise ArgumentError if @value @value = i.to_i end |
#defined? ⇒ Boolean
Ask whether a definite value has been assigned
123 124 125 |
# File 'lib/activefacts/api/numeric.rb', line 123 def defined? !@value.nil? end |
#eql?(o) ⇒ Boolean
:nodoc:
149 150 151 |
# File 'lib/activefacts/api/numeric.rb', line 149 def eql?(o) #:nodoc: self.class == o.class and to_s.eql?(o.to_s) end |
#hash ⇒ Object
:nodoc:
145 146 147 |
# File 'lib/activefacts/api/numeric.rb', line 145 def hash #:nodoc: to_s.hash ^ self.class.hash end |
#inspect ⇒ Object
141 142 143 |
# File 'lib/activefacts/api/numeric.rb', line 141 def inspect "\#<AutoCounter "+to_s+">" end |
#to_s ⇒ Object
127 128 129 130 131 132 133 |
# File 'lib/activefacts/api/numeric.rb', line 127 def to_s if self.defined? @value.to_s else "new_#{object_id}" end end |