Class: Kiba::Extend::Registry::RegistryEntrySelector

Inherits:
Object
  • Object
show all
Defined in:
lib/kiba/extend/registry/registry_entry_selector.rb

Overview

Used in Rake tasks in project application to identify particular files/jobs to run or display information about

Since:

  • 2.2.0

Instance Method Summary collapse

Instance Method Details

#created_by_class(cstr) ⇒ Array<FileRegistryEntry>

Registry entries created by a given class

Parameters:

  • cstr (String)

    stringified class name

Returns:

Since:

  • 2.2.0



14
15
16
# File 'lib/kiba/extend/registry/registry_entry_selector.rb', line 14

def created_by_class(cstr)
  with_creator.select { |entry| entry.creator.mod.to_s[cstr] }
end

#created_by_method(mstr) ⇒ Array<FileRegistryEntry>

Registry entry or entries created by a given method

Parameters:

  • mstr (String)

    stringified method name

Returns:

Since:

  • 2.2.0



21
22
23
24
# File 'lib/kiba/extend/registry/registry_entry_selector.rb', line 21

def created_by_method(mstr)
  matcher = "#<Method: #{mstr}("
  with_creator.select { |entry| entry.creator.to_s[matcher] }
end

#tagged_all(*args) ⇒ Array<FileRegistryEntry>

Selects entries whose tags include all given tags

Parameters:

  • args (Array<Symbol>)

Returns:

Since:

  • 2.2.0



29
30
31
32
33
34
# File 'lib/kiba/extend/registry/registry_entry_selector.rb', line 29

def tagged_all(*args)
  tags = args.flatten.map(&:to_sym)
  tags.inject(Kiba::Extend.registry.entries) do |arr, tag|
    arr.select { |entry| entry.tags.any?(tag) }
  end
end

#tagged_any(*args) ⇒ Array<FileRegistryEntry>

Selects entries whose tags include one or more of the given tags

Parameters:

  • args (Array<Symbol>)

Returns:

Since:

  • 2.2.0



39
40
41
42
43
44
45
# File 'lib/kiba/extend/registry/registry_entry_selector.rb', line 39

def tagged_any(*args)
  tags = args.flatten.map(&:to_sym)
  results = tags.each_with_object([]) do |arg, arr|
    arr << tagged(arg)
  end
  results.flatten.uniq
end