Class: Rid::App

Inherits:
Object
  • Object
show all
Defined in:
lib/rid/app.rb

Overview

Holds Application config

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = OpenStruct.new) ⇒ App

Initialize app with an options object, which behaves like an open struct.

Options are:

root:     specify app root directory
database: set database name


15
16
17
18
19
20
21
22
# File 'lib/rid/app.rb', line 15

def initialize(options = OpenStruct.new)
  @root = options.root
  @root ||= find_root
  @root = Pathname.new(@root)

  @db_url = options.database
  @db_url ||= read_db_url
end

Instance Attribute Details

#dbObject (readonly)

Returns an instance of Rid::Database, configured with db_name.



27
28
29
# File 'lib/rid/app.rb', line 27

def db
  @db
end

#db_urlObject (readonly)

Returns the value of attribute db_url.



5
6
7
# File 'lib/rid/app.rb', line 5

def db_url
  @db_url
end

#rootObject

Returns the value of attribute root.



6
7
8
# File 'lib/rid/app.rb', line 6

def root
  @root
end

Instance Method Details

#documentsObject

List application documents. Each entry is a filename.



35
36
37
38
39
# File 'lib/rid/app.rb', line 35

def documents
  @documents ||= Dir[root.join("*")].
    select { |f| File.directory?(f) && File.file?(File.join(f, '_id')) }.
    map { |f| Rid::Document.new :path => f }
end