Module: ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::CanHaveParentResult::Concern

Includes:
ConvenientService::Support::Concern
Defined in:
lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/can_have_parent_result/concern.rb

Instance Method Summary collapse

Instance Method Details

#parentConvenientService::Service::Plugins::HasJSendResult::Entities::Result?



21
22
23
# File 'lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/can_have_parent_result/concern.rb', line 21

def parent
  Utils.memoize_including_falsy_values(self, :@parent) { extra_kwargs[:parent] }
end

#parents(include_self: false, limit: Constants::PARENTS_LIMIT) ⇒ Array<ConvenientService::Service::Plugins::HasJSendResult::Entities::Result>

Parameters:

  • include_self (Boolean) (defaults to: false)
  • limit (Integer) (defaults to: Constants::PARENTS_LIMIT)

Returns:



53
54
55
# File 'lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/can_have_parent_result/concern.rb', line 53

def parents(include_self: false, limit: Constants::PARENTS_LIMIT)
  parents_enum(include_self: include_self, limit: limit).to_a
end

#parents_enum(include_self: false, limit: Constants::PARENTS_LIMIT) ⇒ Enumerator<ConvenientService::Service::Plugins::HasJSendResult::Entities::Result>

Parameters:

  • include_self (Boolean) (defaults to: false)
  • limit (Integer) (defaults to: Constants::PARENTS_LIMIT)

Returns:

See Also:



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins/can_have_parent_result/concern.rb', line 64

def parents_enum(include_self: false, limit: Constants::PARENTS_LIMIT)
  ::Enumerator.new do |yielder|
    yielder.yield(self) if include_self

    ##
    # NOTE: Empty parentheses are used to force a method call
    # https://docs.ruby-lang.org/en/2.7.0/syntax/assignment_rdoc.html#label-Local+Variables+and+Methods
    #
    parent = parent()

    ##
    # NOTE: `finite_loop` is used to avoid even a theoretical infinite loop.
    #
    Support::FiniteLoop.finite_loop(max_iteration_count: limit, raise_on_exceedance: false) do
      break unless parent

      yielder.yield(parent)

      parent = parent.parent
    end
  end
end