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
47 48 49 50 51 |
# File 'lib/active_record/connection_adapters/postgresql/oid/range.rb', line 47 def ==(other) other.is_a?(Range) && other.subtype == subtype && other.type == type end |
#cast_value(value) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/active_record/connection_adapters/postgresql/oid/range.rb', line 23 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
59 60 61 |
# File 'lib/active_record/connection_adapters/postgresql/oid/range.rb', line 59 def force_equality?(value) value.is_a?(::Range) end |
#map(value) ⇒ Object
:nodoc:
53 54 55 56 57 |
# File 'lib/active_record/connection_adapters/postgresql/oid/range.rb', line 53 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
37 38 39 40 41 42 43 44 45 |
# File 'lib/active_record/connection_adapters/postgresql/oid/range.rb', line 37 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 19 20 21 |
# File 'lib/active_record/connection_adapters/postgresql/oid/range.rb', line 16 def type_cast_for_schema(value) from = bound_for_schema(value.begin) to = bound_for_schema(value.end) op = value.exclude_end? ? "..." : ".." "#{from}#{op}#{to}" end |