napa 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.rubocop.yml +17 -0
- data/bin/napa +1 -1
- data/lib/generators/scaffold.rb +28 -27
- data/lib/generators/templates/scaffold/.rubocop.yml +14 -0
- data/lib/generators/templates/scaffold/Rakefile +1 -1
- data/lib/generators/templates/scaffold/app/apis/hello_api.rb +3 -3
- data/lib/generators/templates/scaffold/app.rb +6 -6
- data/lib/generators/templates/scaffold/lib/password_protected_helpers.rb +5 -5
- data/lib/generators/templates/scaffold/spec/apis/hello_api_spec.rb +2 -2
- data/lib/generators/templates/scaffold/spec/spec_helper.rb +2 -3
- data/lib/napa/activerecord.rb +1 -1
- data/lib/napa/grape_api.rb +6 -6
- data/lib/napa/logger/log_transaction.rb +1 -1
- data/lib/napa/logger/logger.rb +3 -5
- data/lib/napa/middleware/app_monitor.rb +1 -1
- data/lib/napa/middleware/logger.rb +36 -38
- data/lib/napa/version.rb +11 -11
- data/lib/napa.rb +11 -11
- data/lib/tasks/db.rake +78 -76
- data/napa.gemspec +2 -1
- data/spec/identity_spec.rb +20 -20
- data/spec/logger/log_transaction_spec.rb +7 -7
- data/spec/version_spec.rb +21 -21
- metadata +26 -8
data/.rubocop.yml
ADDED
data/bin/napa
CHANGED
data/lib/generators/scaffold.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Napa
|
2
2
|
module Generators
|
3
3
|
class Scaffold
|
4
|
-
def initialize(app_name, app_path=nil)
|
4
|
+
def initialize(app_name, app_path = nil)
|
5
5
|
@app_name = app_name
|
6
6
|
@app_path = app_path.nil? ? app_name : app_path
|
7
7
|
@template_path = File.expand_path(File.join(File.dirname(__FILE__), 'templates/scaffold'))
|
@@ -13,28 +13,29 @@ module Napa
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def file_list
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
16
|
+
[
|
17
|
+
'app/apis/hello_api.rb',
|
18
|
+
'app/models/.keep',
|
19
|
+
'config/database.yml',
|
20
|
+
'config/initializers/active_record.rb',
|
21
|
+
'config/middleware/honeybadger.rb',
|
22
|
+
'db/migrate/.keep',
|
23
|
+
'lib/tasks/.keep',
|
24
|
+
'log/.keep',
|
25
|
+
'public/.keep',
|
26
|
+
'spec/spec_helper.rb',
|
27
|
+
'spec/apis/hello_api_spec.rb',
|
28
|
+
'tmp/.keep',
|
29
|
+
'.env',
|
30
|
+
'.env.test',
|
31
|
+
'.rubocopy.yml',
|
32
|
+
'.gitignore.tpl',
|
33
|
+
'app.rb',
|
34
|
+
'config.ru',
|
35
|
+
'console',
|
36
|
+
'Gemfile',
|
37
|
+
'Rakefile',
|
38
|
+
'README.md'
|
38
39
|
]
|
39
40
|
end
|
40
41
|
|
@@ -45,8 +46,8 @@ module Napa
|
|
45
46
|
end
|
46
47
|
|
47
48
|
def create_file_with_template(file)
|
48
|
-
template_file = [@template_path, file].join(
|
49
|
-
new_file = [@app_name, file.gsub(/.tpl$/,'')].join(
|
49
|
+
template_file = [@template_path, file].join('/')
|
50
|
+
new_file = [@app_name, file.gsub(/.tpl$/, '')].join('/')
|
50
51
|
|
51
52
|
FileUtils.mkdir_p(File.dirname(new_file))
|
52
53
|
|
@@ -55,7 +56,7 @@ module Napa
|
|
55
56
|
|
56
57
|
# replace template variables
|
57
58
|
file_content.gsub!(/{{app_name}}/, @app_name)
|
58
|
-
File.open(new_file, 'w') { |
|
59
|
+
File.open(new_file, 'w') { |f| f.write(file_content) }
|
59
60
|
else
|
60
61
|
FileUtils.touch(new_file)
|
61
62
|
end
|
@@ -64,4 +65,4 @@ module Napa
|
|
64
65
|
end
|
65
66
|
end
|
66
67
|
end
|
67
|
-
end
|
68
|
+
end
|
@@ -2,10 +2,10 @@ module HelloService
|
|
2
2
|
class API < Grape::API
|
3
3
|
format :json
|
4
4
|
|
5
|
-
resource :hello do
|
6
|
-
desc
|
5
|
+
resource :hello do
|
6
|
+
desc 'Return a Hello World message'
|
7
7
|
get do
|
8
|
-
{message:
|
8
|
+
{ message: 'Hello Wonderful World!' }
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
@@ -3,19 +3,19 @@ Bundler.setup(:default)
|
|
3
3
|
require 'napa'
|
4
4
|
Bundler.require(:default, Napa.env.to_sym)
|
5
5
|
require 'will_paginate'
|
6
|
-
require 'will_paginate/active_record'
|
6
|
+
require 'will_paginate/active_record'
|
7
7
|
|
8
8
|
# load environment
|
9
|
-
Dotenv.load(Napa.env.test? ?
|
9
|
+
Dotenv.load(Napa.env.test? ? '.env.test' : '.env')
|
10
10
|
|
11
11
|
# autoload lib
|
12
|
-
Dir['./lib/**/**/*.rb'].map {|file| require file }
|
12
|
+
Dir['./lib/**/**/*.rb'].map { |file| require file }
|
13
13
|
|
14
14
|
# autoload initalizers
|
15
|
-
Dir['./config/initializers/**/*.rb'].map {|file| require file }
|
15
|
+
Dir['./config/initializers/**/*.rb'].map { |file| require file }
|
16
16
|
|
17
17
|
# load middleware configs
|
18
|
-
Dir['./config/middleware/**/*.rb'].map {|file| require file }
|
18
|
+
Dir['./config/middleware/**/*.rb'].map { |file| require file }
|
19
19
|
|
20
20
|
# autoload app
|
21
|
-
Dir['./app/**/**/*.rb'].map {|file| require file }
|
21
|
+
Dir['./app/**/**/*.rb'].map { |file| require file }
|
@@ -1,14 +1,14 @@
|
|
1
1
|
module PasswordProtectedHelpers
|
2
2
|
if ENV['HEADER_PASSWORDS']
|
3
|
-
PW_ARRAY = ENV['HEADER_PASSWORDS'].split(',').
|
3
|
+
PW_ARRAY = ENV['HEADER_PASSWORDS'].split(',').map { |pw| pw.strip }.freeze
|
4
4
|
else
|
5
5
|
PW_ARRAY = [nil].freeze
|
6
6
|
end
|
7
7
|
|
8
|
-
def authenticate
|
9
|
-
error!(
|
10
|
-
:
|
11
|
-
:
|
8
|
+
def authenticate(headers)
|
9
|
+
error!(error: {
|
10
|
+
code: 'bad_password',
|
11
|
+
message: 'bad password' }
|
12
12
|
) unless PW_ARRAY.include? headers['Password']
|
13
13
|
end
|
14
14
|
|
@@ -10,8 +10,8 @@ describe HelloService::API do
|
|
10
10
|
describe 'GET /hello' do
|
11
11
|
it 'returns a hello world message' do
|
12
12
|
get '/hello'
|
13
|
-
expect(last_response.body).to eq({message:
|
13
|
+
expect(last_response.body).to eq({ message: 'Hello Wonderful World!' }.to_json)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
end
|
17
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
ENV['RACK_ENV'] = 'test'
|
2
2
|
|
3
3
|
require 'webmock/rspec'
|
4
|
-
require
|
4
|
+
require 'rack/test'
|
5
5
|
require 'simplecov'
|
6
6
|
require 'factory_girl'
|
7
7
|
|
@@ -14,8 +14,7 @@ require 'database_cleaner'
|
|
14
14
|
|
15
15
|
# Requires supporting ruby files with custom matchers and macros, etc,
|
16
16
|
# in spec/support/ and its subdirectories.
|
17
|
-
Dir[
|
18
|
-
|
17
|
+
Dir['./spec/support/**/*.rb'].each { |f| require f }
|
19
18
|
|
20
19
|
RSpec.configure do |config|
|
21
20
|
config.include FactoryGirl::Syntax::Methods
|
data/lib/napa/activerecord.rb
CHANGED
data/lib/napa/grape_api.rb
CHANGED
@@ -2,14 +2,14 @@ require 'grape'
|
|
2
2
|
require 'grape-swagger'
|
3
3
|
|
4
4
|
class Napa::GrapeAPI < Grape::API
|
5
|
-
|
5
|
+
|
6
6
|
def after
|
7
|
-
@app_response[1][
|
8
|
-
@app_response[1][
|
9
|
-
@app_response[1][
|
7
|
+
@app_response[1]['Cache-Control'] = 'no-cache, no-store, max-age=0, must-revalidate'
|
8
|
+
@app_response[1]['Pragma'] = 'no-cache'
|
9
|
+
@app_response[1]['Expires'] = 'Fri, 01 Jan 1990 00:00:00 GMT'
|
10
10
|
@app_response
|
11
11
|
end
|
12
12
|
|
13
13
|
add_swagger_documentation
|
14
|
-
|
15
|
-
end
|
14
|
+
|
15
|
+
end
|
data/lib/napa/logger/logger.rb
CHANGED
@@ -13,17 +13,15 @@ module Napa
|
|
13
13
|
unless @logger
|
14
14
|
Logging.appenders.stdout(
|
15
15
|
'stdout',
|
16
|
-
:
|
16
|
+
layout: Logging.layouts.json
|
17
17
|
)
|
18
18
|
Logging.appenders.file(
|
19
19
|
"log/#{Napa.env}.log",
|
20
|
-
:
|
20
|
+
layout: Logging.layouts.json
|
21
21
|
)
|
22
22
|
|
23
23
|
@logger = Logging.logger["[#{name}]"]
|
24
|
-
unless Napa.env.test?
|
25
|
-
@logger.add_appenders 'stdout'
|
26
|
-
end
|
24
|
+
@logger.add_appenders 'stdout' unless Napa.env.test?
|
27
25
|
@logger.add_appenders "log/#{Napa.env}.log"
|
28
26
|
end
|
29
27
|
|
@@ -7,7 +7,7 @@ module Napa
|
|
7
7
|
|
8
8
|
def call(env)
|
9
9
|
if env['REQUEST_PATH'] == '/health'
|
10
|
-
[200, {'Content-type' => 'application/json'}, [Napa::Identity.health.to_json]]
|
10
|
+
[200, { 'Content-type' => 'application/json' }, [Napa::Identity.health.to_json]]
|
11
11
|
else
|
12
12
|
@app.call(env)
|
13
13
|
end
|
@@ -6,9 +6,6 @@ module Napa
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def call(env)
|
9
|
-
# set transaction_id
|
10
|
-
transaction_id=SecureRandom.uuid
|
11
|
-
|
12
9
|
# log the request
|
13
10
|
Napa::Logger.logger.debug format_request(env)
|
14
11
|
|
@@ -25,45 +22,46 @@ module Napa
|
|
25
22
|
Napa::LogTransaction.clear
|
26
23
|
end
|
27
24
|
|
28
|
-
|
29
|
-
def format_request(env)
|
30
|
-
request = Rack::Request.new(env)
|
31
|
-
params = request.params
|
32
|
-
begin
|
33
|
-
params = JSON.parse(request.body.read) if env['CONTENT_TYPE'] == 'application/json'
|
34
|
-
rescue
|
35
|
-
# do nothing, params is already set
|
36
|
-
end
|
25
|
+
private
|
37
26
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
}
|
47
|
-
request_data[:user_id] = current_user.try(:id) if defined?(current_user)
|
48
|
-
{request: request_data}
|
49
|
-
end
|
27
|
+
def format_request(env)
|
28
|
+
request = Rack::Request.new(env)
|
29
|
+
params = request.params
|
30
|
+
begin
|
31
|
+
params = JSON.parse(request.body.read) if env['CONTENT_TYPE'] == 'application/json'
|
32
|
+
rescue
|
33
|
+
# do nothing, params is already set
|
34
|
+
end
|
50
35
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
36
|
+
request_data = {
|
37
|
+
method: env['REQUEST_METHOD'],
|
38
|
+
path: env['PATH_INFO'],
|
39
|
+
query: env['QUERY_STRING'],
|
40
|
+
host: Napa::Identity.hostname,
|
41
|
+
pid: Napa::Identity.pid,
|
42
|
+
revision: Napa::Identity.revision,
|
43
|
+
params: params
|
44
|
+
}
|
45
|
+
request_data[:user_id] = current_user.try(:id) if defined?(current_user)
|
46
|
+
{ request: request_data }
|
57
47
|
end
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
48
|
+
|
49
|
+
def format_response(status, headers, body)
|
50
|
+
response_body = nil
|
51
|
+
begin
|
52
|
+
response_body = body.respond_to?(:body) ? body.body.map { |r| r } : nil
|
53
|
+
rescue
|
54
|
+
response_body = body.inspect
|
55
|
+
end
|
56
|
+
|
57
|
+
{ response:
|
58
|
+
{
|
59
|
+
status: status,
|
60
|
+
headers: headers,
|
61
|
+
response: response_body
|
62
|
+
}
|
64
63
|
}
|
65
|
-
|
66
|
-
end
|
64
|
+
end
|
67
65
|
end
|
68
66
|
end
|
69
67
|
end
|
data/lib/napa/version.rb
CHANGED
@@ -1,41 +1,41 @@
|
|
1
1
|
module Napa
|
2
|
-
VERSION =
|
2
|
+
VERSION = '0.1.3'
|
3
3
|
|
4
4
|
class Version
|
5
5
|
class << self
|
6
6
|
def next_major
|
7
|
-
|
7
|
+
next_level(:major)
|
8
8
|
end
|
9
9
|
|
10
10
|
def next_minor
|
11
|
-
|
11
|
+
next_level(:minor)
|
12
12
|
end
|
13
13
|
|
14
14
|
def next_patch
|
15
|
-
|
15
|
+
next_level(:patch)
|
16
16
|
end
|
17
17
|
|
18
18
|
def next_level(level)
|
19
|
-
|
19
|
+
fail 'Unidentified Level' unless [:major, :minor, :patch].include?(level)
|
20
20
|
|
21
|
-
parts = Napa::VERSION.split('.').map{|p| p.to_i}
|
21
|
+
parts = Napa::VERSION.split('.').map { |p| p.to_i }
|
22
22
|
|
23
23
|
if level == :major
|
24
|
-
parts[0] += 1
|
24
|
+
parts[0] += 1
|
25
25
|
significant_index = 1
|
26
26
|
end
|
27
27
|
|
28
28
|
if level == :minor
|
29
|
-
parts[1] += 1
|
30
|
-
significant_index = 2
|
29
|
+
parts[1] += 1
|
30
|
+
significant_index = 2
|
31
31
|
end
|
32
32
|
|
33
33
|
if level == :patch
|
34
|
-
parts[2] += 1
|
34
|
+
parts[2] += 1
|
35
35
|
significant_index = 3
|
36
36
|
end
|
37
37
|
|
38
|
-
parts.map.with_index{|p,i| parts[i] = 0 if i >= significant_index}
|
38
|
+
parts.map.with_index { |p, i| parts[i] = 0 if i >= significant_index }
|
39
39
|
|
40
40
|
parts.join('.')
|
41
41
|
end
|
data/lib/napa.rb
CHANGED
@@ -6,19 +6,19 @@ require 'octokit'
|
|
6
6
|
require 'grape'
|
7
7
|
|
8
8
|
# require internal files
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
13
|
-
require
|
14
|
-
require
|
15
|
-
require
|
16
|
-
require
|
17
|
-
require
|
9
|
+
require 'napa/version'
|
10
|
+
require 'napa/logger/logger'
|
11
|
+
require 'napa/logger/log_transaction'
|
12
|
+
require 'napa/identity'
|
13
|
+
require 'napa/middleware/logger'
|
14
|
+
require 'napa/middleware/app_monitor'
|
15
|
+
require 'napa/activerecord'
|
16
|
+
require 'napa/grape_api'
|
17
|
+
require 'generators/scaffold'
|
18
18
|
|
19
19
|
# load rake tasks if Rake installed
|
20
20
|
if defined?(Rake)
|
21
|
-
|
21
|
+
load 'tasks/git.rake'
|
22
22
|
load 'tasks/deploy.rake'
|
23
23
|
load 'tasks/routes.rake'
|
24
24
|
load 'tasks/db.rake'
|
@@ -27,7 +27,7 @@ end
|
|
27
27
|
module Napa
|
28
28
|
class << self
|
29
29
|
def env
|
30
|
-
@_env ||= ActiveSupport::StringInquirer.new(ENV[
|
30
|
+
@_env ||= ActiveSupport::StringInquirer.new(ENV['RACK_ENV'] || 'development')
|
31
31
|
end
|
32
32
|
|
33
33
|
def env=(environment)
|
data/lib/tasks/db.rake
CHANGED
@@ -1,87 +1,89 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
unless defined?(Rails)
|
2
|
+
task :environment do
|
3
|
+
require 'erb'
|
4
|
+
require './app'
|
4
5
|
|
5
|
-
|
6
|
-
end
|
7
|
-
|
8
|
-
namespace :db do
|
9
|
-
desc "Migrate the database through scripts in db/migrate. Target specific version with VERSION=x"
|
10
|
-
task :migrate => :environment do
|
11
|
-
ActiveRecord::Migrator.migrate('db/migrate', ENV["VERSION"] ? ENV["VERSION"].to_i : nil )
|
12
|
-
Rake::Task["db:schema:dump"].invoke
|
6
|
+
raise "ActiveRecord Not Found" unless Module.const_defined?(:ActiveRecord)
|
13
7
|
end
|
14
8
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
end
|
9
|
+
namespace :db do
|
10
|
+
desc "Migrate the database through scripts in db/migrate. Target specific version with VERSION=x"
|
11
|
+
task :migrate => :environment do
|
12
|
+
ActiveRecord::Migrator.migrate('db/migrate', ENV["VERSION"] ? ENV["VERSION"].to_i : nil )
|
13
|
+
Rake::Task["db:schema:dump"].invoke unless Napa.env.production?
|
14
|
+
end
|
22
15
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
16
|
+
desc "Create the database"
|
17
|
+
task :create => :environment do
|
18
|
+
db = YAML.load(ERB.new(File.read('./config/database.yml')).result)[Napa.env]
|
19
|
+
adapter = db.merge({'database'=> 'mysql'})
|
20
|
+
ActiveRecord::Base.establish_connection(adapter)
|
21
|
+
ActiveRecord::Base.connection.create_database(db.fetch('database'))
|
22
|
+
end
|
30
23
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
24
|
+
desc "Delete the database"
|
25
|
+
task :drop => :environment do
|
26
|
+
db = YAML.load(ERB.new(File.read('./config/database.yml')).result)[Napa.env]
|
27
|
+
adapter = db.merge({'database'=> 'mysql'})
|
28
|
+
ActiveRecord::Base.establish_connection(adapter)
|
29
|
+
ActiveRecord::Base.connection.drop_database(db.fetch('database'))
|
30
|
+
end
|
37
31
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
# Find migration name from env
|
44
|
-
migration_name = ENV['NAME'].strip.chomp
|
45
|
-
|
46
|
-
# Define migrations path (needed later)
|
47
|
-
migrations_path = './db/migrate'
|
48
|
-
|
49
|
-
# Find the highest existing migration version or set to 1
|
50
|
-
if (existing_migrations = Dir[File.join(migrations_path, '*.rb')]).length > 0
|
51
|
-
version = File.basename(existing_migrations.sort.reverse.first)[/^(\d+)_/,1].to_i + 1
|
52
|
-
else
|
53
|
-
version = 1
|
54
|
-
end
|
55
|
-
|
56
|
-
# Use the migration template to fill the body of the migration
|
57
|
-
migration_content = Napa::ActiveRecord.migration_template(migration_name.camelize)
|
58
|
-
|
59
|
-
# Generate migration filename
|
60
|
-
migration_filename = "#{"%03d" % version}_#{migration_name}.rb"
|
61
|
-
|
62
|
-
# Write the migration
|
63
|
-
File.open(File.join(migrations_path, migration_filename), "w+") do |migration|
|
64
|
-
migration.puts migration_content
|
65
|
-
end
|
66
|
-
|
67
|
-
# Done!
|
68
|
-
puts "Successfully created migration #{migration_filename}"
|
32
|
+
desc "Create the test database"
|
33
|
+
task :reset => :environment do
|
34
|
+
Rake::Task["db:drop"].invoke
|
35
|
+
Rake::Task["db:create"].invoke
|
36
|
+
Rake::Task["db:schema:load"].invoke
|
69
37
|
end
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
38
|
+
|
39
|
+
namespace :generate do
|
40
|
+
desc "Generate a migration with given name. Specify migration name with NAME=my_migration_name"
|
41
|
+
task :migration => :environment do
|
42
|
+
raise "Please specify desired migration name with NAME=my_migration_name" unless ENV['NAME']
|
43
|
+
|
44
|
+
# Find migration name from env
|
45
|
+
migration_name = ENV['NAME'].strip.chomp
|
46
|
+
|
47
|
+
# Define migrations path (needed later)
|
48
|
+
migrations_path = './db/migrate'
|
49
|
+
|
50
|
+
# Find the highest existing migration version or set to 1
|
51
|
+
if (existing_migrations = Dir[File.join(migrations_path, '*.rb')]).length > 0
|
52
|
+
version = File.basename(existing_migrations.sort.reverse.first)[/^(\d+)_/,1].to_i + 1
|
53
|
+
else
|
54
|
+
version = 1
|
55
|
+
end
|
56
|
+
|
57
|
+
# Use the migration template to fill the body of the migration
|
58
|
+
migration_content = Napa::ActiveRecord.migration_template(migration_name.camelize)
|
59
|
+
|
60
|
+
# Generate migration filename
|
61
|
+
migration_filename = "#{"%03d" % version}_#{migration_name}.rb"
|
62
|
+
|
63
|
+
# Write the migration
|
64
|
+
File.open(File.join(migrations_path, migration_filename), "w+") do |migration|
|
65
|
+
migration.puts migration_content
|
66
|
+
end
|
67
|
+
|
68
|
+
# Done!
|
69
|
+
puts "Successfully created migration #{migration_filename}"
|
78
70
|
end
|
79
71
|
end
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
72
|
+
|
73
|
+
namespace :schema do
|
74
|
+
desc "Create a db/schema.rb file that can be portably used against any DB supported by AR"
|
75
|
+
task :dump => :environment do
|
76
|
+
require 'active_record/schema_dumper'
|
77
|
+
File.open(ENV['SCHEMA'] || "db/schema.rb", "w") do |file|
|
78
|
+
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
desc "Load a schema.rb file into the database"
|
83
|
+
task :load => :environment do
|
84
|
+
file = ENV['SCHEMA'] || "db/schema.rb"
|
85
|
+
load(file)
|
86
|
+
end
|
85
87
|
end
|
86
88
|
end
|
87
|
-
end
|
89
|
+
end
|
data/napa.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |gem|
|
|
20
20
|
gem.add_dependency 'logging'
|
21
21
|
gem.add_dependency 'dotenv'
|
22
22
|
gem.add_dependency 'octokit', '~> 1.25'
|
23
|
-
gem.add_dependency 'virtus'
|
23
|
+
gem.add_dependency 'virtus'
|
24
24
|
gem.add_dependency 'grape'
|
25
25
|
gem.add_dependency 'grape-swagger'
|
26
26
|
gem.add_dependency 'unicorn'
|
@@ -28,4 +28,5 @@ Gem::Specification.new do |gem|
|
|
28
28
|
gem.add_development_dependency "rspec"
|
29
29
|
gem.add_development_dependency "pry"
|
30
30
|
gem.add_development_dependency "git"
|
31
|
+
gem.add_development_dependency "rubocop"
|
31
32
|
end
|
data/spec/identity_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
require 'napa/identity'
|
3
3
|
|
4
4
|
describe Napa::Identity do
|
5
|
-
context
|
5
|
+
context '#name' do
|
6
6
|
it "returns 'api-service' if no ENV['SERVICE_NAME'] is set" do
|
7
7
|
ENV['SERVICE_NAME'] = nil
|
8
8
|
Napa::Identity.name.should == 'api-service'
|
@@ -11,40 +11,40 @@ describe Napa::Identity do
|
|
11
11
|
it "returns the ENV['SERVICE_NAME'] when specified" do
|
12
12
|
ENV['SERVICE_NAME'] = nil
|
13
13
|
ENV['SERVICE_NAME'] = 'my-service'
|
14
|
-
Napa::Identity.name.should
|
14
|
+
Napa::Identity.name.should eq('my-service')
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
context
|
19
|
-
it
|
20
|
-
Napa::Identity.should_receive(:`).with(
|
21
|
-
Napa::Identity.hostname.should
|
18
|
+
context '#hostname' do
|
19
|
+
it 'returns the value of the hostname system call and doesn\'t make a second system call' do
|
20
|
+
Napa::Identity.should_receive(:`).with('hostname').and_return('system-hostname')
|
21
|
+
Napa::Identity.hostname.should eq('system-hostname')
|
22
22
|
|
23
|
-
Napa::Identity.should_not_receive(:`).with(
|
24
|
-
Napa::Identity.hostname.should
|
23
|
+
Napa::Identity.should_not_receive(:`).with('hostname')
|
24
|
+
Napa::Identity.hostname.should eq('system-hostname')
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
context
|
29
|
-
it
|
30
|
-
Napa::Identity.should_receive(:`).with(
|
31
|
-
Napa::Identity.revision.should
|
28
|
+
context '#revision' do
|
29
|
+
it 'returns the value of the \'git rev-parse HEAD\' system call and doesn\'t make a second system call' do
|
30
|
+
Napa::Identity.should_receive(:`).with('git rev-parse HEAD').and_return('12345')
|
31
|
+
Napa::Identity.revision.should eq('12345')
|
32
32
|
|
33
|
-
Napa::Identity.should_not_receive(:`).with(
|
34
|
-
Napa::Identity.revision.should
|
33
|
+
Napa::Identity.should_not_receive(:`).with('git rev-parse HEAD')
|
34
|
+
Napa::Identity.revision.should eq('12345')
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
context
|
39
|
-
it
|
38
|
+
context '#pid' do
|
39
|
+
it 'returns the process ID value' do
|
40
40
|
Process.stub(:pid).and_return(112233)
|
41
|
-
Napa::Identity.pid.should
|
41
|
+
Napa::Identity.pid.should be(112233)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
context
|
46
|
-
it
|
45
|
+
context '#platform_revision' do
|
46
|
+
it 'returns the current version of the platform gem' do
|
47
47
|
Napa::Identity.platform_revision.should == Napa::VERSION
|
48
48
|
end
|
49
49
|
end
|
50
|
-
end
|
50
|
+
end
|
@@ -6,29 +6,29 @@ describe Napa::LogTransaction do
|
|
6
6
|
Napa::LogTransaction.clear
|
7
7
|
end
|
8
8
|
|
9
|
-
context
|
10
|
-
it
|
9
|
+
context '#id' do
|
10
|
+
it 'returns the current transaction id if it has been set' do
|
11
11
|
id = SecureRandom.hex(10)
|
12
12
|
Thread.current[:napa_tid] = id
|
13
13
|
Napa::LogTransaction.id.should == id
|
14
14
|
end
|
15
15
|
|
16
|
-
it
|
16
|
+
it 'sets and returns a new id if the transaction id hasn\'t been set' do
|
17
17
|
Napa::LogTransaction.id.should_not be_nil
|
18
18
|
end
|
19
19
|
|
20
|
-
it
|
20
|
+
it 'allows the id to be overridden by a setter' do
|
21
21
|
Napa::LogTransaction.id.should_not be_nil
|
22
22
|
Napa::LogTransaction.id = 'foo'
|
23
23
|
Napa::LogTransaction.id.should == 'foo'
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
context
|
28
|
-
it
|
27
|
+
context '#clear' do
|
28
|
+
it 'sets the id to nil' do
|
29
29
|
Napa::LogTransaction.id.should_not be_nil
|
30
30
|
Napa::LogTransaction.clear
|
31
31
|
Thread.current[:napa_tid].should be_nil
|
32
32
|
end
|
33
33
|
end
|
34
|
-
end
|
34
|
+
end
|
data/spec/version_spec.rb
CHANGED
@@ -2,39 +2,39 @@ require 'spec_helper'
|
|
2
2
|
require 'napa/version'
|
3
3
|
|
4
4
|
describe Napa::Version do
|
5
|
-
context
|
6
|
-
it
|
7
|
-
stub_const(
|
8
|
-
Napa::Version.next_major.should ==
|
5
|
+
context '#major_bump' do
|
6
|
+
it 'should set the major revision value, and the rest should be 0' do
|
7
|
+
stub_const('Napa::VERSION', '1.2.3')
|
8
|
+
Napa::Version.next_major.should == '2.0.0'
|
9
9
|
end
|
10
10
|
|
11
|
-
it
|
12
|
-
stub_const(
|
13
|
-
Napa::Version.next_major.should ==
|
11
|
+
it 'should set the major revision value, and the rest should be 0' do
|
12
|
+
stub_const('Napa::VERSION', '5.0.0')
|
13
|
+
Napa::Version.next_major.should == '6.0.0'
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
context
|
18
|
-
it
|
19
|
-
stub_const(
|
20
|
-
Napa::Version.next_minor.should ==
|
17
|
+
context '#minor_bump' do
|
18
|
+
it 'should set the minor revision value, leaving the major value unchanged and the patch value to 0' do
|
19
|
+
stub_const('Napa::VERSION', '1.2.3')
|
20
|
+
Napa::Version.next_minor.should == '1.3.0'
|
21
21
|
end
|
22
22
|
|
23
|
-
it
|
24
|
-
stub_const(
|
25
|
-
Napa::Version.next_minor.should ==
|
23
|
+
it 'should set the minor revision value, leaving the major value unchanged and the patch value to 0' do
|
24
|
+
stub_const('Napa::VERSION', '0.5.0')
|
25
|
+
Napa::Version.next_minor.should == '0.6.0'
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
context
|
30
|
-
it
|
31
|
-
stub_const(
|
32
|
-
Napa::Version.next_patch.should ==
|
29
|
+
context 'patch_bump' do
|
30
|
+
it 'should set the patch revision value, leaving the major and minor values unchanged' do
|
31
|
+
stub_const('Napa::VERSION', '1.2.3')
|
32
|
+
Napa::Version.next_patch.should == '1.2.4'
|
33
33
|
end
|
34
34
|
|
35
|
-
it
|
36
|
-
stub_const(
|
37
|
-
Napa::Version.next_patch.should ==
|
35
|
+
it 'should set the patch revision value, leaving the major and minor values unchanged' do
|
36
|
+
stub_const('Napa::VERSION', '5.5.5')
|
37
|
+
Napa::Version.next_patch.should == '5.5.6'
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-11-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -80,17 +80,17 @@ dependencies:
|
|
80
80
|
requirement: !ruby/object:Gem::Requirement
|
81
81
|
none: false
|
82
82
|
requirements:
|
83
|
-
- - '
|
83
|
+
- - ! '>='
|
84
84
|
- !ruby/object:Gem::Version
|
85
|
-
version: 0
|
85
|
+
version: '0'
|
86
86
|
type: :runtime
|
87
87
|
prerelease: false
|
88
88
|
version_requirements: !ruby/object:Gem::Requirement
|
89
89
|
none: false
|
90
90
|
requirements:
|
91
|
-
- - '
|
91
|
+
- - ! '>='
|
92
92
|
- !ruby/object:Gem::Version
|
93
|
-
version: 0
|
93
|
+
version: '0'
|
94
94
|
- !ruby/object:Gem::Dependency
|
95
95
|
name: grape
|
96
96
|
requirement: !ruby/object:Gem::Requirement
|
@@ -187,6 +187,22 @@ dependencies:
|
|
187
187
|
- - ! '>='
|
188
188
|
- !ruby/object:Gem::Version
|
189
189
|
version: '0'
|
190
|
+
- !ruby/object:Gem::Dependency
|
191
|
+
name: rubocop
|
192
|
+
requirement: !ruby/object:Gem::Requirement
|
193
|
+
none: false
|
194
|
+
requirements:
|
195
|
+
- - ! '>='
|
196
|
+
- !ruby/object:Gem::Version
|
197
|
+
version: '0'
|
198
|
+
type: :development
|
199
|
+
prerelease: false
|
200
|
+
version_requirements: !ruby/object:Gem::Requirement
|
201
|
+
none: false
|
202
|
+
requirements:
|
203
|
+
- - ! '>='
|
204
|
+
- !ruby/object:Gem::Version
|
205
|
+
version: '0'
|
190
206
|
description: A simple framework for building APIs with Grape
|
191
207
|
email:
|
192
208
|
- darby@bellycard.com
|
@@ -196,6 +212,7 @@ extensions: []
|
|
196
212
|
extra_rdoc_files: []
|
197
213
|
files:
|
198
214
|
- .gitignore
|
215
|
+
- .rubocop.yml
|
199
216
|
- Gemfile
|
200
217
|
- LICENSE
|
201
218
|
- README.md
|
@@ -205,6 +222,7 @@ files:
|
|
205
222
|
- lib/generators/templates/scaffold/.env
|
206
223
|
- lib/generators/templates/scaffold/.env.test
|
207
224
|
- lib/generators/templates/scaffold/.gitignore.tpl
|
225
|
+
- lib/generators/templates/scaffold/.rubocop.yml
|
208
226
|
- lib/generators/templates/scaffold/Gemfile
|
209
227
|
- lib/generators/templates/scaffold/README.md
|
210
228
|
- lib/generators/templates/scaffold/Rakefile
|
@@ -252,7 +270,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
252
270
|
version: '0'
|
253
271
|
segments:
|
254
272
|
- 0
|
255
|
-
hash: -
|
273
|
+
hash: -3815573023004026351
|
256
274
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
257
275
|
none: false
|
258
276
|
requirements:
|
@@ -261,7 +279,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
261
279
|
version: '0'
|
262
280
|
segments:
|
263
281
|
- 0
|
264
|
-
hash: -
|
282
|
+
hash: -3815573023004026351
|
265
283
|
requirements: []
|
266
284
|
rubyforge_project:
|
267
285
|
rubygems_version: 1.8.25
|