reel_template 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/reel_template/version.rb +1 -1
- data/template/lib/appname/commands.rb.erb +2 -2
- data/template/lib/appname/commands/create.rb.erb +19 -0
- data/template/lib/appname/commands/{test.rb.erb → get_all.rb.erb} +4 -2
- data/template/lib/appname/core.rb.erb +8 -0
- data/template/lib/appname/endpoints.rb.erb +2 -2
- data/template/lib/appname/endpoints/base.rb.erb +12 -0
- data/template/lib/appname/endpoints/test_endpoint.rb.erb +28 -5
- data/template/lib/appname/models.rb.erb +2 -2
- data/template/lib/appname/models/test.rb.erb +2 -1
- data/template/lib/appname/server.rb.erb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1517f28622ae1969ecbe03740539f63a200a606
|
4
|
+
data.tar.gz: f17540bd89a3f2e4d6619c1b63e5ffd6db97994e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 24c8db48181528af449d39ddfde1aea8c36982dbae6c087c7c12e4e2553d46c40ae81ae52d90e416673ee5baa165c84387ae4e70a5bd24c8c48b4acbaa39a9f1
|
7
|
+
data.tar.gz: 47371943250a4bc8b0282dde762001c72ed3fe9ffb1d01528d6c3234c1d6617174491b8e53d1b65b93012af5987090c6a7fa93039416647e6b4e43baa4e16f8d
|
@@ -7,8 +7,8 @@ module <%= @app_module %>
|
|
7
7
|
|
8
8
|
require '<%= @app_name %>/commands/base'
|
9
9
|
|
10
|
-
#
|
11
|
-
|
10
|
+
# Require all files from the 'commands' directory
|
11
|
+
<%= @app_module %>.require_dir 'commands'
|
12
12
|
|
13
13
|
end
|
14
14
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<%
|
2
|
+
@file_name = "lib/#{@app_name}/commands/create.rb"
|
3
|
+
%>
|
4
|
+
module <%= @app_module %>::Commands
|
5
|
+
class Create < Command
|
6
|
+
|
7
|
+
def execute
|
8
|
+
record = <%= @app_module %>::Models::Test.new(params)
|
9
|
+
|
10
|
+
if record.save
|
11
|
+
success record
|
12
|
+
else
|
13
|
+
failure record, t(:invalid, model: "ModelName") # Returns failure code with an invalid message (from locale/en.yml file)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -5,10 +5,12 @@
|
|
5
5
|
module <%= @app_module %>
|
6
6
|
module Commands
|
7
7
|
|
8
|
-
class
|
8
|
+
class GetAll < Command
|
9
9
|
|
10
10
|
def execute
|
11
|
-
|
11
|
+
database_records = <%= @app_module %>::Models::Test.all
|
12
|
+
|
13
|
+
success database_records
|
12
14
|
end
|
13
15
|
|
14
16
|
end
|
@@ -17,6 +17,14 @@ module <%= @app_module %>
|
|
17
17
|
<%= @app_const %>_ROOT
|
18
18
|
end
|
19
19
|
|
20
|
+
# Requires all .rb files in the named directory
|
21
|
+
# Useful for loading all commands / endpoints / models / etc...
|
22
|
+
# @param [String] directory The directory to load files from
|
23
|
+
def require_dir(directory)
|
24
|
+
directory = File.expand_path("../#{directory}", __FILE__)
|
25
|
+
Dir["#{directory}/**/*.rb"].each { |f| require f }
|
26
|
+
end
|
27
|
+
|
20
28
|
# Determines the current environment from the system ENV variable. Defaults to development
|
21
29
|
# @return [String] The current application environment
|
22
30
|
def env
|
@@ -11,8 +11,8 @@ module <%= @app_module %>
|
|
11
11
|
require '<%= @app_name %>/endpoints/base'
|
12
12
|
require '<%= @app_name %>/support/authentication'
|
13
13
|
|
14
|
-
#
|
15
|
-
|
14
|
+
# Require all files from the 'endpoints' directory
|
15
|
+
<%= @app_module %>.require_dir 'endpoints'
|
16
16
|
|
17
17
|
end
|
18
18
|
end
|
@@ -45,10 +45,22 @@ module <%= @app_module %>::Endpoints
|
|
45
45
|
@params ||= Hashie::Mash.new( combined_params )
|
46
46
|
end
|
47
47
|
|
48
|
+
# Returns the current user
|
49
|
+
# @current_user could be set from inside the `basic_auth` block located in support/authentication.rb
|
48
50
|
def current_user
|
49
51
|
@current_user || nil
|
50
52
|
end
|
51
53
|
|
54
|
+
# Returns an array of allowed HTTP methods (GET, POST, etc...)
|
55
|
+
def self.allowed_methods
|
56
|
+
raise NotImplementedError
|
57
|
+
end
|
58
|
+
|
59
|
+
# @private
|
60
|
+
def allowed_methods
|
61
|
+
self.class.allowed_methods
|
62
|
+
end
|
63
|
+
|
52
64
|
private
|
53
65
|
|
54
66
|
# Retrieves all parameters from request body, URL segments and URL query string
|
@@ -5,20 +5,43 @@
|
|
5
5
|
module <%= @app_module %>
|
6
6
|
module Endpoints
|
7
7
|
|
8
|
+
# Endpoint allows for the use of Webmachine resource callbacks
|
8
9
|
class TestEndpoint < Endpoint
|
9
10
|
|
10
|
-
|
11
|
-
|
11
|
+
# Only allow GET and POST requests to this endpoint
|
12
|
+
def self.allowed_methods
|
13
|
+
%w(GET POST)
|
12
14
|
end
|
13
15
|
|
16
|
+
# All URLs route to this endpoint
|
14
17
|
def self.path
|
15
|
-
["
|
18
|
+
["*"]
|
16
19
|
end
|
17
20
|
|
21
|
+
# POST requests create a resource
|
22
|
+
def post_is_create?
|
23
|
+
true
|
24
|
+
end
|
25
|
+
|
26
|
+
# Webmachine callback for POST requests
|
27
|
+
def create_path
|
28
|
+
create_command = <%= @app_module %>::Commands::Create.new(params)
|
29
|
+
@create_response = create_command.execute
|
30
|
+
|
31
|
+
"/#{@create_response.id}" # Returns the path to the created resource
|
32
|
+
end
|
33
|
+
|
34
|
+
# Called during POST and PUT requests
|
35
|
+
def from_json
|
36
|
+
send_response! @create_response
|
37
|
+
end
|
38
|
+
|
39
|
+
# Called for GET requests
|
18
40
|
def to_json
|
19
|
-
|
20
|
-
send_response!
|
41
|
+
get_all = <%= @app_module %>::Commands::GetAll.new(params)
|
42
|
+
send_response! get_all.execute
|
21
43
|
end
|
44
|
+
|
22
45
|
end
|
23
46
|
|
24
47
|
end
|
@@ -9,8 +9,8 @@ module <%= @app_module %>
|
|
9
9
|
|
10
10
|
require '<%= @app_name %>/support/serializable_attributes'
|
11
11
|
|
12
|
-
#
|
13
|
-
|
12
|
+
# Require all files from the 'models' directory
|
13
|
+
<%= @app_module %>.require_dir 'models'
|
14
14
|
|
15
15
|
end
|
16
16
|
end
|
@@ -12,8 +12,9 @@ module <%= @app_module %>
|
|
12
12
|
set_collection_name 'test'
|
13
13
|
|
14
14
|
key :test_field, String
|
15
|
+
validates_presence_of :test_field
|
15
16
|
|
16
|
-
|
17
|
+
serialize_attrs :id, :test_field # Only these fields are included in the response JSON output
|
17
18
|
end
|
18
19
|
|
19
20
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reel_template
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kyle Dayton
|
@@ -50,7 +50,8 @@ files:
|
|
50
50
|
- template/lib/app.rb.erb
|
51
51
|
- template/lib/appname/commands.rb.erb
|
52
52
|
- template/lib/appname/commands/base.rb.erb
|
53
|
-
- template/lib/appname/commands/
|
53
|
+
- template/lib/appname/commands/create.rb.erb
|
54
|
+
- template/lib/appname/commands/get_all.rb.erb
|
54
55
|
- template/lib/appname/config.rb.erb
|
55
56
|
- template/lib/appname/core.rb.erb
|
56
57
|
- template/lib/appname/endpoints.rb.erb
|