Skip to content

Easier way to define context (base) class #7

@tdegrunt

Description

@tdegrunt

Replace the following logic with an extra parameter/argument to context method in the service:

      # Get the base class for new contexts defined using context blocks
      # Defaults to Servitium::Context
      def context_base_class_name
        @@_context_base_class_name ||= 'Servitium::Context'
      end

      # Override the base class for contexts defined using context blocks, you can use this to
      # change the base class to your own ApplicationContext
      def context_base_class_name=(base_class)
        @@_context_base_class_name = base_class
      end

Basically we want it to work like this:

# mobile_service.rb
class MobileService < ApplicationService
  context do
    # some basic context for all mobile services
  end
end

# mobile_add_user_service.rb
class MobileAddUserService < MobileService
  context do
    # context of MobileServce is here already, anything in ths block wil extend it
  end
end

Hereby we have a MobileService, which defines an implicit context (with class MobileContext).
The class MobileAddUserService inherits from MobileService, servitium should then understand that it should take the MobileContext as a base class.

For overrides, it would be nicer to be able to do this:

context base_class: 'ApplicationContext' do
end

Metadata

Metadata

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions