Class: Akane::Storages::File

Inherits:
AbstractStorage show all
Defined in:
lib/akane/storages/file.rb

Instance Method Summary collapse

Methods inherited from AbstractStorage

#exitable?, #status, #stop!

Constructor Details

#initializeFile

Returns a new instance of File.



10
11
12
13
14
15
16
17
# File 'lib/akane/storages/file.rb', line 10

def initialize(*)
  super
  @screen_name_to_id_cache = {}
  @dir = Pathname.new(@config["dir"])
  [@dir, @dir.join('names'), @dir.join('users'), @dir.join('event'), @dir.join('timeline')].each do |d|
    d.mkdir unless d.exist?
  end
end

Instance Method Details

#mark_as_deleted(account, user_id, tweet_id) ⇒ Object



32
33
34
35
36
37
# File 'lib/akane/storages/file.rb', line 32

def mark_as_deleted(, user_id, tweet_id)
  timeline_deletion_io.puts "#{Time.now.xmlschema},#{user_id},#{tweet_id}"
  tweets_deletion_io_for_user(user_id) do |io|
    io.puts "#{Time.now.xmlschema},#{user_id},#{tweet_id}"
  end
end

#nameObject



19
20
21
# File 'lib/akane/storages/file.rb', line 19

def name
  @name ||= "#{self.class.name}:#{@config["dir"]}"
end

#record_event(account, event) ⇒ Object



39
40
41
# File 'lib/akane/storages/file.rb', line 39

def record_event(, event)
  event_io.puts event.merge(:happened_on => ).to_json
end

#record_message(account, message) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/akane/storages/file.rb', line 43

def record_message(, message)
  messages_raw_io_for_user(message.sender.id, message.sender.screen_name) do |io|
    io.puts message.attrs.to_json
  end
  messages_io_for_user(message.sender.id, message.sender.screen_name) do |io|
    io.puts "[#{message.created_at.xmlschema}] #{message.sender.screen_name} -> #{message.recipient.screen_name}:" \
            " #{message.text} (#{message.sender.id} -> #{message.recipient.id},#{message.id})"
  end
end

#record_tweet(account, tweet) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/akane/storages/file.rb', line 23

def record_tweet(, tweet)
  timeline_io.puts "[#{tweet.created_at.xmlschema}][#{}] #{tweet.user.screen_name}: " \
                   "#{tweet.text.gsub(/\r?\n/,' ')} (#{tweet.user.id},#{tweet.id})"

  tweets_io_for_user(tweet.user.id, tweet.user.screen_name) do |io|
    io.puts tweet.attrs.to_json
  end
end