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

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

Overview

Used in Thor 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>

Returns created by a given class.

Parameters:

  • cstr (String)

    stringified class name

Returns:

Since:

  • 2.2.0



11
12
13
# File 'lib/kiba/extend/registry/registry_entry_selector.rb', line 11

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



18
19
20
21
# File 'lib/kiba/extend/registry/registry_entry_selector.rb', line 18

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



26
27
28
29
30
31
# File 'lib/kiba/extend/registry/registry_entry_selector.rb', line 26

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



36
37
38
39
40
41
# File 'lib/kiba/extend/registry/registry_entry_selector.rb', line 36

def tagged_any(*args)
  args.flatten
    .map { |tag| tagged(tag.to_sym) }
    .flatten
    .uniq
end