Class: Wallaby::ModelServiceProvider

Inherits:
Object
  • Object
show all
Defined in:
lib/interfaces/wallaby/model_service_provider.rb

Overview

Model service provider interface

Direct Known Subclasses

Custom::ModelServiceProvider

Instance Method Summary collapse

Constructor Details

#initialize(model_class, model_decorator) ⇒ ModelServiceProvider

Returns a new instance of ModelServiceProvider.

Parameters:

  • model_class (Class)
  • model_decorator (ModelDecorator, nil)

    model decorator

Raises:

  • (::ArgumentError)


8
9
10
11
12
13
# File 'lib/interfaces/wallaby/model_service_provider.rb', line 8

def initialize(model_class, model_decorator)
  raise ::ArgumentError, 'model class required' unless model_class

  @model_class = model_class
  @model_decorator = model_decorator
end

Instance Method Details

#collection(_params, _authorizer) ⇒ #to_a

Fetch collection by params

Parameters:

  • _params (ActionController::Parameters)
  • _authorizer

Returns:

  • (#to_a)

Raises:



28
29
30
# File 'lib/interfaces/wallaby/model_service_provider.rb', line 28

def collection(_params, _authorizer)
  raise NotImplemented
end

#create(_resource, _params, _authorizer) ⇒ Object

Save the newly initialized resource

Parameters:

  • _resource (Object)
  • _params (ActionController::Parameters)
  • _authorizer

Returns:

  • a resource object

Raises:



62
63
64
# File 'lib/interfaces/wallaby/model_service_provider.rb', line 62

def create(_resource, _params, _authorizer)
  raise NotImplemented
end

#destroy(_resource, _params, _authorizer) ⇒ Object

Destroy the given resource

Parameters:

  • _resource (Object)
  • _params (ActionController::Parameters)
  • _authorizer

Returns:

  • a resource object

Raises:



80
81
82
# File 'lib/interfaces/wallaby/model_service_provider.rb', line 80

def destroy(_resource, _params, _authorizer)
  raise NotImplemented
end

#find(_id, _params, _authorizer) ⇒ Object

Find a resource using id

Parameters:

  • _id (Object)
  • _params (ActionController::Parameters)
  • _authorizer

Returns:

  • a resource object

Raises:



53
54
55
# File 'lib/interfaces/wallaby/model_service_provider.rb', line 53

def find(_id, _params, _authorizer)
  raise NotImplemented
end

#new(_params, _authorizer) ⇒ Object

Initialize the model class using params

Parameters:

  • _params (ActionController::Parameters)
  • _authorizer

Returns:

  • a resource object

Raises:



44
45
46
# File 'lib/interfaces/wallaby/model_service_provider.rb', line 44

def new(_params, _authorizer)
  raise NotImplemented
end

#paginate(_query, _params) ⇒ #to_a

Paginate the resources

Parameters:

  • _query
  • _params (ActionController::Parameters)

Returns:

  • (#to_a)

Raises:



36
37
38
# File 'lib/interfaces/wallaby/model_service_provider.rb', line 36

def paginate(_query, _params)
  raise NotImplemented
end

#permit(_params, _action, _authorizer) ⇒ ActionController::Parameters

To allowlist params for a model class

Parameters:

  • _params (ActionController::Parameters)
  • _action (String, Symbol)
  • _authorizer (ModelAuthorizer)

Returns:

  • (ActionController::Parameters)

    allowlisted params

Raises:



20
21
22
# File 'lib/interfaces/wallaby/model_service_provider.rb', line 20

def permit(_params, _action, _authorizer)
  raise NotImplemented
end

#update(_resource, _params, _authorizer) ⇒ Object

Update the persisted resource

Parameters:

  • _resource (Object)
  • _params (ActionController::Parameters)
  • _authorizer

Returns:

  • a resource object

Raises:



71
72
73
# File 'lib/interfaces/wallaby/model_service_provider.rb', line 71

def update(_resource, _params, _authorizer)
  raise NotImplemented
end