napa 0.1.21 → 0.1.22
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/napa/active_record_extensions/filter_by_hash.rb +1 -1
- data/lib/napa/generators/templates/api/app/apis/%name_tableize%_api.rb.tt +7 -12
- data/lib/napa/generators/templates/scaffold/{.env.test → .env.test.tt} +2 -2
- data/lib/napa/generators/templates/scaffold/.env.tt +6 -0
- data/lib/napa/generators/templates/scaffold/.gitignore.tt +2 -1
- data/lib/napa/generators/templates/scaffold/Gemfile +1 -3
- data/lib/napa/generators/templates/scaffold/app/apis/application_api.rb +9 -0
- data/lib/napa/generators/templates/scaffold/app/apis/hello_api.rb.tt +6 -9
- data/lib/napa/generators/templates/scaffold/app.rb +2 -3
- data/lib/napa/generators/templates/scaffold/config.ru.tt +1 -1
- data/lib/napa/grape_extenders.rb +17 -0
- data/lib/napa/grape_extensions/error_presenter.rb +1 -1
- data/lib/napa/json_error.rb +6 -2
- data/lib/napa/stats_d_timer.rb +22 -0
- data/lib/napa/version.rb +1 -1
- data/lib/napa.rb +1 -1
- data/lib/tasks/db.rake +4 -8
- metadata +7 -5
- data/lib/napa/generators/templates/scaffold/.env +0 -6
- data/lib/napa/grape_api.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a86977739a2b0f1f4cf4aaa6e09e4e46cb418bb1
|
4
|
+
data.tar.gz: 17e5f2adcfac479a0dffaa387426cb4bc62f332d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c773958e1082a196633c1b3fcc0e98fd3d71749508067f962e8e5b4a372e8bee079c9a74abe0c136bedeb3ec08137a9990fb1cb6b9c132f9134f800056c04098
|
7
|
+
data.tar.gz: 270d6fae56b4ab43ef83ad14f85775e6e9d489985eb7aa2d20505837fdcd6fa4b8abf9a6fafd6dc6db1b1cbab1393aeb814b5d2761f63d94948d6c6c58d5dcbe
|
@@ -6,7 +6,7 @@ if defined?(ActiveRecord)
|
|
6
6
|
# pass an empty where clause to force results to be a relation that will be lazy evaluated
|
7
7
|
results = where({})
|
8
8
|
search_hash.each do |k, v|
|
9
|
-
results = results.where(k => v)
|
9
|
+
results = results.where(k => v)
|
10
10
|
end
|
11
11
|
results
|
12
12
|
end
|
@@ -1,12 +1,11 @@
|
|
1
1
|
class <%= name.classify.pluralize %>Api < Grape::API
|
2
|
-
represent <%= name.classify %>, with: <%= name.classify %>Entity
|
3
2
|
desc 'Get a list of <%= name.underscore.tableize %>', entity: <%= name.classify %>Entity
|
4
3
|
params do
|
5
4
|
optional :ids, type: String, desc: 'comma separated <%= name.underscore %> ids'
|
6
5
|
end
|
7
6
|
get do
|
8
|
-
<%= name.underscore.tableize %> = <%= name.classify %>.filter(declared(params))
|
9
|
-
present <%= name.underscore.tableize %>
|
7
|
+
<%= name.underscore.tableize %> = <%= name.classify %>.filter(declared(params, include_missing: false))
|
8
|
+
present <%= name.underscore.tableize %>, with: <%= name.classify %>Entity
|
10
9
|
end
|
11
10
|
|
12
11
|
desc 'Create an <%= name.underscore %>', entity: <%= name.classify %>Entity
|
@@ -14,13 +13,9 @@ class <%= name.classify.pluralize %>Api < Grape::API
|
|
14
13
|
end
|
15
14
|
|
16
15
|
post do
|
17
|
-
|
18
|
-
<%= name.underscore %> = <%= name.classify %>.create(declared(params))
|
19
|
-
rescue NameError
|
20
|
-
error!(present_error(:kind_not_found))
|
21
|
-
end
|
16
|
+
<%= name.underscore %> = <%= name.classify %>.create(declared(params, include_missing: false))
|
22
17
|
error!(present_error(:record_invalid, <%= name.underscore %>.errors.full_messages)) unless <%= name.underscore %>.errors.empty?
|
23
|
-
present <%= name.underscore %>
|
18
|
+
present <%= name.underscore %>, with: <%= name.classify %>Entity
|
24
19
|
end
|
25
20
|
|
26
21
|
params do
|
@@ -30,7 +25,7 @@ class <%= name.classify.pluralize %>Api < Grape::API
|
|
30
25
|
desc 'Get an <%= name.underscore %>', entity: <%= name.classify %>Entity
|
31
26
|
get do
|
32
27
|
<%= name.underscore %> = <%= name.classify %>.find(params[:id])
|
33
|
-
present <%= name.underscore %>
|
28
|
+
present <%= name.underscore %>, with: <%= name.classify %>Entity
|
34
29
|
end
|
35
30
|
|
36
31
|
desc 'Update an <%= name.underscore %>', entity: <%= name.classify %>Entity
|
@@ -39,8 +34,8 @@ class <%= name.classify.pluralize %>Api < Grape::API
|
|
39
34
|
put do
|
40
35
|
# fetch <%= name.underscore %> record and update attributes. exceptions caught in app.rb
|
41
36
|
<%= name.underscore %> = <%= name.classify %>.find(params[:id])
|
42
|
-
<%= name.underscore %>.update_attributes!(declared(params).select { |param, value| value.present? })
|
43
|
-
present <%= name.underscore %>
|
37
|
+
<%= name.underscore %>.update_attributes!(declared(params, include_missing: false).select { |param, value| value.present? })
|
38
|
+
present <%= name.underscore %>, with: <%= name.classify %>Entity
|
44
39
|
end
|
45
40
|
end
|
46
41
|
end
|
@@ -2,13 +2,11 @@ source 'https://rubygems.org'
|
|
2
2
|
|
3
3
|
gem 'rack-cors'
|
4
4
|
gem 'mysql2'
|
5
|
-
gem 'activerecord',
|
5
|
+
gem 'activerecord', :require => 'active_record'
|
6
6
|
gem 'honeybadger'
|
7
7
|
gem 'json'
|
8
8
|
gem 'shotgun'
|
9
9
|
gem 'napa'
|
10
|
-
gem 'grape-pagination'
|
11
|
-
gem 'will_paginate', '~> 3.0'
|
12
10
|
|
13
11
|
group :development,:test do
|
14
12
|
gem 'pry'
|
@@ -1,13 +1,10 @@
|
|
1
|
-
|
2
|
-
class API < Grape::API
|
3
|
-
format :json
|
1
|
+
class HelloApi < Grape::API
|
4
2
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
end
|
3
|
+
resource :hello do
|
4
|
+
desc 'Return a Hello World message'
|
5
|
+
get do
|
6
|
+
{ message: 'Hello Wonderful World, from <%= app_name.classify %>!' }
|
10
7
|
end
|
11
|
-
|
12
8
|
end
|
9
|
+
|
13
10
|
end
|
@@ -4,8 +4,6 @@ Bundler.setup(:default)
|
|
4
4
|
require 'napa/setup'
|
5
5
|
Bundler.require(:default, Napa.env.to_sym)
|
6
6
|
require 'napa'
|
7
|
-
require 'will_paginate'
|
8
|
-
require 'will_paginate/active_record'
|
9
7
|
|
10
8
|
# load environment
|
11
9
|
Dotenv.load(Napa.env.test? ? '.env.test' : '.env')
|
@@ -20,4 +18,5 @@ Dir['./config/initializers/**/*.rb'].map { |file| require file }
|
|
20
18
|
Dir['./config/middleware/**/*.rb'].map { |file| require file }
|
21
19
|
|
22
20
|
# autoload app
|
23
|
-
|
21
|
+
relative_load_paths = %w[app/apis app/entities app/models app/workers lib]
|
22
|
+
ActiveSupport::Dependencies.autoload_paths += relative_load_paths
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Napa
|
2
|
+
module GrapeExtenders
|
3
|
+
def self.extended(modified_class)
|
4
|
+
# when extended, set the exceptions to handle
|
5
|
+
|
6
|
+
# if AR is being used, rescue from common AR errors
|
7
|
+
if defined?(::ActiveRecord)
|
8
|
+
modified_class.rescue_from ::ActiveRecord::RecordNotFound do |e|
|
9
|
+
rack_response(Napa::JsonError.new(:record_not_found, 'record not found').to_json, 404)
|
10
|
+
end
|
11
|
+
modified_class.rescue_from ::ActiveRecord::RecordInvalid do |e|
|
12
|
+
rack_response(Napa::JsonError.new(:record_invalid, 'record not found').to_json, 500)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/napa/json_error.rb
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
module Napa
|
2
|
+
module StatsDTimer
|
3
|
+
def report_time(timer_name)
|
4
|
+
start_time = Time.now
|
5
|
+
yield
|
6
|
+
response_time = Time.now - start_time
|
7
|
+
Napa::Stats.emitter.timing(timer_name, response_time)
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
def report_time(timer_name)
|
12
|
+
new.report_time(timer_name) do
|
13
|
+
yield
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.included(base)
|
19
|
+
base.extend(ClassMethods)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/napa/version.rb
CHANGED
data/lib/napa.rb
CHANGED
@@ -17,13 +17,13 @@ require 'napa/stats'
|
|
17
17
|
require 'napa/active_record_extensions/filter_by_hash'
|
18
18
|
require 'napa/grape_extensions/error_formatter'
|
19
19
|
require 'napa/grape_extensions/error_presenter'
|
20
|
+
require 'napa/grape_extenders'
|
20
21
|
require 'napa/middleware/logger'
|
21
22
|
require 'napa/middleware/app_monitor'
|
22
23
|
require 'napa/middleware/authentication'
|
23
24
|
require 'napa/middleware/request_stats'
|
24
25
|
require 'napa/activerecord'
|
25
26
|
require 'napa/authentication'
|
26
|
-
require 'napa/grape_api'
|
27
27
|
|
28
28
|
# load rake tasks if Rake installed
|
29
29
|
if defined?(Rake)
|
data/lib/tasks/db.rake
CHANGED
@@ -47,18 +47,14 @@ unless defined?(Rails)
|
|
47
47
|
# Define migrations path (needed later)
|
48
48
|
migrations_path = './db/migrate'
|
49
49
|
|
50
|
-
#
|
51
|
-
|
52
|
-
version = File.basename(existing_migrations.sort.reverse.first)[/^(\d+)_/,1].to_i + 1
|
53
|
-
else
|
54
|
-
version = 1
|
55
|
-
end
|
50
|
+
# timestamp the migration
|
51
|
+
version = Time.now.utc.to_s.gsub(':','').gsub('-','').gsub('UTC','').gsub(' ','')
|
56
52
|
|
57
53
|
# Use the migration template to fill the body of the migration
|
58
54
|
migration_content = Napa::ActiveRecord.migration_template(migration_name.camelize)
|
59
55
|
|
60
56
|
# Generate migration filename
|
61
|
-
migration_filename = "#{
|
57
|
+
migration_filename = "#{version}_#{migration_name}.rb"
|
62
58
|
|
63
59
|
# Write the migration
|
64
60
|
File.open(File.join(migrations_path, migration_filename), "w+") do |migration|
|
@@ -86,4 +82,4 @@ unless defined?(Rails)
|
|
86
82
|
end
|
87
83
|
end
|
88
84
|
end
|
89
|
-
end
|
85
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: napa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.22
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Darby Frey
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -261,14 +261,15 @@ files:
|
|
261
261
|
- lib/napa/generators/templates/api/app/apis/%name_tableize%_api.rb.tt
|
262
262
|
- lib/napa/generators/templates/api/app/entities/%name_underscore%_entity.rb.tt
|
263
263
|
- lib/napa/generators/templates/api/app/models/%name_underscore%.rb.tt
|
264
|
-
- lib/napa/generators/templates/scaffold/.env
|
265
|
-
- lib/napa/generators/templates/scaffold/.env.
|
264
|
+
- lib/napa/generators/templates/scaffold/.env.test.tt
|
265
|
+
- lib/napa/generators/templates/scaffold/.env.tt
|
266
266
|
- lib/napa/generators/templates/scaffold/.gitignore.tt
|
267
267
|
- lib/napa/generators/templates/scaffold/.rubocop.yml
|
268
268
|
- lib/napa/generators/templates/scaffold/Gemfile
|
269
269
|
- lib/napa/generators/templates/scaffold/README.md
|
270
270
|
- lib/napa/generators/templates/scaffold/Rakefile
|
271
271
|
- lib/napa/generators/templates/scaffold/app.rb
|
272
|
+
- lib/napa/generators/templates/scaffold/app/apis/application_api.rb
|
272
273
|
- lib/napa/generators/templates/scaffold/app/apis/hello_api.rb.tt
|
273
274
|
- lib/napa/generators/templates/scaffold/config.ru.tt
|
274
275
|
- lib/napa/generators/templates/scaffold/config/database.yml
|
@@ -279,7 +280,7 @@ files:
|
|
279
280
|
- lib/napa/generators/templates/scaffold/spec/apis/hello_api_spec.rb
|
280
281
|
- lib/napa/generators/templates/scaffold/spec/factories/.gitkeep
|
281
282
|
- lib/napa/generators/templates/scaffold/spec/spec_helper.rb
|
282
|
-
- lib/napa/
|
283
|
+
- lib/napa/grape_extenders.rb
|
283
284
|
- lib/napa/grape_extensions/error_formatter.rb
|
284
285
|
- lib/napa/grape_extensions/error_presenter.rb
|
285
286
|
- lib/napa/identity.rb
|
@@ -292,6 +293,7 @@ files:
|
|
292
293
|
- lib/napa/middleware/request_stats.rb
|
293
294
|
- lib/napa/setup.rb
|
294
295
|
- lib/napa/stats.rb
|
296
|
+
- lib/napa/stats_d_timer.rb
|
295
297
|
- lib/napa/version.rb
|
296
298
|
- lib/tasks/db.rake
|
297
299
|
- lib/tasks/deploy.rake
|
data/lib/napa/grape_api.rb
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
require 'grape'
|
2
|
-
class Napa::GrapeAPI < Grape::API
|
3
|
-
def after
|
4
|
-
@app_response[1]['Cache-Control'] = 'no-cache, no-store, max-age=0, must-revalidate'
|
5
|
-
@app_response[1]['Pragma'] = 'no-cache'
|
6
|
-
@app_response[1]['Expires'] = 'Fri, 01 Jan 1990 00:00:00 GMT'
|
7
|
-
@app_response
|
8
|
-
end
|
9
|
-
end
|