Class: Hubtime::Activity::Forever

Inherits:
Period
  • Object
show all
Defined in:
lib/hubtime/activity.rb

Instance Attribute Summary collapse

Attributes inherited from Period

#children, #compiled, #example, #label, #repo_stats, #total_stats

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Period

#_first_child_key, #_last_child_key, #add, #additions, #child_keys, #commits, #compile!, #compiled?, #count, #default_stats, #deletions, #first!, #impact, #import, #key_value, #last!, #repositories

Constructor Details

#initialize(cache_key) ⇒ Forever

Returns a new instance of Forever.



173
174
175
176
# File 'lib/hubtime/activity.rb', line 173

def initialize(cache_key)
  @cache_key = cache_key
  super(self.class.display(Time.zone.now), Time.zone.now)
end

Instance Attribute Details

#cache_keyObject (readonly)

Returns the value of attribute cache_key.



172
173
174
# File 'lib/hubtime/activity.rb', line 172

def cache_key
  @cache_key
end

Class Method Details

.cacherObject



178
179
180
# File 'lib/hubtime/activity.rb', line 178

def self.cacher
  @cacher ||= Cacher.new("activity")
end

.child_classObject



168
169
170
# File 'lib/hubtime/activity.rb', line 168

def self.child_class
  Year
end

.display(time) ⇒ Object



164
165
166
# File 'lib/hubtime/activity.rb', line 164

def self.display(time)
  "All"
end

.load(username, start_time, end_time) ⇒ Object



182
183
184
185
186
187
188
189
# File 'lib/hubtime/activity.rb', line 182

def self.load(username, start_time, end_time)
  key = "#{username}/#{start_time.to_i}-#{end_time.to_i}"
  out = self.new(key)
  if stats = cacher.read(key)
    out.import(stats)
  end
  out
end

Instance Method Details

#each(unit, &block) ⇒ Object



204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/hubtime/activity.rb', line 204

def each(unit, &block)
  unit = unit.to_s
  if unit == "all"
    yield "All", self
  else
    self.children.each do |year_key, year|
      if unit == "year"
        yield "#{year_key}", year
      else
        year.children.each do |month_key, month|
          if unit == "month"
            yield "#{year_key}-#{month_key}", month
          else
            month.children.each do |day_key, day|
              yield "#{year_key}-#{month_key}-#{day_key}", day
            end
          end
        end
      end
    end
  end
end

#first?Boolean

Returns:

  • (Boolean)


196
197
198
# File 'lib/hubtime/activity.rb', line 196

def first?
  true
end

#last?Boolean

Returns:

  • (Boolean)


200
201
202
# File 'lib/hubtime/activity.rb', line 200

def last?
  true
end

#store!Object



191
192
193
194
# File 'lib/hubtime/activity.rb', line 191

def store!
  raise "not compiled" unless compiled?
  self.class.cacher.write(cache_key, @compiled)
end