Class: ConvenientService::Support::DependencyContainer::Entities::MethodCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/convenient_service/support/dependency_container/entities/method_collection.rb

Instance Method Summary collapse

Constructor Details

#initialize(methods: []) ⇒ void

Parameters:



12
13
14
# File 'lib/convenient_service/support/dependency_container/entities/method_collection.rb', line 12

def initialize(methods: [])
  @methods = methods
end

Instance Method Details

#<<(method) ⇒ ConvenientService::Support::DependencyContainer::Entities::MethodCollection



38
39
40
41
42
# File 'lib/convenient_service/support/dependency_container/entities/method_collection.rb', line 38

def <<(method)
  methods << method

  self
end

#==(other) ⇒ Boolean

Parameters:

  • other (Object)

    Can be any type.

Returns:

  • (Boolean)


79
80
81
82
83
84
85
# File 'lib/convenient_service/support/dependency_container/entities/method_collection.rb', line 79

def ==(other)
  return unless other.instance_of?(self.class)

  return false if methods != other.methods

  true
end

#clearConvenientService::Support::DependencyContainer::Entities::MethodCollection



62
63
64
65
66
# File 'lib/convenient_service/support/dependency_container/entities/method_collection.rb', line 62

def clear
  methods.clear

  self
end

#empty?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/convenient_service/support/dependency_container/entities/method_collection.rb', line 47

def empty?
  methods.empty?
end

#find_by(name: Support::NOT_PASSED, slug: Support::NOT_PASSED, scope: Support::NOT_PASSED) ⇒ ConvenientService::Support::DependencyContainer::Entities::Method?

Parameters:

  • name (String, Symbol) (defaults to: Support::NOT_PASSED)
  • slug (String, Symbol) (defaults to: Support::NOT_PASSED)
  • scope (:instance, :class) (defaults to: Support::NOT_PASSED)

Returns:



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/convenient_service/support/dependency_container/entities/method_collection.rb', line 22

def find_by(name: Support::NOT_PASSED, slug: Support::NOT_PASSED, scope: Support::NOT_PASSED)
  rules = []

  rules << ->(method) { method.name.to_s == name.to_s } if name != Support::NOT_PASSED
  rules << ->(method) { method.slug.to_s == slug.to_s } if slug != Support::NOT_PASSED
  rules << ->(method) { method.scope == scope } if scope != Support::NOT_PASSED

  condition = Utils::Proc.conjunct(rules)

  methods.find(&condition)
end

#include?(method) ⇒ Boolean



55
56
57
# File 'lib/convenient_service/support/dependency_container/entities/method_collection.rb', line 55

def include?(method)
  methods.include?(method)
end

#to_aArray

Returns:

  • (Array)


71
72
73
# File 'lib/convenient_service/support/dependency_container/entities/method_collection.rb', line 71

def to_a
  methods.to_a
end