asciinema.org/app/services/view_counter.rb
2013-06-13 22:26:27 +02:00

23 lines
393 B
Ruby

class ViewCounter
attr_reader :asciicast, :storage
def initialize(asciicast, storage)
@asciicast = asciicast
@storage = storage
end
def increment
unless storage[key]
Asciicast.increment_counter(:views_count, asciicast.id)
asciicast.reload
storage[key] = '1'
end
end
private
def key
@key ||= :"asciicast_#{asciicast.id}_viewed"
end
end