Class: CouchbaseOrm::IndexMigration::IndexIntrospector

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

Instance Method Summary collapse

Constructor Details

#initialize(execute_query: nil) ⇒ IndexIntrospector

Returns a new instance of IndexIntrospector.



6
7
8
# File 'lib/couchbase-orm/index_migration/index_introspector.rb', line 6

def initialize(execute_query: nil)
  @execute_query = execute_query || method(:default_execute_query)
end

Instance Method Details

#indexes(bucket: configured_bucket) ⇒ Object

Raises:

  • (ArgumentError)


10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/couchbase-orm/index_migration/index_introspector.rb', line 10

def indexes(bucket: configured_bucket)
  bucket_name = bucket.to_s
  raise ArgumentError.new('Missing index bucket configuration') if bucket_name.strip.empty?

  result = @execute_query.call(query_for(bucket_name))
  rows = result.respond_to?(:rows) ? result.rows : []

  Array(rows).map { |row| normalize_row(row) }
             .select { |row| row[:keyspace_id] == bucket_name }
             .reject { |row| row[:is_primary] }
             .sort_by { |row| row[:name] }
             .map { |row| row.slice(:name, :index_key, :condition, :state) }
end