-
Notifications
You must be signed in to change notification settings - Fork 108
/
rails_app.rb
67 lines (56 loc) · 1.19 KB
/
rails_app.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
require "action_controller"
require "rails"
def request_params(params)
return params if Rails::VERSION::MAJOR < 5
{ params: params }
end
module Rails
class App
def env_config; {} end
def routes
@routes ||= ActionDispatch::Routing::RouteSet.new.tap do |routes|
routes.draw do
resources :birds
namespace :api do
resources :birds
end
end
end
end
end
def self.root
''
end
def self.application
@app ||= App.new
end
end
class Bird
attr_accessor :name
def initialize(options = {})
options.each { |k, v| self.public_send("#{k}=", v) }
end
end
class ApplicationController < ActionController::Base
include Rails.application.routes.url_helpers
end
def base_api_class
return ApplicationController if Rails::VERSION::MAJOR < 5
ActionController::API
end
class BirdsController < ApplicationController
%i(index show edit new create update).each do |action|
define_method action do
head :ok
end
end
end
module Api
class BirdsController < base_api_class
%i(index show edit new create update).each do |action|
define_method action do
head :ok
end
end
end
end