Class: Perpetuity::Postgres::Index
- Inherits:
-
Object
- Object
- Perpetuity::Postgres::Index
- Defined in:
- lib/perpetuity/postgres/index.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #activate! ⇒ Object
- #active? ⇒ Boolean
- #attribute ⇒ Object
- #attribute_names ⇒ Object
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
- #inactive? ⇒ Boolean
-
#initialize(options = {}) ⇒ Index
constructor
A new instance of Index.
- #table ⇒ Object
- #unique? ⇒ Boolean
Constructor Details
#initialize(options = {}) ⇒ Index
Returns a new instance of Index.
8 9 10 11 12 13 |
# File 'lib/perpetuity/postgres/index.rb', line 8 def initialize ={} @attributes = .fetch(:attributes) @name = .fetch(:name) @unique = .fetch(:unique) { false } @active = .fetch(:active) { false } end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
6 7 8 |
# File 'lib/perpetuity/postgres/index.rb', line 6 def attributes @attributes end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/perpetuity/postgres/index.rb', line 6 def name @name end |
Class Method Details
.from_sql(sql_result) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# 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 |
Instance Method Details
#==(other) ⇒ Object
55 56 57 58 59 60 |
# 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! ⇒ Object
47 48 49 |
# File 'lib/perpetuity/postgres/index.rb', line 47 def activate! @active = true end |
#active? ⇒ Boolean
39 40 41 |
# File 'lib/perpetuity/postgres/index.rb', line 39 def active? !!@active end |
#attribute ⇒ Object
27 28 29 |
# File 'lib/perpetuity/postgres/index.rb', line 27 def attribute attributes.first end |
#attribute_names ⇒ Object
31 32 33 |
# File 'lib/perpetuity/postgres/index.rb', line 31 def attribute_names attributes.map { |attr| attr.name.to_s } end |
#eql?(other) ⇒ Boolean
62 63 64 |
# File 'lib/perpetuity/postgres/index.rb', line 62 def eql? other self == other end |
#hash ⇒ Object
66 67 68 |
# File 'lib/perpetuity/postgres/index.rb', line 66 def hash name.to_s.hash end |
#inactive? ⇒ Boolean
43 44 45 |
# File 'lib/perpetuity/postgres/index.rb', line 43 def inactive? !active? end |
#table ⇒ Object
51 52 53 |
# File 'lib/perpetuity/postgres/index.rb', line 51 def table name.gsub("_#{attributes.map(&:to_s).join('_')}_index", '') end |
#unique? ⇒ Boolean
35 36 37 |
# File 'lib/perpetuity/postgres/index.rb', line 35 def unique? !!@unique end |