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(readonly: false, persisted: false, existing_context: nil, &block) ⇒ Context
constructor
A new instance of Context.
- #persisted? ⇒ Boolean
- #readonly? ⇒ Boolean
Constructor Details
#initialize(readonly: false, persisted: false, existing_context: nil, &block) ⇒ Context
Returns a new instance of Context.
5 6 7 8 9 10 |
# File 'lib/jsonapionify/api/context.rb', line 5 def initialize(readonly: false, persisted: false, existing_context: nil, &block) @readonly = readonly @persisted = persisted @existing_context = existing_context @block = block || proc {} end |
Instance Method Details
#call(instance, delegate) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/jsonapionify/api/context.rb', line 12 def call(instance, delegate) existing_context = @existing_context || proc {} existing_block = proc { existing_context.call(instance, delegate) } begin instance.instance_exec(delegate, existing_block, &@block.destructure(0)) rescue => e e.backtrace.unshift @block.source_location.join(':') + ":in (context)" raise e end end |
#persisted? ⇒ Boolean
27 28 29 |
# File 'lib/jsonapionify/api/context.rb', line 27 def persisted? !!@persisted end |
#readonly? ⇒ Boolean
23 24 25 |
# File 'lib/jsonapionify/api/context.rb', line 23 def readonly? !!@readonly end |