class Perpetuity::Postgres::Index
Attributes
attributes[R]
name[R]
Public Class Methods
from_sql(sql_result)
click to toggle source
# File lib/perpetuity/postgres/index.rb, line 15 def self.from_sql sql_result attributes = sql_result['attributes'].gsub(/[{}]/, '').split(',').map do |attr| Attribute.new(attr) end unique = sql_result['unique'] == 't' active = sql_result['active'] == 't' new(name: sql_result['name'], attributes: attributes, unique: unique, active: active) end
new(options={})
click to toggle source
# File lib/perpetuity/postgres/index.rb, line 8 def initialize options={} @attributes = options.fetch(:attributes) @name = options.fetch(:name) @unique = options.fetch(:unique) { false } @active = options.fetch(:active) { false } end
Public Instance Methods
==(other)
click to toggle source
# File lib/perpetuity/postgres/index.rb, line 55 def == other other.is_a?(self.class) && attributes.map(&:to_s) == other.attributes.map(&:to_s) && name.to_s == other.name.to_s && unique? == other.unique? end
activate!()
click to toggle source
# File lib/perpetuity/postgres/index.rb, line 47 def activate! @active = true end
active?()
click to toggle source
# File lib/perpetuity/postgres/index.rb, line 39 def active? !!@active end
attribute()
click to toggle source
# File lib/perpetuity/postgres/index.rb, line 27 def attribute attributes.first end
attribute_names()
click to toggle source
# File lib/perpetuity/postgres/index.rb, line 31 def attribute_names attributes.map { |attr| attr.name.to_s } end
eql?(other)
click to toggle source
# File lib/perpetuity/postgres/index.rb, line 62 def eql? other self == other end
hash()
click to toggle source
# File lib/perpetuity/postgres/index.rb, line 66 def hash name.to_s.hash end
inactive?()
click to toggle source
# File lib/perpetuity/postgres/index.rb, line 43 def inactive? !active? end
table()
click to toggle source
# File lib/perpetuity/postgres/index.rb, line 51 def table name.gsub("_#{attributes.map(&:to_s).join('_')}_index", '') end
unique?()
click to toggle source
# File lib/perpetuity/postgres/index.rb, line 35 def unique? !!@unique end