Module: Scales::Worker::Cache::JSON

Includes:
Helper::ContentTypes
Defined in:
lib/scales-worker/cache/json.rb

Class Method Summary collapse

Class Method Details

.append(params = {}) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/scales-worker/cache/json.rb', line 9

def append(params = {})
  json = params[:json]
  path = params[:to] || params[:at]
  change_content_at(path, params[:select]) do |selection, selector|
    selection.gsub(selector){ |selection| selection << parse(json) }
  end
end

.prepend(params = {}) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/scales-worker/cache/json.rb', line 17

def prepend(params = {})
  json = params[:json]
  path = params[:to] || params[:at]
  change_content_at(path, params[:select]) do |selection, selector|
    selection.gsub(selector){ |selection| (selection.reverse << parse(json)).reverse }
  end
end

.remove(params = {}) ⇒ Object



37
38
39
40
41
42
# File 'lib/scales-worker/cache/json.rb', line 37

def remove(params = {})
  path = params[:to] || params[:at]
  change_content_at(path, params[:select]) do |selection, selector|
    selection.delete(selector)
  end
end

.replace(params = {}) ⇒ Object



33
34
35
# File 'lib/scales-worker/cache/json.rb', line 33

def replace(params = {})
  set(params)
end

.set(params = {}) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/scales-worker/cache/json.rb', line 25

def set(params = {})
  json = params[:json]
  path = params[:to] || params[:at]
  change_content_at(path, params[:select]) do |selection, selector|
    selection.gsub(selector){ |selection| selection = parse(json) }
  end
end