Class: DatabaseReader

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/database_reader.rb

Defined Under Namespace

Classes: Error, NotFoundError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path:, query: nil) ⇒ DatabaseReader

Returns a new instance of DatabaseReader.



11
12
13
14
# File 'lib/database_reader.rb', line 11

def initialize(path:, query: nil)
  @path = Pathname.new(path)
  @query = query || default_query
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



44
45
46
# File 'lib/database_reader.rb', line 44

def path
  @path
end

#queryObject (readonly)

Returns the value of attribute query.



44
45
46
# File 'lib/database_reader.rb', line 44

def query
  @query
end

Class Method Details

.default_queryObject



47
48
49
50
51
# File 'lib/database_reader.rb', line 47

def default_query
  <<~SQL
    SELECT * FROM ItemTable WHERE key LIKE 'extensionsIdentifiers/enabled'
  SQL
end

Instance Method Details

#extensionsObject



18
19
20
21
22
# File 'lib/database_reader.rb', line 18

def extensions
  @extensions ||=
    JSON.parse(query_extensions.dig(0, 1) || raise(NotFoundError, "Unexpected query result #{query_extensions}"))
        .map { |ext| ext['id'] }
end