Skip to content

Commit

Permalink
refactor(core): do not assert since concerns can be added anytime
Browse files Browse the repository at this point in the history
  • Loading branch information
marian13 committed Oct 9, 2022
1 parent 2f53b03 commit bbd0b73
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 42 deletions.
2 changes: 0 additions & 2 deletions lib/convenient_service/core/class_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ def concerns(&configuration_block)

return @concerns unless configuration_block

@concerns.assert_not_included!

@concerns.configure(&configuration_block)

@concerns
Expand Down
38 changes: 3 additions & 35 deletions lib/convenient_service/core/entities/concerns.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,6 @@ def private_class_method_defined?(method_name)
private_class_method_defined_in_class_methods_modules?(method_name)
end

##
# @return [void]
#
def assert_not_included!
return unless included?

raise Errors::ConcernsAreIncluded.new(concerns: concerns)
end

##
# @return [void]
#
Expand All @@ -69,30 +60,14 @@ def configure(&configuration_block)
end

##
# Includes concerns into entity when called for the first time.
# Does nothing for the subsequent calls.
# Includes concerns into entity.
#
# @return [Boolean] true if called for the first time, false otherwise (similarly as Kernel#require).
# @return [void]
#
# @see https://ruby-doc.org/core-3.1.2/Kernel.html#method-i-require
# @see https://stackoverflow.com/questions/1077412/what-is-an-idempotent-operation
#
def include!
return false if included?

stack.call(entity: stack.entity)

mark_as_included!

true
end

##
# Checks whether concerns are included into entity (include! was called at least once).
#
# @return [Boolean]
#
def included?
Utils::Bool.to_bool(@included)
end

##
Expand Down Expand Up @@ -196,13 +171,6 @@ def class_methods_modules
.select { |concern| concern.const_defined?(:ClassMethods, false) }
.map { |concern| concern.const_get(:ClassMethods) }
end

##
# @return [void]
#
def mark_as_included!
@included = true
end
end
end
end
Expand Down
5 changes: 0 additions & 5 deletions spec/lib/convenient_service/core/class_methods_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ def ==(other)
end
end

specify {
expect { service_class.concerns(&configuration_block) }
.to delegate_to(service_class.concerns, :assert_not_included!)
}

specify {
expect { service_class.concerns(&configuration_block) }
.to delegate_to(service_class.concerns, :configure)
Expand Down

0 comments on commit bbd0b73

Please sign in to comment.