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:



17
18
19
# File 'lib/convenient_service/support/dependency_container/entities/method_collection.rb', line 17

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

Instance Method Details

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



43
44
45
46
47
# File 'lib/convenient_service/support/dependency_container/entities/method_collection.rb', line 43

def <<(method)
  methods << method

  self
end

#==(other) ⇒ Boolean?

Parameters:

  • other (Object)

    Can be any type.

Returns:

  • (Boolean, nil)


84
85
86
87
88
89
90
# File 'lib/convenient_service/support/dependency_container/entities/method_collection.rb', line 84

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

  return false if methods != other.methods

  true
end

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



67
68
69
70
71
# File 'lib/convenient_service/support/dependency_container/entities/method_collection.rb', line 67

def clear
  methods.clear

  self
end

#empty?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/convenient_service/support/dependency_container/entities/method_collection.rb', line 52

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:



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/convenient_service/support/dependency_container/entities/method_collection.rb', line 27

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 } unless Support::NOT_PASSED[name]
  rules << ->(method) { method.slug.to_s == slug.to_s } unless Support::NOT_PASSED[slug]
  rules << ->(method) { method.scope == scope } unless Support::NOT_PASSED[scope]

  condition = Utils::Proc.conjunct(rules)

  methods.find(&condition)
end

#include?(method) ⇒ Boolean



60
61
62
# File 'lib/convenient_service/support/dependency_container/entities/method_collection.rb', line 60

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

#to_aArray

Returns:

  • (Array)


76
77
78
# File 'lib/convenient_service/support/dependency_container/entities/method_collection.rb', line 76

def to_a
  methods.to_a
end