napa 0.1.26 → 0.1.28

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4ad5d6d9cbf7390f1b3d421b3fd4d58e121d97af
4
- data.tar.gz: a0dc5a4d8ecc8e1664395cebbeb6d64626bc81e5
3
+ metadata.gz: 921842df68ddfd43053accc0281962d797225ced
4
+ data.tar.gz: 892d34f1952b7e73dba7dff8f485d2930d6b39ed
5
5
  SHA512:
6
- metadata.gz: 879a62d886ee27f396f994504d1f421d1f7a6b9f2aadc7b5b7ddf74e2a3e57c9ba8e40caf17954ce67f6deb44abbdbd9848eaf06d3c8002a0705d5571003cd4a
7
- data.tar.gz: 5de5e10a32e948e07d238cd687846a2cfe4383630da6b522f80435ab9b7ab5d9d56bce8c439398df678eaffb4fc0eaf7fde859001a9a41884d46a0cb874462c9
6
+ metadata.gz: 3b9c94ad04f33374ffc54ec532ef07de33e915f03c5353e50d0ad43e823ff22d0dd731c2b8fd1917faf747945e68a43cc4f73fb6b401b75d37de3ea89bae4c46
7
+ data.tar.gz: 651d69ad11fa10824d704f0c87b268f9e4a5c997b7408f483e04472f8c54d0a8844d9789d9b6a27317d5a1a191559ae721ae8f1cfcc4e0786024253acbde1c02
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  [![Build Status](https://travis-ci.org/bellycard/napa.png?branch=master)](https://travis-ci.org/bellycard/napa)
2
+ [![Dependency Status](https://gemnasium.com/bellycard/napa.png)](https://gemnasium.com/bellycard/napa)
2
3
 
3
4
  # Napa
4
5
 
@@ -195,4 +196,4 @@ The Health Check middleware will add an endpoint at `/health` that will return s
195
196
 
196
197
  ## Todo/Feature Requests
197
198
 
198
- * Add specs for logger and logging middleware
199
+ * Add specs for logger and logging middleware
data/bin/napa CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  require 'napa/cli'
4
4
 
5
- Napa::CLI.start(ARGV)
5
+ Napa::CLI::Base.start(ARGV)
data/lib/napa.rb CHANGED
@@ -4,6 +4,7 @@ require 'dotenv'
4
4
  require 'logging'
5
5
  require 'octokit'
6
6
  require 'grape'
7
+ require 'grape-entity'
7
8
  require 'json'
8
9
 
9
10
  # require internal files
@@ -17,12 +18,12 @@ require 'napa/stats'
17
18
  require 'napa/active_record_extensions/filter_by_hash'
18
19
  require 'napa/grape_extensions/error_formatter'
19
20
  require 'napa/grape_extensions/error_presenter'
21
+ require 'napa/grape_extensions/entity'
20
22
  require 'napa/grape_extenders'
21
23
  require 'napa/middleware/logger'
22
24
  require 'napa/middleware/app_monitor'
23
25
  require 'napa/middleware/authentication'
24
26
  require 'napa/middleware/request_stats'
25
- require 'napa/activerecord'
26
27
  require 'napa/authentication'
27
28
 
28
29
  # load rake tasks if Rake installed
data/lib/napa/cli.rb CHANGED
@@ -1,16 +1,45 @@
1
1
  require 'thor'
2
2
  require 'napa/generators'
3
+ require 'napa/version'
3
4
 
4
5
  module Napa
5
- class CLI < Thor
6
- desc "version", "Shows the Napa version number"
7
- def version
8
- say Napa::VERSION
6
+ class CLI
7
+ class Generate < Thor
8
+ register(
9
+ Generators::ApiGenerator,
10
+ 'api',
11
+ 'api <api_name>',
12
+ 'Create a Grape API, Model and Entity'
13
+ )
14
+
15
+ register(
16
+ Generators::MigrationGenerator,
17
+ 'migration',
18
+ 'migration <migration_name>',
19
+ 'Create a Database Migration'
20
+ )
9
21
  end
22
+ end
23
+
24
+ class CLI
25
+ class Base < Thor
26
+ desc "version", "Shows the Napa version number"
27
+ def version
28
+ say Napa::VERSION
29
+ end
10
30
 
11
- register(Generators::ScaffoldGenerator, 'new', 'new <app_name> [app_path]',
12
- 'Create a scaffold for a new Napa service')
13
- register(Generators::ApiGenerator, 'generate:api', 'generate:api <api_name>',
14
- 'Create a Grape API, Model and Entity')
31
+ register(
32
+ Generators::ScaffoldGenerator,
33
+ 'new',
34
+ 'new <app_name> [app_path]',
35
+ 'Create a scaffold for a new Napa service'
36
+ )
37
+
38
+ desc "generate api <api_name>", "Create a Grape API, Model and Entity"
39
+ subcommand "generate api", Napa::CLI::Generate
40
+
41
+ desc "generate migration <migration_name>", "Create a Database Migration"
42
+ subcommand "generate", Napa::CLI::Generate
43
+ end
15
44
  end
16
45
  end
@@ -1,2 +1,3 @@
1
1
  require 'napa/generators/scaffold_generator'
2
2
  require 'napa/generators/api_generator'
3
+ require 'napa/generators/migration_generator'
@@ -5,7 +5,6 @@ module Napa
5
5
  module Generators
6
6
  class ApiGenerator < Thor::Group
7
7
  include Thor::Actions
8
- namespace :generate
9
8
  argument :name
10
9
 
11
10
  def name_underscore
@@ -0,0 +1,26 @@
1
+ require 'thor'
2
+ require 'active_support/all'
3
+
4
+ module Napa
5
+ module Generators
6
+ class MigrationGenerator < Thor::Group
7
+ include Thor::Actions
8
+ argument :migration_name
9
+
10
+ def version
11
+ Time.now.utc.to_s.gsub(':','').gsub('-','').gsub('UTC','').gsub(' ','')
12
+ end
13
+
14
+ def migration_filename
15
+ "#{version}_#{migration_name}"
16
+ end
17
+
18
+ def migration
19
+ self.class.source_root "#{File.dirname(__FILE__)}/templates/migration"
20
+ say 'Generating migration...'
21
+ directory '.', './db/migrate'
22
+ say 'Done!', :green
23
+ end
24
+ end
25
+ end
26
+ end
@@ -34,7 +34,7 @@ class <%= name.classify.pluralize %>Api < Grape::API
34
34
  put do
35
35
  # fetch <%= name.underscore %> record and update attributes. exceptions caught in app.rb
36
36
  <%= name.underscore %> = <%= name.classify %>.find(params[:id])
37
- <%= name.underscore %>.update_attributes!(declared(params, include_missing: false).select { |param, value| value.present? })
37
+ <%= name.underscore %>.update_attributes!(declared(params, include_missing: false)
38
38
  present <%= name.underscore %>, with: <%= name.classify %>Entity
39
39
  end
40
40
  end
@@ -1,4 +1,4 @@
1
- class <%= name.classify %>Entity < Grape::Entity
1
+ class <%= name.classify %>Entity < Napa::Entity
2
2
  root :data, :data
3
3
  expose :id, proc: lambda { |o, opts| o.id.to_s }, documentation:
4
4
  { type: 'String', description: 'ID' }
@@ -0,0 +1,7 @@
1
+ class <%= migration_name.classify %> < ActiveRecord::Migration
2
+ def change
3
+ # create_table :foo do |t|
4
+ # t.string :name, :null => false
5
+ # end
6
+ end
7
+ end
@@ -9,7 +9,7 @@ module Napa
9
9
  rack_response(Napa::JsonError.new(:record_not_found, 'record not found').to_json, 404)
10
10
  end
11
11
  modified_class.rescue_from ::ActiveRecord::RecordInvalid do |e|
12
- rack_response(Napa::JsonError.new(:record_invalid, 'record not found').to_json, 500)
12
+ rack_response(Napa::JsonError.new(:record_invalid, 'record not found').to_json, 400)
13
13
  end
14
14
  end
15
15
  end
@@ -0,0 +1,11 @@
1
+ module Napa
2
+ class Entity < Grape::Entity
3
+ format_with :to_s do |val|
4
+ val.to_s
5
+ end
6
+
7
+ def object_type
8
+ object.class.name.underscore
9
+ end
10
+ end
11
+ end
data/lib/napa/identity.rb CHANGED
@@ -7,7 +7,7 @@ module Napa
7
7
  revision: revision,
8
8
  pid: pid,
9
9
  parent_pid: parent_pid,
10
- napa_revision: napa_revision
10
+ platform: platform
11
11
  }
12
12
  end
13
13
 
@@ -31,7 +31,14 @@ module Napa
31
31
  @ppid ||= Process.ppid
32
32
  end
33
33
 
34
- def self.napa_revision
34
+ def self.platform
35
+ {
36
+ version: platform_revision,
37
+ name: "Napa"
38
+ }
39
+ end
40
+
41
+ def self.platform_revision
35
42
  Napa::VERSION
36
43
  end
37
44
  end
@@ -6,7 +6,7 @@ module Napa
6
6
  end
7
7
 
8
8
  def call(env)
9
- if env['REQUEST_PATH'] == '/health'
9
+ if ["/health", "/health.json"].include? env['REQUEST_PATH']
10
10
  [200, { 'Content-type' => 'application/json' }, [Napa::Identity.health.to_json]]
11
11
  else
12
12
  @app.call(env)
data/lib/napa/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Napa
2
- VERSION = '0.1.26'
2
+ VERSION = '0.1.28'
3
3
 
4
4
  class Version
5
5
  class << self
data/lib/tasks/db.rake CHANGED
@@ -36,36 +36,6 @@ unless defined?(Rails)
36
36
  Rake::Task["db:schema:load"].invoke
37
37
  end
38
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
- # timestamp the migration
51
- version = Time.now.utc.to_s.gsub(':','').gsub('-','').gsub('UTC','').gsub(' ','')
52
-
53
- # Use the migration template to fill the body of the migration
54
- migration_content = Napa::ActiveRecord.migration_template(migration_name.camelize)
55
-
56
- # Generate migration filename
57
- migration_filename = "#{version}_#{migration_name}.rb"
58
-
59
- # Write the migration
60
- File.open(File.join(migrations_path, migration_filename), "w+") do |migration|
61
- migration.puts migration_content
62
- end
63
-
64
- # Done!
65
- puts "Successfully created migration #{migration_filename}"
66
- end
67
- end
68
-
69
39
  namespace :schema do
70
40
  desc "Create a db/schema.rb file that can be portably used against any DB supported by AR"
71
41
  task :dump => :environment do
@@ -42,9 +42,9 @@ describe Napa::Identity do
42
42
  end
43
43
  end
44
44
 
45
- context '#napa_revision' do
45
+ context '#platform_revision' do
46
46
  it 'returns the current version of the platform gem' do
47
- Napa::Identity.napa_revision.should == Napa::VERSION
47
+ Napa::Identity.platform_revision.should == Napa::VERSION
48
48
  end
49
49
  end
50
50
  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.26
4
+ version: 0.1.28
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-28 00:00:00.000000000 Z
11
+ date: 2014-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -252,15 +252,16 @@ files:
252
252
  - bin/napa
253
253
  - lib/napa.rb
254
254
  - lib/napa/active_record_extensions/filter_by_hash.rb
255
- - lib/napa/activerecord.rb
256
255
  - lib/napa/authentication.rb
257
256
  - lib/napa/cli.rb
258
257
  - lib/napa/generators.rb
259
258
  - lib/napa/generators/api_generator.rb
259
+ - lib/napa/generators/migration_generator.rb
260
260
  - lib/napa/generators/scaffold_generator.rb
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/migration/%migration_filename%.rb.tt
264
265
  - lib/napa/generators/templates/scaffold/.env.test.tt
265
266
  - lib/napa/generators/templates/scaffold/.env.tt
266
267
  - lib/napa/generators/templates/scaffold/.gitignore.tt
@@ -281,6 +282,7 @@ files:
281
282
  - lib/napa/generators/templates/scaffold/spec/factories/.gitkeep
282
283
  - lib/napa/generators/templates/scaffold/spec/spec_helper.rb
283
284
  - lib/napa/grape_extenders.rb
285
+ - lib/napa/grape_extensions/entity.rb
284
286
  - lib/napa/grape_extensions/error_formatter.rb
285
287
  - lib/napa/grape_extensions/error_presenter.rb
286
288
  - lib/napa/identity.rb
@@ -1,21 +0,0 @@
1
- module Napa
2
- class ActiveRecord
3
- class << self
4
- def migration_template(migration_class)
5
- <<-MIGRATION
6
- class #{migration_class} < ActiveRecord::Migration
7
- def up
8
- # create_table :foo do |t|
9
- # t.string :name, :null => false
10
- # end
11
- end
12
-
13
- def down
14
- # drop_table :foo
15
- end
16
- end
17
- MIGRATION
18
- end
19
- end
20
- end
21
- end