class AppBase::Engine::CrudInitializer
Public Class Methods
new(model, op)
click to toggle source
# File lib/appbase/railtie.rb, line 52 def initialize(model, op) @model = model @op = op @http_methods = { create: :post, update: :put, delete: :delete, query: :get } end
Public Instance Methods
init()
click to toggle source
# File lib/appbase/railtie.rb, line 58 def init pre_init add_controller_stub add_route end
Private Instance Methods
add_controller_stub()
click to toggle source
# File lib/appbase/railtie.rb, line 69 def add_controller_stub AppBaseController.send "add_#{@op}_stub".to_sym, @model end
add_route()
click to toggle source
# File lib/appbase/railtie.rb, line 73 def add_route model_name_underscore = AppBase.underscore @model.name url_path = "/#{model_name_underscore}" url_path += "/:id" if @op == :update || @op == :delete http_method = @http_methods[@op] op = @op AppBase::Engine.routes.append do match url_path, to: "app_base##{op}_#{model_name_underscore}", via: http_method end end
pre_init()
click to toggle source
# File lib/appbase/railtie.rb, line 65 def pre_init raise "Unexpected crud operation: #{@op}" if !@http_methods.has_key?(@op) end