Module: EmojiDiffer
- Defined in:
- lib/emoji_differ.rb,
lib/emoji_differ/list.rb,
lib/emoji_differ/emoji.rb,
lib/emoji_differ/config.rb,
lib/emoji_differ/version.rb,
lib/emoji_differ/slack_api.rb
Defined Under Namespace
Classes: Config, Emoji, Error, List, SlackApi
Constant Summary
collapse
- VERSION =
"0.1.0"
Class Method Summary
collapse
Class Method Details
.cached ⇒ Object
21
22
23
|
# File 'lib/emoji_differ.rb', line 21
def self.cached
load
end
|
.config ⇒ Object
8
9
10
11
12
13
14
15
|
# File 'lib/emoji_differ.rb', line 8
def self.config
@config ||= EmojiDiffer::Config.new
if block_given?
yield @config
else
@config
end
end
|
.current ⇒ Object
17
18
19
|
# File 'lib/emoji_differ.rb', line 17
def self.current
@current ||= EmojiDiffer::SlackApi.new(config.token).emoji
end
|
.deleted ⇒ Object
25
26
27
|
# File 'lib/emoji_differ.rb', line 25
def self.deleted
load - current
end
|
.load ⇒ Object
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/emoji_differ.rb', line 46
def self.load
File.open(config.cache_location, 'r') do |f|
contents = ''
while !f.eof? && (chunk = read_nb_chunk(f))
contents += chunk
end
EmojiDiffer::List.from_json(contents)
end
end
|
.new_emoji ⇒ Object
29
30
31
|
# File 'lib/emoji_differ.rb', line 29
def self.new_emoji
current - load
end
|
.read_nb_chunk(io) ⇒ Object
39
40
41
42
43
44
|
# File 'lib/emoji_differ.rb', line 39
def self.read_nb_chunk(io)
io.read_nonblock(8000)
rescue IO::WaitReadable
IO.select([io])
retry
end
|
.save ⇒ Object
33
34
35
36
37
|
# File 'lib/emoji_differ.rb', line 33
def self.save
File.open(config.cache_location, 'w') do |f|
f.print EmojiDiffer::SlackApi.new(config.token).emoji.to_json
end
end
|