Class: TwitterFuseFS
- Inherits:
-
FuseFS::FuseDir
- Object
- FuseFS::FuseDir
- TwitterFuseFS
- Defined in:
- lib/twitter-fusefs.rb
Instance Method Summary collapse
- #can_delete?(path) ⇒ Boolean
- #can_write?(path) ⇒ Boolean
- #contents(path) ⇒ Object
- #directory?(path) ⇒ Boolean
- #file?(path) ⇒ Boolean
-
#initialize ⇒ TwitterFuseFS
constructor
A new instance of TwitterFuseFS.
- #read_file(path) ⇒ Object
- #write_to(path, body) ⇒ Object
Constructor Details
#initialize ⇒ TwitterFuseFS
Returns a new instance of TwitterFuseFS.
7 8 9 10 11 |
# File 'lib/twitter-fusefs.rb', line 7 def initialize @twitter_user = TwitterAccount.new @files = %w{ direct_messages updates timeline replies README} @dirs = %w{ followers friends } end |
Instance Method Details
#can_delete?(path) ⇒ Boolean
71 72 73 |
# File 'lib/twitter-fusefs.rb', line 71 def can_delete?(path) can_write?(path) end |
#can_write?(path) ⇒ Boolean
67 68 69 |
# File 'lib/twitter-fusefs.rb', line 67 def can_write?(path) path == "/updates" or path =~ /\/(followers|friends)\/.*/ end |
#contents(path) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/twitter-fusefs.rb', line 13 def contents(path) case path when "/" @dirs + @files when "/friends" @twitter_user.friends when "/followers" @twitter_user.followers end end |
#directory?(path) ⇒ Boolean
33 34 35 36 |
# File 'lib/twitter-fusefs.rb', line 33 def directory?(path) dir_items = scan_path(path) @dirs.include?(dir_items.last) end |
#file?(path) ⇒ Boolean
24 25 26 27 28 29 30 31 |
# File 'lib/twitter-fusefs.rb', line 24 def file?(path) dir, base = scan_path(path) root_cond = (@files.include? dir and base.nil?) dirs_cond = (@dirs.include? dir and (@twitter_user.friends.include? base or @twitter_user.followers.include? base)) root_cond or dirs_cond end |
#read_file(path) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/twitter-fusefs.rb', line 38 def read_file(path) case path when "/timeline" @twitter_user.friends_timeline when "/direct_messages" @twitter_user. when "/updates" @twitter_user.updates when "/replies" @twitter_user.replies when "/README" "twitter-fusefs\n" when /\/(followers|friends)\/(.*)/ @twitter_user.user_timeline($2) end end |
#write_to(path, body) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/twitter-fusefs.rb', line 55 def write_to(path, body) if !body.empty? # don't know why it gets executed twice, first time without body case path when "/updates" @twitter_user.update body when /\/(followers|friends)\/(.*)$/ body = "@#{$2} #{body}" @twitter_user.update body end end end |