Class: ActiveRecord::Type::Value

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/type/value.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Value

Valid options are precision, scale, and limit. They are only used when dumping schema.



8
9
10
11
12
13
# File 'lib/active_record/type/value.rb', line 8

def initialize(options = {})
  options.assert_valid_keys(:precision, :scale, :limit)
  @precision = options[:precision]
  @scale = options[:scale]
  @limit = options[:limit]
end

Instance Attribute Details

#limitObject (readonly)

Returns the value of attribute limit.



4
5
6
# File 'lib/active_record/type/value.rb', line 4

def limit
  @limit
end

#precisionObject (readonly)

Returns the value of attribute precision.



4
5
6
# File 'lib/active_record/type/value.rb', line 4

def precision
  @precision
end

#scaleObject (readonly)

Returns the value of attribute scale.



4
5
6
# File 'lib/active_record/type/value.rb', line 4

def scale
  @scale
end

Instance Method Details

#==(other) ⇒ Object



83
84
85
86
87
88
# File 'lib/active_record/type/value.rb', line 83

def ==(other)
  self.class == other.class &&
    precision == other.precision &&
    scale == other.scale &&
    limit == other.limit
end

#binary?Boolean

:nodoc:

Returns:



61
62
63
# File 'lib/active_record/type/value.rb', line 61

def binary? # :nodoc:
  false
end

#changed?(old_value, new_value, _new_value_before_type_cast) ⇒ Boolean

Determines whether a value has changed for dirty checking. old_value and new_value will always be type-cast. Types should not need to override this method.

Returns:



71
72
73
# File 'lib/active_record/type/value.rb', line 71

def changed?(old_value, new_value, _new_value_before_type_cast)
  old_value != new_value
end

#changed_in_place?Boolean

Determines whether the mutable value has been modified since it was read. Returns false by default. This method should not be overridden directly. Types which return a mutable value should include Type::Mutable, which will define this method.

Returns:



79
80
81
# File 'lib/active_record/type/value.rb', line 79

def changed_in_place?(*)
  false
end

#klassObject

:nodoc:



65
66
# File 'lib/active_record/type/value.rb', line 65

def klass # :nodoc:
end

#number?Boolean

:nodoc:

Returns:



57
58
59
# File 'lib/active_record/type/value.rb', line 57

def number? # :nodoc:
  false
end

#text?Boolean

These predicates are not documented, as I need to look further into their use, and see if they can be removed entirely.

Returns:



53
54
55
# File 'lib/active_record/type/value.rb', line 53

def text? # :nodoc:
  false
end

#typeObject

The simplified type that this object represents. Returns a symbol such as :string or :integer



17
# File 'lib/active_record/type/value.rb', line 17

def type; end

#type_cast_for_database(value) ⇒ Object

Cast a value from the ruby type to a type that the database knows how to understand. The returned value from this method should be a String, Numeric, Date, Time, Symbol, true, false, or nil



41
42
43
# File 'lib/active_record/type/value.rb', line 41

def type_cast_for_database(value)
  value
end

#type_cast_for_schema(value) ⇒ Object

Type cast a value for schema dumping. This method is private, as we are hoping to remove it entirely.



47
48
49
# File 'lib/active_record/type/value.rb', line 47

def type_cast_for_schema(value) # :nodoc:
  value.inspect
end

#type_cast_from_database(value) ⇒ Object

Type casts a string from the database into the appropriate ruby type. Classes which do not need separate type casting behavior for database and user provided values should override cast_value instead.



22
23
24
# File 'lib/active_record/type/value.rb', line 22

def type_cast_from_database(value)
  type_cast(value)
end

#type_cast_from_user(value) ⇒ Object

Type casts a value from user input (e.g. from a setter). This value may be a string from the form builder, or an already type cast value provided manually to a setter.

Classes which do not need separate type casting behavior for database and user provided values should override type_cast or cast_value instead.



33
34
35
# File 'lib/active_record/type/value.rb', line 33

def type_cast_from_user(value)
  type_cast(value)
end