lib/jsonapionify/api/context.rb in jsonapionify-0.9.0 vs lib/jsonapionify/api/context.rb in jsonapionify-0.9.1
- old
+ new
@@ -1,14 +1,27 @@
module JSONAPIonify::Api
- class Context < Struct.new :block, :readonly
+ class Context
+ def initialize(readonly: false, persisted: false, existing_context: nil, &block)
+ @readonly = readonly
+ @persisted = persisted
+ @existing_context = existing_context
+ @block = block
+ end
+
def call(instance, delegate)
- block = self.block || proc {}
- instance.instance_exec(delegate, &block)
+ existing_context = @existing_context || proc {}
+ existing_block = proc { existing_context.call(instance, delegate) }
+ block = @block || proc {}
+ instance.instance_exec(delegate, existing_block, &block)
end
def readonly?
- !!readonly
+ !!@readonly
end
+ def persisted?
+ !!@persisted
+ end
+
end
-end
\ No newline at end of file
+end