Class: SafetyCone::Path

Inherits:
Object
  • Object
show all
Defined in:
app/models/safety_cone/path.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, params) ⇒ Path

Returns a new instance of Path.



7
8
9
10
11
12
13
14
15
16
# File 'app/models/safety_cone/path.rb', line 7

def initialize(key, params)
  @key = key
  @name = params[:name]
  @controller = params[:controller]
  @method = params[:action]
  @method = params[:method]
  @message = params[:message]
  @type = params[:type] || 'disabled'
  @redis = SafetyCone.redis
end

Instance Attribute Details

#actionObject

Returns the value of attribute action.



3
4
5
# File 'app/models/safety_cone/path.rb', line 3

def action
  @action
end

#controllerObject

Returns the value of attribute controller.



3
4
5
# File 'app/models/safety_cone/path.rb', line 3

def controller
  @controller
end

#keyObject

Returns the value of attribute key.



3
4
5
# File 'app/models/safety_cone/path.rb', line 3

def key
  @key
end

#messageObject

Returns the value of attribute message.



3
4
5
# File 'app/models/safety_cone/path.rb', line 3

def message
  @message
end

#methodObject

Returns the value of attribute method.



3
4
5
# File 'app/models/safety_cone/path.rb', line 3

def method
  @method
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'app/models/safety_cone/path.rb', line 3

def name
  @name
end

#redisObject

Returns the value of attribute redis.



3
4
5
# File 'app/models/safety_cone/path.rb', line 3

def redis
  @redis
end

#typeObject

Returns the value of attribute type.



3
4
5
# File 'app/models/safety_cone/path.rb', line 3

def type
  @type
end

Instance Method Details

#fetchObject



23
24
25
26
27
28
29
30
31
# File 'app/models/safety_cone/path.rb', line 23

def fetch
  stored_data = @redis.get(redis_key)

  if stored_data
    data = JSON.parse(stored_data)
    @message = data['message']
    @type = data['type']
  end
end

#redis_keyObject



33
34
35
# File 'app/models/safety_cone/path.rb', line 33

def redis_key
  "safety::cone::#{@key}"
end

#saveObject



18
19
20
21
# File 'app/models/safety_cone/path.rb', line 18

def save
  data = { message: @message, type: @type }.to_json
  @redis.set(redis_key, data)
end