Class: JSONAPIonify::Api::Context
- Inherits:
-
Object
- Object
- JSONAPIonify::Api::Context
- Defined in:
- lib/jsonapionify/api/context.rb
Instance Method Summary collapse
- #call(instance, delegate) ⇒ Object
-
#initialize(name, readonly: false, persisted: false, existing_context: nil, &block) ⇒ Context
constructor
A new instance of Context.
- #persisted? ⇒ Boolean
- #readonly? ⇒ Boolean
Constructor Details
#initialize(name, readonly: false, persisted: false, existing_context: nil, &block) ⇒ Context
Returns a new instance of Context.
5 6 7 8 9 10 11 |
# File 'lib/jsonapionify/api/context.rb', line 5 def initialize(name, readonly: false, persisted: false, existing_context: nil, &block) @name = name.to_sym @readonly = readonly @persisted = persisted @existing_context = existing_context @block = block || proc {} end |
Instance Method Details
#call(instance, delegate) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/jsonapionify/api/context.rb', line 13 def call(instance, delegate) existing_context = @existing_context || proc {} existing_block = proc { existing_context.call(instance, delegate) } JSONAPIonify::CustomRescue.perform(remove: __FILE__, source: @block, formatter: ->() { .source_location.join(':') + ":in context: `#{@name}''" }) do instance.instance_exec(delegate, existing_block, &@block.destructure(0)) end end |
#persisted? ⇒ Boolean
25 26 27 |
# File 'lib/jsonapionify/api/context.rb', line 25 def persisted? !!@persisted end |
#readonly? ⇒ Boolean
21 22 23 |
# File 'lib/jsonapionify/api/context.rb', line 21 def readonly? !!@readonly end |