Class: BetweenMeals::Changes::Role
- Defined in:
- lib/between_meals/changes/role.rb
Overview
Changeset aware role
Instance Attribute Summary
Attributes inherited from Change
Class Method Summary collapse
-
.find(list, role_dir, logger) ⇒ Object
Given a list of changed files create a list of Role objects.
- .name_from_path(path, role_dir) ⇒ Object
Instance Method Summary collapse
-
#initialize(file, role_dir) ⇒ Role
constructor
A new instance of Role.
Methods inherited from Change
#debug, debug, #info, info, #logger=, #to_s
Constructor Details
#initialize(file, role_dir) ⇒ Role
Returns a new instance of Role.
32 33 34 35 |
# File 'lib/between_meals/changes/role.rb', line 32 def initialize(file, role_dir) @status = file[:status] == :deleted ? :deleted : :modified @name = self.class.name_from_path(file[:path], role_dir) end |
Class Method Details
.find(list, role_dir, logger) ⇒ Object
Given a list of changed files create a list of Role objects
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/between_meals/changes/role.rb', line 39 def self.find(list, role_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], role_dir) }. map do |x| BetweenMeals::Changes::Role.new(x, role_dir) end end |
.name_from_path(path, role_dir) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/between_meals/changes/role.rb', line 21 def self.name_from_path(path, role_dir) re = %r{^#{role_dir}/(.+)\.(?:rb|json)} debug("[role] Matching #{path} against #{re}") m = path.match(re) if m info("Name is #{m[1]}") return m[1] end nil end |