Class: ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Range
- Defined in:
- lib/arjdbc/postgresql/base/oid.rb
Instance Attribute Summary collapse
-
#subtype ⇒ Object
readonly
Returns the value of attribute subtype.
Instance Method Summary collapse
- #extract_bounds(value) ⇒ Object
- #infinity?(value) ⇒ Boolean
-
#initialize(subtype) ⇒ Range
constructor
A new instance of Range.
- #simplified_type(sql_type) ⇒ Object
- #type_cast(value) ⇒ Object
- #type_cast_single(value) ⇒ Object
Methods inherited from Type
Constructor Details
#initialize(subtype) ⇒ Range
Returns a new instance of Range.
157 158 159 |
# File 'lib/arjdbc/postgresql/base/oid.rb', line 157 def initialize(subtype) @subtype = subtype end |
Instance Attribute Details
#subtype ⇒ Object (readonly)
Returns the value of attribute subtype.
154 155 156 |
# File 'lib/arjdbc/postgresql/base/oid.rb', line 154 def subtype @subtype end |
Instance Method Details
#extract_bounds(value) ⇒ Object
161 162 163 164 165 166 167 168 169 |
# File 'lib/arjdbc/postgresql/base/oid.rb', line 161 def extract_bounds(value) from, to = value[1..-2].split(',') { from: (value[1] == ',' || from == '-infinity') ? @subtype.infinity(negative: true) : from, to: (value[-2] == ',' || to == 'infinity') ? @subtype.infinity : to, exclude_start: (value[0] == '('), exclude_end: (value[-1] == ')') } end |
#infinity?(value) ⇒ Boolean
171 172 173 |
# File 'lib/arjdbc/postgresql/base/oid.rb', line 171 def infinity?(value) value.respond_to?(:infinite?) && value.infinite? end |
#simplified_type(sql_type) ⇒ Object
155 |
# File 'lib/arjdbc/postgresql/base/oid.rb', line 155 def simplified_type(sql_type); sql_type.to_sym end |
#type_cast(value) ⇒ Object
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/arjdbc/postgresql/base/oid.rb', line 179 def type_cast(value) return if value.nil? || value == 'empty' return value if value.is_a?(::Range) extracted = extract_bounds(value) from = type_cast_single extracted[:from] to = type_cast_single extracted[:to] if !infinity?(from) && extracted[:exclude_start] if from.respond_to?(:succ) from = from.succ ActiveSupport::Deprecation.warn <<-MESSAGE Excluding the beginning of a Range is only partialy supported through `#succ`. This is not reliable and will be removed in the future. MESSAGE else raise ArgumentError, "The Ruby Range object does not support excluding the beginning of a Range. (unsupported value: '#{value}')" end end ::Range.new(from, to, extracted[:exclude_end]) end |
#type_cast_single(value) ⇒ Object
175 176 177 |
# File 'lib/arjdbc/postgresql/base/oid.rb', line 175 def type_cast_single(value) infinity?(value) ? value : @subtype.type_cast(value) end |