Class: ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Range
- Inherits:
-
Type::Value
- Object
- ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Range
- Defined in:
- lib/active_record/connection_adapters/postgresql/oid/range.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#subtype ⇒ Object
readonly
Returns the value of attribute subtype.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #cast_value(value) ⇒ Object
- #force_equality?(value) ⇒ Boolean
-
#initialize(subtype, type = :range) ⇒ Range
constructor
A new instance of Range.
-
#map(value) ⇒ Object
:nodoc:.
- #serialize(value) ⇒ Object
- #type_cast_for_schema(value) ⇒ Object
Constructor Details
#initialize(subtype, type = :range) ⇒ Range
Returns a new instance of Range.
11 12 13 14 |
# File 'lib/active_record/connection_adapters/postgresql/oid/range.rb', line 11 def initialize(subtype, type = :range) @subtype = subtype @type = type end |
Instance Attribute Details
#subtype ⇒ Object (readonly)
Returns the value of attribute subtype.
8 9 10 |
# File 'lib/active_record/connection_adapters/postgresql/oid/range.rb', line 8 def subtype @subtype end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
8 9 10 |
# File 'lib/active_record/connection_adapters/postgresql/oid/range.rb', line 8 def type @type end |
Instance Method Details
#==(other) ⇒ Object
44 45 46 47 48 |
# File 'lib/active_record/connection_adapters/postgresql/oid/range.rb', line 44 def ==(other) other.is_a?(Range) && other.subtype == subtype && other.type == type end |
#cast_value(value) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/active_record/connection_adapters/postgresql/oid/range.rb', line 20 def cast_value(value) return if ["empty", ""].include? value return value unless value.is_a?(::String) extracted = extract_bounds(value) from = type_cast_single extracted[:from] to = type_cast_single extracted[:to] if !infinity?(from) && extracted[:exclude_start] raise ArgumentError, "The Ruby Range object does not support excluding the beginning of a Range. (unsupported value: '#{value}')" end ::Range.new(*sanitize_bounds(from, to), extracted[:exclude_end]) end |
#force_equality?(value) ⇒ Boolean
56 57 58 |
# File 'lib/active_record/connection_adapters/postgresql/oid/range.rb', line 56 def force_equality?(value) value.is_a?(::Range) end |
#map(value) ⇒ Object
:nodoc:
50 51 52 53 54 |
# File 'lib/active_record/connection_adapters/postgresql/oid/range.rb', line 50 def map(value) # :nodoc: new_begin = yield(value.begin) new_end = yield(value.end) ::Range.new(new_begin, new_end, value.exclude_end?) end |
#serialize(value) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/active_record/connection_adapters/postgresql/oid/range.rb', line 34 def serialize(value) if value.is_a?(::Range) from = type_cast_single_for_database(value.begin) to = type_cast_single_for_database(value.end) ::Range.new(from, to, value.exclude_end?) else super end end |
#type_cast_for_schema(value) ⇒ Object
16 17 18 |
# File 'lib/active_record/connection_adapters/postgresql/oid/range.rb', line 16 def type_cast_for_schema(value) value.inspect.gsub("Infinity", "::Float::INFINITY") end |