Class: BetweenMeals::Changes::Databag
- Defined in:
- lib/between_meals/changes/databag.rb
Overview
Changeset aware databag
Instance Attribute Summary collapse
-
#item ⇒ Object
Returns the value of attribute item.
Attributes inherited from Change
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(file, databag_dir) ⇒ Databag
constructor
A new instance of Databag.
Methods inherited from Change
#debug, debug, #info, info, #logger=, #to_s
Constructor Details
#initialize(file, databag_dir) ⇒ Databag
Returns a new instance of Databag.
34 35 36 37 |
# File 'lib/between_meals/changes/databag.rb', line 34 def initialize(file, databag_dir) @status = file[:status] @name, @item = self.class.name_from_path(file[:path], databag_dir) end |
Instance Attribute Details
#item ⇒ Object
Returns the value of attribute item.
22 23 24 |
# File 'lib/between_meals/changes/databag.rb', line 22 def item @item end |
Class Method Details
.find(list, databag_dir, logger) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/between_meals/changes/databag.rb', line 39 def self.find(list, databag_dir, logger) @@logger = logger 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
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/between_meals/changes/databag.rb', line 23 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 |