Sha256: 3e2fd7eeaab7c2739c96126d500eee94634e34ec6c2570b463fa65071ccfbfe5

Contents?: true

Size: 1.12 KB

Versions: 24

Compression:

Stored size: 1.12 KB

Contents

module Riveter
  module Service
    extend ActiveSupport::Concern
    include AssociatedTypeRegistry

    module ClassMethods
      def register_as_handler_for(command_type)
        register_type self, command_type
      end
    end

    # override in derived classes
    def perform(command, *args)

      #
      # use the given command's attributes to perform the action
      #

      raise NotImplementedError
    end

    # helper class
    class Base
      include Service

      class << self
        def inherited(klass)
          #
          # attempt to get the name of the command
          # from the derived classes name and register
          # it as the service handler for that command
          #
          # e.g. CreatePortfolioCommand ==> CreatePortfolioService
          #
          command_type = klass.name.gsub(/Service$/, 'Command').constantize rescue nil
          register_type klass, command_type unless command_type.nil?
        end
      end

      # NOTE: associated commands will be registered on this class!
      # use the respective resolve methods with the Riveter::Service::Base in this case

    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
riveter-0.8.3 lib/riveter/service.rb
riveter-0.8.2 lib/riveter/service.rb
riveter-0.8.1 lib/riveter/service.rb
riveter-0.8.0 lib/riveter/service.rb
riveter-0.7.0 lib/riveter/service.rb
riveter-0.6.0 lib/riveter/service.rb
riveter-0.3.0 lib/riveter/service.rb
riveter-0.2.1 lib/riveter/service.rb
riveter-0.2.0 lib/riveter/service.rb
riveter-0.1.1 lib/riveter/service.rb
riveter-0.0.15 lib/riveter/service.rb
riveter-0.0.14 lib/riveter/service.rb
riveter-0.0.13 lib/riveter/service.rb
riveter-0.0.12 lib/riveter/service.rb
riveter-0.0.11 lib/riveter/service.rb
riveter-0.0.10 lib/riveter/service.rb
riveter-0.0.9 lib/riveter/service.rb
riveter-0.0.8 lib/riveter/service.rb
riveter-0.0.7 lib/riveter/service.rb
riveter-0.0.6 lib/riveter/service.rb