Class: CouchbaseOrm::IndexDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/couchbase-orm/index_definition.rb

Constant Summary collapse

NAME_SYMBOL_PATTERN =
/\A[a-zA-Z_][a-zA-Z0-9_]*\z/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, keys:, where: nil, defer_build: false, num_replica: nil) ⇒ IndexDefinition

Returns a new instance of IndexDefinition.



9
10
11
12
13
14
15
# File 'lib/couchbase-orm/index_definition.rb', line 9

def initialize(name:, keys:, where: nil, defer_build: false, num_replica: nil)
  @name = normalize_name(name)
  @keys = normalize_keys(keys)
  @where = normalize_where(where)
  @defer_build = !!defer_build
  @num_replica = num_replica
end

Instance Attribute Details

#defer_buildObject (readonly)

Returns the value of attribute defer_build.



5
6
7
# File 'lib/couchbase-orm/index_definition.rb', line 5

def defer_build
  @defer_build
end

#keysObject (readonly)

Returns the value of attribute keys.



5
6
7
# File 'lib/couchbase-orm/index_definition.rb', line 5

def keys
  @keys
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/couchbase-orm/index_definition.rb', line 5

def name
  @name
end

#num_replicaObject (readonly)

Returns the value of attribute num_replica.



5
6
7
# File 'lib/couchbase-orm/index_definition.rb', line 5

def num_replica
  @num_replica
end

#whereObject (readonly)

Returns the value of attribute where.



5
6
7
# File 'lib/couchbase-orm/index_definition.rb', line 5

def where
  @where
end

Class Method Details

.from_introspected(index_data) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/couchbase-orm/index_definition.rb', line 17

def self.from_introspected(index_data)
  new(
    name: index_data.fetch(:name),
    keys: index_data.fetch(:index_key, []),
    where: index_data[:condition]
  )
end

.normalize_name(name) ⇒ Object



36
37
38
39
40
41
# File 'lib/couchbase-orm/index_definition.rb', line 36

def normalize_name(name)
  value = name.to_s.strip
  return value.to_sym if value.match?(NAME_SYMBOL_PATTERN)

  value
end

Instance Method Details

#<=>(other) ⇒ Object



25
26
27
# File 'lib/couchbase-orm/index_definition.rb', line 25

def <=>(other)
  name.to_s <=> other.name.to_s
end