Class: NoSE::Fields::Field
- Includes:
- Supertype
- Defined in:
- lib/nose/model/fields.rb
Overview
A single field on an Entity
Direct Known Subclasses
BooleanField, DateField, FloatField, HashField, IDField, IntegerField, StringField
Constant Summary collapse
- TYPE =
The Ruby type of values stored in this field
nil
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#primary_key ⇒ Object
(also: #primary_key?)
Returns the value of attribute primary_key.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Class Method Summary collapse
-
.value_from_string(_string) ⇒ Object
abstract
:nocov:.
Instance Method Summary collapse
-
#*(other) ⇒ Field
Set the estimated cardinality of the field.
-
#==(other) ⇒ Object
(also: #eql?)
Compare by parent entity and name.
-
#cardinality ⇒ Object
Return the previously set cardinality, falling back to the number of entities for the field if set, or just 1.
-
#hash ⇒ Fixnum
Hash by entity and name.
-
#id ⇒ Object
A simple string representing the field.
-
#initialize(name, size, count: nil) ⇒ Field
constructor
A new instance of Field.
-
#random_value ⇒ Object
abstract
:nocov:.
-
#to_color ⇒ Object
:nocov:.
-
#to_s ⇒ Object
:nocov:.
Methods included from Supertype
Constructor Details
#initialize(name, size, count: nil) ⇒ Field
Returns a new instance of Field.
22 23 24 25 26 27 |
# File 'lib/nose/model/fields.rb', line 22 def initialize(name, size, count: nil) @name = name @size = size @cardinality = count @primary_key = false end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
15 16 17 |
# File 'lib/nose/model/fields.rb', line 15 def name @name end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
15 16 17 |
# File 'lib/nose/model/fields.rb', line 15 def parent @parent end |
#primary_key ⇒ Object Also known as: primary_key?
Returns the value of attribute primary_key.
16 17 18 |
# File 'lib/nose/model/fields.rb', line 16 def primary_key @primary_key end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
15 16 17 |
# File 'lib/nose/model/fields.rb', line 15 def size @size end |
Class Method Details
.value_from_string(_string) ⇒ Object
Subclasses should produce a typed value from a string
:nocov:
74 75 76 |
# File 'lib/nose/model/fields.rb', line 74 def self.value_from_string(_string) fail NotImplementedError end |
Instance Method Details
#*(other) ⇒ Field
Set the estimated cardinality of the field
61 62 63 64 |
# File 'lib/nose/model/fields.rb', line 61 def *(other) @cardinality = other self end |
#==(other) ⇒ Object Also known as: eql?
Compare by parent entity and name
30 31 32 33 |
# File 'lib/nose/model/fields.rb', line 30 def ==(other) other.is_a?(Field) && @parent == other.parent && @name == other.name end |
#cardinality ⇒ Object
Return the previously set cardinality, falling back to the number of entities for the field if set, or just 1
68 69 70 |
# File 'lib/nose/model/fields.rb', line 68 def cardinality @cardinality || @parent.count || 1 end |
#hash ⇒ Fixnum
Hash by entity and name
38 39 40 |
# File 'lib/nose/model/fields.rb', line 38 def hash @hash ||= id.hash end |
#id ⇒ Object
A simple string representing the field
55 56 57 |
# File 'lib/nose/model/fields.rb', line 55 def id @id ||= "#{@parent.name}_#{@name}" end |
#random_value ⇒ Object
Subclasses should produce a random value of the correct type
:nocov:
81 82 83 |
# File 'lib/nose/model/fields.rb', line 81 def random_value fail NotImplementedError end |
#to_color ⇒ Object
:nocov:
43 44 45 |
# File 'lib/nose/model/fields.rb', line 43 def to_color "[blue]#{@parent.name}[/].[blue]#{@name}[/]" end |
#to_s ⇒ Object
:nocov:
49 50 51 |
# File 'lib/nose/model/fields.rb', line 49 def to_s "#{@parent.name}.#{@name}" end |