Class: ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Range
| Relationships & Source Files | |
| Super Chains via Extension / Inclusion / Inheritance | |
| Class Chain: | |
| Instance Chain: | |
| Inherits: | ActiveModel::Type::Value 
 | 
| Defined in: | activerecord/lib/active_record/connection_adapters/postgresql/oid/range.rb | 
Constant Summary
- 
    INFINITE_FLOAT_RANGE =
    
 # File 'activerecord/lib/active_record/connection_adapters/postgresql/oid/range.rb', line 79(-::Float::INFINITY)..(::Float::INFINITY) 
Class Method Summary
- .new(subtype, type = :range) ⇒ Range constructor
::ActiveModel::Type::Value - Inherited
| .new | Initializes a type with three basic configuration settings: precision, limit, and scale. | 
Instance Attribute Summary
- #subtype readonly
- #type readonly
- #user_input_in_time_zone readonly
::ActiveModel::Type::Value - Inherited
| #limit, #precision, #scale, | |
| #binary? | These predicates are not documented, as I need to look further into their use, and see if they can be removed entirely. | 
| #mutable?, #serialized? | |
Instance Method Summary
- #==(other)
- #cast_value(value)
- #force_equality?(value) ⇒ Boolean
- #map(value)
- #serialize(value)
- #type_cast_for_schema(value)
- #extract_bounds(value) private
- #infinity(negative: false) private
- #infinity?(value) ⇒ Boolean private
- #sanitize_bounds(from, to) private
- #type_cast_single(value) private
- #type_cast_single_for_database(value) private
- 
    
      #unquote(value)  
    
    private
    When formatting the bound values of range types, ::ActiveRecord::ConnectionAdapters::PostgreSQLquotes the bound value using double-quotes in certain conditions.
::ActiveModel::Type::Value - Inherited
| #==, #as_json, #assert_valid_value, | |
| #cast | 
 | 
| #changed? | Determines whether a value has changed for dirty checking. | 
| #changed_in_place? | Determines whether the mutable value has been modified since it was read. | 
| #deserialize | Converts a value from database input to the appropriate ruby type. | 
| #eql? | Alias for ActiveModel::Type::Value#==. | 
| #hash, | |
| #serializable? | Returns true if this type can convert  | 
| #serialize | Casts a value from the ruby type to a type that the database knows how to understand. | 
| #type | Returns the unique type name as a  | 
| #cast_value | Convenience method for types which do not need separate type casting behavior for user and database inputs. | 
| #force_equality?, #map, | |
| #type_cast_for_schema | 
 | 
| #value_constructed_by_mass_assignment? | |
::ActiveModel::Type::SerializeCastValue - Included
Constructor Details
    .new(subtype, type = :range)  ⇒ Range 
  
Instance Attribute Details
#subtype (readonly)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/postgresql/oid/range.rb', line 8
attr_reader :subtype, :type
#type (readonly)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/postgresql/oid/range.rb', line 8
attr_reader :subtype, :type
#user_input_in_time_zone (readonly)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/postgresql/oid/range.rb', line 9
delegate :user_input_in_time_zone, to: :subtype
Instance Method Details
#==(other)
[ GitHub ]#cast_value(value)
[ GitHub ]# File 'activerecord/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
#extract_bounds(value) (private)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/postgresql/oid/range.rb', line 69
def extract_bounds(value) from, to = value[1..-2].split(",", 2) { from: (from == "" || from == "-infinity") ? infinity(negative: true) : unquote(from), to: (to == "" || to == "infinity") ? infinity : unquote(to), exclude_start: value.start_with?("("), exclude_end: value.end_with?(")") } end
    #force_equality?(value)  ⇒ Boolean 
  
# File 'activerecord/lib/active_record/connection_adapters/postgresql/oid/range.rb', line 56
def force_equality?(value) value.is_a?(::Range) end
#infinity(negative: false) (private)
[ GitHub ]
    #infinity?(value)  ⇒ Boolean  (private)
  
# File 'activerecord/lib/active_record/connection_adapters/postgresql/oid/range.rb', line 117
def infinity?(value) value.respond_to?(:infinite?) && value.infinite? end
#map(value)
[ GitHub ]#sanitize_bounds(from, to) (private)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/postgresql/oid/range.rb', line 81
def sanitize_bounds(from, to) [ (from == -::Float::INFINITY && !INFINITE_FLOAT_RANGE.cover?(to)) ? nil : from, (to == ::Float::INFINITY && !INFINITE_FLOAT_RANGE.cover?(from)) ? nil : to ] end
#serialize(value)
[ GitHub ]# File 'activerecord/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)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/postgresql/oid/range.rb', line 16
def type_cast_for_schema(value) value.inspect.gsub("Infinity", "::Float::INFINITY") end
#type_cast_single(value) (private)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/postgresql/oid/range.rb', line 61
def type_cast_single(value) infinity?(value) ? value : @subtype.deserialize(value) end
#type_cast_single_for_database(value) (private)
[ GitHub ]#unquote(value) (private)
When formatting the bound values of range types, ::ActiveRecord::ConnectionAdapters::PostgreSQL quotes the bound value using double-quotes in certain conditions. Within a double-quoted string, literal “ and \ characters are themselves escaped. In input, ::ActiveRecord::ConnectionAdapters::PostgreSQL accepts multiple escape styles for ” (either " or “”) but in output always uses “”. See:
# File 'activerecord/lib/active_record/connection_adapters/postgresql/oid/range.rb', line 96
def unquote(value) if value.start_with?('"') && value.end_with?('"') unquoted_value = value[1..-2] unquoted_value.gsub!('""', '"') unquoted_value.gsub!("\\\\", "\\") unquoted_value else value end end