Module: CheckIn::Writer

Defined in:
lib/check_in/writer.rb

Defined Under Namespace

Classes: Configuration

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/check_in/writer.rb', line 4

def self.included(klass)
  klass.class_eval do
    class << self
      attr_accessor :check_in_configuration
    end
  end
  klass.check_in_configuration = Configuration.new(klass)
end

Instance Method Details

#check_in(*args) ⇒ Object



76
77
78
79
80
81
82
# File 'lib/check_in/writer.rb', line 76

def check_in(*args)
  instance_name = send(check_in_configuration.instance_name_method)
  time = Time.now.strftime(CheckIn.time_format)
  line = "#{instance_name} | #{time}"
  CheckIn.redis.rpush(check_in_configuration.redis_key, line)
  trim_checkins
end

#check_in_configurationObject



91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/check_in/writer.rb', line 91

def check_in_configuration
  # this is to allow usage on class methods
  if self.class.respond_to?(:check_in_configuration)
    self.class.check_in_configuration
  else 
    self.class_eval do
      class << self
        check_in_configuration
      end
    end
  end
end

#trim_checkinsObject



84
85
86
87
88
89
# File 'lib/check_in/writer.rb', line 84

def trim_checkins
  size = CheckIn.redis.llen(check_in_configuration.redis_key)
  if size > check_in_configuration.list_length
    CheckIn.redis.ltrim(check_in_configuration.redis_key, size - check_in_configuration.list_length, size - 1)
  end
end