module Frigate::Operation::Renderable
allows operation to be rendered as json for now))
Public Class Methods
included(base)
click to toggle source
# File lib/frigate/operation/renderable.rb, line 5 def self.included(base) base.extend(ClassMethods) end
Public Instance Methods
render(ctrl)
click to toggle source
@param [ActionController::Base] ctrl An Instance of subclass of ActionController::Base
# File lib/frigate/operation/renderable.rb, line 24 def render(ctrl) ctrl.respond_to do |f| f.json do ctrl.render status: (model_form.valid? ? 200 : 400), json: build_json(ctrl) end end end
Private Instance Methods
build_json(ctrl)
click to toggle source
@param [ActionController::Base] ctrl An Instance of subclass of ActionController::Base
# File lib/frigate/operation/renderable.rb, line 35 def build_json(ctrl) if model_form.valid? Jbuilder.new { |_j| _j.status 'success'; _j.data { render_op(_j, self, ctrl) } }.target! else Jbuilder.new do |_j| _j.status 'error' _j.errors errors.messages end.target! end end
render_op(*args)
click to toggle source
# File lib/frigate/operation/renderable.rb, line 47 def render_op(*args) self.class.render_block.call(*args) if self.class.render_block.is_a?(Proc) end