Module: Cachai

Defined in:
lib/models.rb

Defined Under Namespace

Classes: Post, Response

Class Method Summary collapse

Class Method Details

.cacheObject



42
43
44
# File 'lib/models.rb', line 42

def self.cache
  @cache
end

.cache=(obj) ⇒ Object



38
39
40
# File 'lib/models.rb', line 38

def self.cache=(obj)
  @cache = obj
end

.clear_cache(path) ⇒ Object



46
47
48
# File 'lib/models.rb', line 46

def self.clear_cache(path)
  cache.del(key_for(path))
end

.domainObject



34
35
36
# File 'lib/models.rb', line 34

def self.domain
  @domain
end

.domain=(value) ⇒ Object



30
31
32
# File 'lib/models.rb', line 30

def self.domain=(value)
  @domain = value
end

.key_for(path) ⇒ Object



50
51
52
53
# File 'lib/models.rb', line 50

def self.key_for(path)
  raise "Domain not set!" unless @domain
  "comments:#{@domain}:#{path}"
end

.load_db!Object



10
11
12
# File 'lib/models.rb', line 10

def self.load_db!
  load_schema unless schema_loaded?
end

.load_schemaObject



14
15
16
# File 'lib/models.rb', line 14

def self.load_schema
  require_relative '../db/schema.rb'
end

.schema_loaded?Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
24
25
26
27
28
# File 'lib/models.rb', line 18

def self.schema_loaded?
  Post.first
  true
rescue ActiveRecord::StatementInvalid => e
  # SQLite3::SQLException => e
  # return !e.message['no such table']
  false
rescue ActiveRecord::ConnectionNotEstablished
  puts "Connection not established."
  false
end