Class: ZeroRailsAdapter::Mutator
- Inherits:
-
Object
- Object
- ZeroRailsAdapter::Mutator
- Includes:
- ActiveModel::Attributes, ActiveModel::Model
- Defined in:
- lib/zero_rails_adapter/mutator.rb
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
Returns the value of attribute arguments.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
Class Method Summary collapse
- .authorize_with(callable = nil, &block) ⇒ Object
- .call(arguments = {}, context:) ⇒ Object
- .mutation_name(name = nil) ⇒ Object
- .perform(&block) ⇒ Object
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(arguments = {}, context:) ⇒ Mutator
constructor
A new instance of Mutator.
- #perform ⇒ Object
Constructor Details
#initialize(arguments = {}, context:) ⇒ Mutator
Returns a new instance of Mutator.
34 35 36 37 38 39 |
# File 'lib/zero_rails_adapter/mutator.rb', line 34 def initialize(arguments = {}, context:) @arguments = arguments @context = context attributes = arguments.respond_to?(:to_h) ? arguments.to_h.symbolize_keys : {} super(attributes) end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
Returns the value of attribute arguments.
11 12 13 |
# File 'lib/zero_rails_adapter/mutator.rb', line 11 def arguments @arguments end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
11 12 13 |
# File 'lib/zero_rails_adapter/mutator.rb', line 11 def context @context end |
Class Method Details
.authorize_with(callable = nil, &block) ⇒ Object
21 22 23 |
# File 'lib/zero_rails_adapter/mutator.rb', line 21 def (callable = nil, &block) self. = callable || block end |
.call(arguments = {}, context:) ⇒ Object
29 30 31 |
# File 'lib/zero_rails_adapter/mutator.rb', line 29 def call(arguments = {}, context:) new(arguments, context:).call end |
.mutation_name(name = nil) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/zero_rails_adapter/mutator.rb', line 14 def mutation_name(name = nil) return configured_mutation_name if name.nil? self.configured_mutation_name = name.to_s ZeroRailsAdapter.registry.register(self) end |
.perform(&block) ⇒ Object
25 26 27 |
# File 'lib/zero_rails_adapter/mutator.rb', line 25 def perform(&block) define_method(:perform, &block) end |
Instance Method Details
#call ⇒ Object
41 42 43 44 45 |
# File 'lib/zero_rails_adapter/mutator.rb', line 41 def call validate_arguments! perform end |
#perform ⇒ Object
47 48 49 |
# File 'lib/zero_rails_adapter/mutator.rb', line 47 def perform raise NotImplementedError, "#{self.class.name} must implement #perform" end |