Class: ConvenientService::Common::Plugins::CanHaveUserProvidedEntity::Commands::FindOrCreateEntity
- Inherits:
-
Support::Command
- Object
- Support::Command
- ConvenientService::Common::Plugins::CanHaveUserProvidedEntity::Commands::FindOrCreateEntity
- Defined in:
- lib/convenient_service/common/plugins/can_have_user_provided_entity/commands/find_or_create_entity.rb
Instance Attribute Summary collapse
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#proto_entity ⇒ Object
readonly
Returns the value of attribute proto_entity.
Instance Method Summary collapse
Methods inherited from Support::Command
Constructor Details
#initialize(namespace:, proto_entity:) ⇒ void
31 32 33 34 |
# File 'lib/convenient_service/common/plugins/can_have_user_provided_entity/commands/find_or_create_entity.rb', line 31 def initialize(namespace:, proto_entity:) @namespace = namespace @proto_entity = proto_entity end |
Instance Attribute Details
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
18 19 20 |
# File 'lib/convenient_service/common/plugins/can_have_user_provided_entity/commands/find_or_create_entity.rb', line 18 def namespace @namespace end |
#proto_entity ⇒ Object (readonly)
Returns the value of attribute proto_entity.
24 25 26 |
# File 'lib/convenient_service/common/plugins/can_have_user_provided_entity/commands/find_or_create_entity.rb', line 24 def proto_entity @proto_entity end |
Instance Method Details
#call ⇒ void
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/convenient_service/common/plugins/can_have_user_provided_entity/commands/find_or_create_entity.rb', line 39 def call ::ConvenientService.raise Exceptions::ProtoEntityHasNoName.new(proto_entity: proto_entity) unless proto_entity_name ::ConvenientService.raise Exceptions::ProtoEntityHasNoConcern.new(proto_entity: proto_entity) unless proto_entity_concern entity.include Core entity.include proto_entity_concern ## # @example Result for service. # # klass = ConvenientService::Common::Plugins::CanHaveUserProvidedEntity::Commands::FindOrCreateEntity.call( # namespace: SomeService, # proto_entity: ConvenientService::Service::Plugins::HasJSendResult::Entities::Result # ) # # ## # # `klass` is something like: # # # # class Result < ConvenientService::Service::Plugins::HasJSendResult::Entities::Result # or just `class Result` if service (namespace) class defines its own. # # include ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Concern # (concern) # # # # class << self # # def proto_entity # # ## # # # NOTE: Returns `proto_entity` passed to `FindOrCreateEntity`. # # # # # proto_entity # # end # # # # def ==(other) # # return unless other.respond_to?(:proto_entity) # # # # self.proto_entity == other.proto_entity # # end # # end # # end # entity.class_exec(proto_entity) do |proto_entity| ## # @return [Class] # define_singleton_method(:proto_entity) { proto_entity } ## # @param other [Object] Can by any type. # @return [Boolean, nil] # # @internal # TODO: Try `self.proto_entity == other.proto_entity if self < proto_entity_concern`. # define_singleton_method(:==) { |other| self.proto_entity == other.proto_entity if other.respond_to?(:proto_entity) } ## # TODO: `inspect`. # # define_singleton_method(:inspect) { "#{entity}(Prototyped by #{proto_entity})" } end entity end |