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::ContextNoteId, ActiveFacts::Metamodel::FactId, ActiveFacts::Metamodel::FactTypeId, ActiveFacts::Metamodel::InstanceId, ActiveFacts::Metamodel::JoinId, ActiveFacts::Metamodel::RoleSequenceId, ActiveFacts::Metamodel::ShapeId, ActiveFacts::Metamodel::UnitId
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.
112 113 114 115 116 |
# File 'lib/activefacts/api/numeric.rb', line 112 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
138 139 140 141 |
# File 'lib/activefacts/api/numeric.rb', line 138 def self.coerce(i) raise ArgumentError unless @value [ i.to_i, @value ] end |
.inherited(other) ⇒ Object
:nodoc:
155 156 157 158 159 160 161 |
# File 'lib/activefacts/api/numeric.rb', line 155 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
119 120 121 122 |
# File 'lib/activefacts/api/numeric.rb', line 119 def assign(i) raise ArgumentError if @value @value = i.to_i end |
#defined? ⇒ Boolean
Ask whether a definite value has been assigned
125 126 127 |
# File 'lib/activefacts/api/numeric.rb', line 125 def defined? !@value.nil? end |
#eql?(o) ⇒ Boolean
:nodoc:
151 152 153 |
# File 'lib/activefacts/api/numeric.rb', line 151 def eql?(o) #:nodoc: self.class == o.class and to_s.eql?(o.to_s) end |
#hash ⇒ Object
:nodoc:
147 148 149 |
# File 'lib/activefacts/api/numeric.rb', line 147 def hash #:nodoc: to_s.hash ^ self.class.hash end |
#inspect ⇒ Object
143 144 145 |
# File 'lib/activefacts/api/numeric.rb', line 143 def inspect "\#<AutoCounter "+to_s+">" end |
#to_s ⇒ Object
129 130 131 132 133 134 135 |
# File 'lib/activefacts/api/numeric.rb', line 129 def to_s if self.defined? @value.to_s else "new_#{object_id}" end end |