Class: Twterm::App
Constant Summary collapse
- DATA_DIR =
"#{ENV['HOME']}/.twterm".freeze
Instance Attribute Summary collapse
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#preferences ⇒ Object
readonly
Returns the value of attribute preferences.
-
#screen ⇒ Object
readonly
Returns the value of attribute screen.
Instance Method Summary collapse
- #completion_manager ⇒ Object
- #direct_message_composer ⇒ Object
- #direct_message_repository ⇒ Object
- #friendship_repository ⇒ Object
- #hashtag_repository ⇒ Object
-
#initialize ⇒ App
constructor
A new instance of App.
- #list_repository ⇒ Object
- #load_preferences_from_file! ⇒ Object
- #quit ⇒ Object
- #register_interruption_handler(&block) ⇒ Object
- #reset_interruption_handler ⇒ Object
- #run ⇒ Object
- #status_repository ⇒ Object
- #tab_manager ⇒ Object
- #tweetbox ⇒ Object
- #user_repository ⇒ Object
Methods included from Publisher
Methods included from Utils
Constructor Details
#initialize ⇒ App
Returns a new instance of App.
31 32 33 34 |
# File 'lib/twterm/app.rb', line 31 def initialize @environment = Environment.new @preferences = Preferences.default end |
Instance Attribute Details
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
27 28 29 |
# File 'lib/twterm/app.rb', line 27 def environment @environment end |
#preferences ⇒ Object (readonly)
Returns the value of attribute preferences.
27 28 29 |
# File 'lib/twterm/app.rb', line 27 def preferences @preferences end |
#screen ⇒ Object (readonly)
Returns the value of attribute screen.
27 28 29 |
# File 'lib/twterm/app.rb', line 27 def screen @screen end |
Instance Method Details
#completion_manager ⇒ Object
41 42 43 |
# File 'lib/twterm/app.rb', line 41 def completion_manager @completion_manager ||= CompletionManager.new(self) end |
#direct_message_composer ⇒ Object
45 46 47 |
# File 'lib/twterm/app.rb', line 45 def @direct_message_composer ||= DirectMessageComposer.new(self, client) end |
#direct_message_repository ⇒ Object
49 50 51 |
# File 'lib/twterm/app.rb', line 49 def @direct_messages_repository ||= Repository::DirectMessageRepository.new end |
#friendship_repository ⇒ Object
53 54 55 |
# File 'lib/twterm/app.rb', line 53 def friendship_repository @friendship_repository ||= Repository::FriendshipRepository.new end |
#hashtag_repository ⇒ Object
57 58 59 |
# File 'lib/twterm/app.rb', line 57 def hashtag_repository @hashtag_repository ||= Repository::HashtagRepository.new end |
#list_repository ⇒ Object
61 62 63 |
# File 'lib/twterm/app.rb', line 61 def list_repository @list_repository ||= Repository::ListRepository.new end |
#load_preferences_from_file! ⇒ Object
36 37 38 39 |
# File 'lib/twterm/app.rb', line 36 def load_preferences_from_file! @preferences = PersistableConfigurationProxy .load_from_file!(Preferences, "#{DATA_DIR}/preferences.toml") end |
#quit ⇒ Object
152 153 154 155 156 |
# File 'lib/twterm/app.rb', line 152 def quit Curses.close_screen tab_manager.dump_tabs exit end |
#register_interruption_handler(&block) ⇒ Object
143 144 145 146 |
# File 'lib/twterm/app.rb', line 143 def register_interruption_handler(&block) fail ArgumentError, 'no block given' unless block_given? Signal.trap(:INT) { block.call } end |
#reset_interruption_handler ⇒ Object
148 149 150 |
# File 'lib/twterm/app.rb', line 148 def reset_interruption_handler Signal.trap(:INT) { quit } end |
#run ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/twterm/app.rb', line 65 def run Dir.mkdir(DATA_DIR, 0700) unless File.directory?(DATA_DIR) Auth.authenticate_user(config) if config[:user_id].nil? load_preferences_from_file! KeyMapper.instance @screen = Screen.new(self, client) SearchQueryWindow.instance MessageWindow.instance @notification_dispatcher = NotificationDispatcher.new(preferences) @photo_viewer = PhotoViewer.new(preferences) timeline = Tab::Statuses::Home.new(self, client) tab_manager.add_and_show(timeline) mentions_tab = Tab::Statuses::Mentions.new(self, client) tab_manager.add(mentions_tab) tab_manager.recover_tabs publish(Event::Screen::Refresh.new) client.connect_user_stream reset_interruption_handler Signal.trap(:WINCH) { on_resize } Scheduler.new(60) { on_resize } URIOpener.instance Scheduler.new(300) do status_repository.expire(3600) _ = status_repository.all.map { |status| user_repository.find(status.user_id) } user_repository.expire(3600) end .before_create do |dm| user_repository.create(dm.recipient) user_repository.create(dm.sender) end user_repository.before_create do |user| client_id = client.user_id if user.following? friendship_repository.follow(client_id, user.id) else friendship_repository.unfollow(client_id, user.id) end if user.follow_request_sent? friendship_repository.following_requested(client_id, user.id) else friendship_repository.following_not_requested(client_id, user.id) end end status_repository.before_create do |tweet| user_repository.create(tweet.user) end status_repository.before_create do |tweet| tweet..each do |hashtag| hashtag_repository.create(hashtag) end end screen.wait screen.refresh end |
#status_repository ⇒ Object
158 159 160 |
# File 'lib/twterm/app.rb', line 158 def status_repository @status_repository ||= Repository::StatusRepository.new end |
#tab_manager ⇒ Object
162 163 164 |
# File 'lib/twterm/app.rb', line 162 def tab_manager @tab_manager ||= TabManager.new(self, client) end |
#tweetbox ⇒ Object
166 167 168 |
# File 'lib/twterm/app.rb', line 166 def tweetbox @tweetbox = Tweetbox.new(self, client) end |
#user_repository ⇒ Object
170 171 172 |
# File 'lib/twterm/app.rb', line 170 def user_repository @user_repository ||= Repository::UserRepository.new end |