Class: Atig::Db::Db

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

Constant Summary collapse

Path =
::Dir.tmpdir
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.



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

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

  @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.



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

def dms
  @dms
end

#followingsObject (readonly)

Returns the value of attribute followings.



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

def followings
  @followings
end

#listsObject (readonly)

Returns the value of attribute lists.



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

def lists
  @lists
end

#meObject

Returns the value of attribute me.



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

def me
  @me
end

#noretweetsObject (readonly)

Returns the value of attribute noretweets.



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

def noretweets
  @noretweets
end

#statusesObject (readonly)

Returns the value of attribute statuses.



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

def statuses
  @statuses
end

Instance Method Details

#cleanupObject



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

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

#dir(id) ⇒ Object



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

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

#transaction(&f) ⇒ Object



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

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