Class: Atig::Db::Db

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/atig/db/db.rb

Constant Summary collapse

VERSION =
4

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ExceptionUtil

daemon, safe

Constructor Details

#initialize(context, opt = {}) ⇒ Db

Returns a new instance of Db.



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/atig/db/db.rb', line 19

def initialize(context, opt={})
  @log        = context.log
  @me         = opt[:me]
  @tmpdir     = opt[:tmpdir]

  @followings = Followings.new dir('following')
  @statuses   = Statuses.new   dir('status')
  @dms        = Statuses.new   dir('dm')
  @lists      = Lists.new      dir('lists.%s')
  @noretweets = Array.new

  log :info, "initialize"
end

Instance Attribute Details

#dmsObject (readonly)

Returns the value of attribute dms.



15
16
17
# File 'lib/atig/db/db.rb', line 15

def dms
  @dms
end

#followingsObject (readonly)

Returns the value of attribute followings.



15
16
17
# File 'lib/atig/db/db.rb', line 15

def followings
  @followings
end

#listsObject (readonly)

Returns the value of attribute lists.



15
16
17
# File 'lib/atig/db/db.rb', line 15

def lists
  @lists
end

#meObject

Returns the value of attribute me.



16
17
18
# File 'lib/atig/db/db.rb', line 16

def me
  @me
end

#noretweetsObject (readonly)

Returns the value of attribute noretweets.



15
16
17
# File 'lib/atig/db/db.rb', line 15

def noretweets
  @noretweets
end

#statusesObject (readonly)

Returns the value of attribute statuses.



15
16
17
# File 'lib/atig/db/db.rb', line 15

def statuses
  @statuses
end

Instance Method Details

#cleanupObject



52
53
54
55
56
57
# File 'lib/atig/db/db.rb', line 52

def cleanup
  transaction do
    @statuses.cleanup
    @dms.cleanup
  end
end

#dir(id) ⇒ Object



33
34
35
36
37
38
# File 'lib/atig/db/db.rb', line 33

def dir(id)
  dir = File.expand_path "atig/#{@me.screen_name}/", @tmpdir
  log :debug, "db(#{id}) = #{dir}"
  FileUtils.mkdir_p dir
  File.expand_path "#{id}.#{VERSION}.db", dir
end

#transaction(&f) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/atig/db/db.rb', line 40

def transaction(&f)
  @followings.transaction do|_|
    @statuses.transaction do|_|
      @dms.transaction do|_|
        @lists.transaction do|_|
          f.call self
        end
      end
    end
  end
end