Class: BetweenMeals::Changes::Databag

Inherits:
Change
  • Object
show all
Defined in:
lib/between_meals/changes/databag.rb

Overview

Changeset aware databag

Instance Attribute Summary collapse

Attributes inherited from Change

#name, #status

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Change

#debug, debug, #info, info, #logger=, #to_s

Constructor Details

#initialize(file, databag_dir) ⇒ Databag

Returns a new instance of Databag.



33
34
35
36
# File 'lib/between_meals/changes/databag.rb', line 33

def initialize(file, databag_dir)
  @status = file[:status]
  @name, @item = self.class.name_from_path(file[:path], databag_dir)
end

Instance Attribute Details

#itemObject

Returns the value of attribute item.



21
22
23
# File 'lib/between_meals/changes/databag.rb', line 21

def item
  @item
end

Class Method Details

.find(list, databag_dir, logger) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/between_meals/changes/databag.rb', line 38

def self.find(list, databag_dir, logger)
  # rubocop:disable ClassVars
  @@logger = logger
  # rubocop:enable ClassVars
  return [] if list.nil? || list.empty?

  list.
    select { |x| self.name_from_path(x[:path], databag_dir) }.
    map do |x|
      BetweenMeals::Changes::Databag.new(x, databag_dir)
    end
end

.name_from_path(path, databag_dir) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/between_meals/changes/databag.rb', line 22

def self.name_from_path(path, databag_dir)
  re = %r{^#{databag_dir}/([^/]+)/([^/]+)\.json}
  debug("[databag] Matching #{path} against #{re}")
  m = path.match(re)
  if m
    info("Databag is #{m[1]} item is #{m[2]}")
    return m[1], m[2]
  end
  nil
end