Module: ServiceObjects::Helpers::Parameters

Included in:
Base, Parameterized
Defined in:
lib/service_objects/helpers/parameters.rb

Overview

Note:

A target class should include the module

Features for whitelisting service options

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.paramsHash (readonly)

Service object parameters



23
24
25
# File 'lib/service_objects/helpers/parameters.rb', line 23

def params
  @params
end

.whitelistArray<Symbol> (readonly)

Returns the list of allowed parameters



# File 'lib/service_objects/helpers/parameters.rb', line 13


Class Method Details

.initialize(options = {}) ⇒ undefined

Service object initializer

Examples:

Normalizing options

class AddFoo
  include ServiceObjects::Helpers::Parameters

  @whitelist = [:foo]
end

service = AddFoo.new("foo" => { "bar" => "baz" })
service.params # => { foo: { bar: "baz" } }

Whitelisting options

class AddFoo
  include ServiceObjects::Helpers::Parameters

  @whitelist = [:foo]
end

service = AddFoo.new(foo: "bar", bar: "baz")
service.params # => { foo: "bar" }


50
51
52
# File 'lib/service_objects/helpers/parameters.rb', line 50

def initialize(options = {})
  @params = Utils::NormalHash.from(options).slice(*__whitelist__)
end