Class: Redis::Breadcrumb

Inherits:
Object
  • Object
show all
Includes:
Breadcrumbs::AsMethods, Breadcrumbs::Dsl, Breadcrumbs::Entrance
Defined in:
lib/redis-breadcrumbs/breadcrumb.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Breadcrumbs::Entrance

included

Methods included from Breadcrumbs::AsMethods

included

Methods included from Breadcrumbs::Dsl

included

Constructor Details

#initialize(object = Breadcrumbs::UnspecializedDummyObject.new) ⇒ Breadcrumb

Returns a new instance of Breadcrumb.



21
22
23
24
# File 'lib/redis-breadcrumbs/breadcrumb.rb', line 21

def initialize object=Breadcrumbs::UnspecializedDummyObject.new
  @tracked_in = self.class.tracked_in_key.specialize(object).to_s
  @keys = self.class.keys.specialize object
end

Instance Attribute Details

#tracked_inObject (readonly)

Returns the value of attribute tracked_in.



19
20
21
# File 'lib/redis-breadcrumbs/breadcrumb.rb', line 19

def tracked_in
  @tracked_in
end

Class Method Details

.method_missing(mthd, *args) ⇒ Object



14
15
16
# File 'lib/redis-breadcrumbs/breadcrumb.rb', line 14

def method_missing mthd, *args
  new.send(mthd)
end

Instance Method Details

#clean!Object



38
39
40
# File 'lib/redis-breadcrumbs/breadcrumb.rb', line 38

def clean!
  run_cmds Set.new(tracked_keys.concat(@keys.clean_cmds))
end

#reset!Object



34
35
36
# File 'lib/redis-breadcrumbs/breadcrumb.rb', line 34

def reset!
  run_cmds @keys.reset_cmds
end

#track!Object



26
27
28
29
30
31
32
# File 'lib/redis-breadcrumbs/breadcrumb.rb', line 26

def track!
  return if @tracked_in.nil? || @tracked_in == ""

  jsons = @keys.clean_cmds.map(&:to_json)

  redis.sadd @tracked_in, jsons
end

#tracked_keysObject



42
43
44
45
46
# File 'lib/redis-breadcrumbs/breadcrumb.rb', line 42

def tracked_keys
  redis.smembers(@tracked_in).map do |json|
    JSON.parse(json)
  end
end