module Godfather
Constants
- VERSION
Public Class Methods
included(base)
click to toggle source
# File lib/godfather.rb, line 7 def self.included(base) base.send(:before_action, :init_crud, only: %i(where create update destroy)) end
Public Instance Methods
create()
click to toggle source
# File lib/godfather.rb, line 17 def create record = @crud.create_from_data render json: { success: true, id: record.id, } end
destroy()
click to toggle source
# File lib/godfather.rb, line 35 def destroy @crud.destroy_from_data render json: { success: true, } end
update()
click to toggle source
# File lib/godfather.rb, line 26 def update record = @crud.update_from_data render json: { success: true, id: record.id, } end
where()
click to toggle source
# File lib/godfather.rb, line 11 def where records = @crud.find_scoped_records render json: serialized(records) end
Private Instance Methods
init_crud()
click to toggle source
# File lib/godfather.rb, line 62 def init_crud @crud = Godfather::Manager.new(self, model, params[:scope], params[:data], params[:extra_find_scopes]) end
model()
click to toggle source
# File lib/godfather.rb, line 54 def model raise 'Override model method to specify a model to be used in CRUD' end
override!(name, value, data)
click to toggle source
# File lib/godfather.rb, line 58 def override!(name, value, data) value end
serialized(records)
click to toggle source
# File lib/godfather.rb, line 45 def serialized(records) return records unless defined?(ActiveModel::Serializer) serializer = ActiveModel::Serializer.serializer_for(records.first) return records unless serializer ActiveModel::ArraySerializer.new(records).to_json end