Class: Kennel::Filter
- Inherits:
-
Object
- Object
- Kennel::Filter
- Defined in:
- lib/kennel/filter.rb
Instance Method Summary collapse
- #filter_parts(parts) ⇒ Object
- #filter_projects(projects) ⇒ Object
- #filtering? ⇒ Boolean
-
#initialize ⇒ Filter
constructor
A new instance of Filter.
- #matches_project_id?(project_id) ⇒ Boolean
- #matches_tracking_id?(tracking_id) ⇒ Boolean
- #tracking_id_for_path(tracking_id) ⇒ Object
Constructor Details
#initialize ⇒ Filter
Returns a new instance of Filter.
5 6 7 8 9 |
# File 'lib/kennel/filter.rb', line 5 def initialize # read early so we fail fast on invalid user input @tracking_id_filter = read_tracking_id_filter_from_env @project_filter = read_project_filter_from_env end |
Instance Method Details
#filter_parts(parts) ⇒ Object
15 16 17 |
# File 'lib/kennel/filter.rb', line 15 def filter_parts(parts) filter_resources(parts, :tracking_id, tracking_id_filter, "resources", "TRACKING_ID") end |
#filter_projects(projects) ⇒ Object
11 12 13 |
# File 'lib/kennel/filter.rb', line 11 def filter_projects(projects) filter_resources(projects, :kennel_id, project_filter, "projects", "PROJECT") end |
#filtering? ⇒ Boolean
19 20 21 |
# File 'lib/kennel/filter.rb', line 19 def filtering? !project_filter.nil? end |
#matches_project_id?(project_id) ⇒ Boolean
23 24 25 |
# File 'lib/kennel/filter.rb', line 23 def matches_project_id?(project_id) !filtering? || project_filter.include?(project_id) end |
#matches_tracking_id?(tracking_id) ⇒ Boolean
27 28 29 30 31 32 33 |
# File 'lib/kennel/filter.rb', line 27 def matches_tracking_id?(tracking_id) return true unless filtering? return tracking_id_filter.include?(tracking_id) if tracking_id_filter project_id = tracking_id.split(":").first project_filter.include?(project_id) end |
#tracking_id_for_path(tracking_id) ⇒ Object
35 36 37 38 |
# File 'lib/kennel/filter.rb', line 35 def tracking_id_for_path(tracking_id) return tracking_id unless tracking_id.end_with?(".json") tracking_id.sub("generated/", "").sub(".json", "").sub("/", ":") end |