napa 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +14 -0
  3. data/README.md +41 -8
  4. data/Rakefile +1 -0
  5. data/docs/grape_entity_to_roar.md +110 -0
  6. data/docs/quickstart.md +29 -3
  7. data/lib/napa/active_record_extensions/filter_by_hash.rb +1 -0
  8. data/lib/napa/active_record_extensions/seeder.rb +14 -0
  9. data/lib/napa/cli.rb +28 -2
  10. data/lib/napa/deploy.rb +98 -0
  11. data/lib/napa/deprecations/active_support_behavior.rb +8 -0
  12. data/lib/napa/deprecations/application_api.rb +9 -0
  13. data/lib/napa/deprecations/grape_entity.rb +5 -0
  14. data/lib/napa/deprecations/napa_setup.rb +38 -0
  15. data/lib/napa/deprecations.rb +13 -0
  16. data/lib/napa/gem_dependency.rb +37 -0
  17. data/lib/napa/generators/migration_generator.rb +199 -2
  18. data/lib/napa/generators/readme_generator.rb +47 -0
  19. data/lib/napa/generators/templates/create_table_migration/%migration_filename%.rb.tt +19 -0
  20. data/lib/napa/generators/templates/migration/%migration_filename%.rb.tt +36 -1
  21. data/lib/napa/generators/templates/readme/README.md.tt +55 -0
  22. data/lib/napa/generators/templates/readme/spec/docs/readme_spec.rb +7 -0
  23. data/lib/napa/generators/templates/scaffold/.env.test.tt +3 -0
  24. data/lib/napa/generators/templates/scaffold/.env.tt +3 -0
  25. data/lib/napa/generators/templates/scaffold/.gitignore.tt +1 -0
  26. data/lib/napa/generators/templates/scaffold/Rakefile +2 -1
  27. data/lib/napa/generators/templates/scaffold/app.rb +1 -1
  28. data/lib/napa/generators/templates/scaffold/config.ru.tt +3 -2
  29. data/lib/napa/generators/templates/scaffold/log/{.gitkeep → .keep} +0 -0
  30. data/lib/napa/generators.rb +1 -0
  31. data/lib/napa/middleware/logger.rb +1 -1
  32. data/lib/napa/middleware/request_stats.rb +0 -2
  33. data/lib/napa/output_formatters/entity.rb +4 -0
  34. data/lib/napa/rspec_extensions/response_helpers.rb +29 -0
  35. data/lib/napa/setup.rb +20 -0
  36. data/lib/napa/stats_d_timer.rb +1 -1
  37. data/lib/napa/version.rb +1 -1
  38. data/lib/napa.rb +19 -1
  39. data/lib/tasks/db.rake +7 -0
  40. data/lib/tasks/deploy.rake +2 -4
  41. data/lib/tasks/routes.rake +4 -3
  42. data/napa.gemspec +2 -1
  43. data/spec/active_record_extensions/filter_by_hash_spec.rb +5 -3
  44. data/spec/active_record_extensions/seeder_spec.rb +13 -0
  45. data/spec/authentication_spec.rb +3 -3
  46. data/spec/deprecations/application_api_spec.rb +19 -0
  47. data/spec/deprecations/entity_spec.rb +9 -0
  48. data/spec/deprecations/filter_by_hash_spec.rb +9 -0
  49. data/spec/deprecations/napa_setup_spec.rb +52 -0
  50. data/spec/generators/api_generator_spec.rb +1 -1
  51. data/spec/generators/migration_generator_spec.rb +86 -8
  52. data/spec/generators/readme_generator_spec.rb +35 -0
  53. data/spec/grape_extensions/error_formatter_spec.rb +6 -6
  54. data/spec/identity_spec.rb +13 -13
  55. data/spec/json_error_spec.rb +3 -3
  56. data/spec/logger/log_transaction_spec.rb +6 -6
  57. data/spec/middleware/authentication_spec.rb +8 -8
  58. data/spec/middleware/database_stats_spec.rb +8 -8
  59. data/spec/middleware/request_stats_spec.rb +2 -11
  60. data/spec/spec_helper.rb +11 -2
  61. data/spec/stats_d_timer_spec.rb +23 -0
  62. data/spec/stats_spec.rb +2 -2
  63. data/spec/version_spec.rb +6 -6
  64. metadata +35 -9
  65. data/lib/tasks/git.rake +0 -53
@@ -5,10 +5,15 @@ module Napa
5
5
  module Generators
6
6
  class MigrationGenerator < Thor::Group
7
7
  include Thor::Actions
8
+ # largely ported over, with a few differences, from
9
+ # https://github.com/rails/rails/blob/76883f92374c6395f13c16628e1d87d40b6d2399/activerecord/lib/rails/generators/active_record/migration/migration_generator.rb
8
10
  argument :migration_name
11
+ argument :attributes, type: :array, default: []
12
+
13
+ attr_reader :migration_action, :join_tables, :table_name
9
14
 
10
15
  def version
11
- Time.now.utc.to_s.gsub(':','').gsub('-','').gsub('UTC','').gsub(' ','')
16
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
12
17
  end
13
18
 
14
19
  def migration_filename
@@ -19,12 +24,204 @@ module Napa
19
24
  './db/migrate'
20
25
  end
21
26
 
27
+ def parse_attributes!
28
+ self.attributes = (attributes || []).map do |attr|
29
+ GeneratedAttribute.parse(attr)
30
+ end
31
+ end
32
+
33
+ def set_local_assigns!
34
+ @migration_template = "migration"
35
+ filename = migration_name.underscore
36
+ case filename
37
+ when /^(add|remove)_.*_(?:to|from)_(.*)/
38
+ @migration_action = $1
39
+ @table_name = $2.pluralize
40
+ when /join_table/
41
+ if attributes.length == 2
42
+ @migration_action = 'join'
43
+ @join_tables = attributes.map(&:plural_name)
44
+
45
+ set_index_names
46
+ end
47
+ when /^create_(.+)/
48
+ @table_name = $1.pluralize
49
+ @migration_template = "create_table_migration"
50
+ end
51
+ end
52
+
22
53
  def migration
23
- self.class.source_root "#{File.dirname(__FILE__)}/templates/migration"
54
+ self.class.source_root "#{File.dirname(__FILE__)}/templates/#{@migration_template}"
24
55
  say 'Generating migration...'
25
56
  directory '.', output_directory
26
57
  say 'Done!', :green
27
58
  end
59
+
60
+ private
61
+ def attributes_with_index
62
+ attributes.select { |a| !a.reference? && a.has_index? }
63
+ end
64
+
65
+ def set_index_names
66
+ attributes.each_with_index do |attr, i|
67
+ attr.index_name = [attr, attributes[i - 1]].map{ |a| index_name_for(a) }
68
+ end
69
+ end
70
+
71
+ def index_name_for(attribute)
72
+ if attribute.foreign_key?
73
+ attribute.name
74
+ else
75
+ attribute.name.singularize.foreign_key
76
+ end.to_sym
77
+ end
78
+ end
79
+
80
+ # directly ported from
81
+ # https://github.com/rails/rails/blob/76883f92374c6395f13c16628e1d87d40b6d2399/railties/lib/rails/generators/generated_attribute.rb
82
+ class GeneratedAttribute # :nodoc:
83
+ INDEX_OPTIONS = %w(index uniq)
84
+ UNIQ_INDEX_OPTIONS = %w(uniq)
85
+
86
+ attr_accessor :name, :type
87
+ attr_reader :attr_options
88
+ attr_writer :index_name
89
+
90
+ class << self
91
+ def parse(column_definition)
92
+ name, type, has_index = column_definition.split(':')
93
+
94
+ # if user provided "name:index" instead of "name:string:index"
95
+ # type should be set blank so GeneratedAttribute's constructor
96
+ # could set it to :string
97
+ has_index, type = type, nil if INDEX_OPTIONS.include?(type)
98
+
99
+ type, attr_options = *parse_type_and_options(type)
100
+ type = type.to_sym if type
101
+
102
+ if type && reference?(type)
103
+ references_index = UNIQ_INDEX_OPTIONS.include?(has_index) ? { unique: true } : true
104
+ attr_options[:index] = references_index
105
+ end
106
+
107
+ new(name, type, has_index, attr_options)
108
+ end
109
+
110
+ def reference?(type)
111
+ [:references, :belongs_to].include? type
112
+ end
113
+
114
+ private
115
+
116
+ # parse possible attribute options like :limit for string/text/binary/integer, :precision/:scale for decimals or :polymorphic for references/belongs_to
117
+ # when declaring options curly brackets should be used
118
+ def parse_type_and_options(type)
119
+ case type
120
+ when /(string|text|binary|integer)\{(\d+)\}/
121
+ return $1, limit: $2.to_i
122
+ when /decimal\{(\d+)[,.-](\d+)\}/
123
+ return :decimal, precision: $1.to_i, scale: $2.to_i
124
+ when /(references|belongs_to)\{polymorphic\}/
125
+ return $1, polymorphic: true
126
+ else
127
+ return type, {}
128
+ end
129
+ end
130
+ end
131
+
132
+ def initialize(name, type=nil, index_type=false, attr_options={})
133
+ @name = name
134
+ @type = type || :string
135
+ @has_index = INDEX_OPTIONS.include?(index_type)
136
+ @has_uniq_index = UNIQ_INDEX_OPTIONS.include?(index_type)
137
+ @attr_options = attr_options
138
+ end
139
+
140
+ def field_type
141
+ @field_type ||= case type
142
+ when :integer then :number_field
143
+ when :float, :decimal then :text_field
144
+ when :time then :time_select
145
+ when :datetime, :timestamp then :datetime_select
146
+ when :date then :date_select
147
+ when :text then :text_area
148
+ when :boolean then :check_box
149
+ else
150
+ :text_field
151
+ end
152
+ end
153
+
154
+ def default
155
+ @default ||= case type
156
+ when :integer then 1
157
+ when :float then 1.5
158
+ when :decimal then "9.99"
159
+ when :datetime, :timestamp, :time then Time.now.to_s(:db)
160
+ when :date then Date.today.to_s(:db)
161
+ when :string then name == "type" ? "" : "MyString"
162
+ when :text then "MyText"
163
+ when :boolean then false
164
+ when :references, :belongs_to then nil
165
+ else
166
+ ""
167
+ end
168
+ end
169
+
170
+ def plural_name
171
+ name.sub(/_id$/, '').pluralize
172
+ end
173
+
174
+ def singular_name
175
+ name.sub(/_id$/, '').singularize
176
+ end
177
+
178
+ def human_name
179
+ name.humanize
180
+ end
181
+
182
+ def index_name
183
+ @index_name ||= if polymorphic?
184
+ %w(id type).map { |t| "#{name}_#{t}" }
185
+ else
186
+ column_name
187
+ end
188
+ end
189
+
190
+ def column_name
191
+ @column_name ||= reference? ? "#{name}_id" : name
192
+ end
193
+
194
+ def foreign_key?
195
+ !!(name =~ /_id$/)
196
+ end
197
+
198
+ def reference?
199
+ self.class.reference?(type)
200
+ end
201
+
202
+ def polymorphic?
203
+ self.attr_options.has_key?(:polymorphic)
204
+ end
205
+
206
+ def has_index?
207
+ @has_index
208
+ end
209
+
210
+ def has_uniq_index?
211
+ @has_uniq_index
212
+ end
213
+
214
+ def password_digest?
215
+ name == 'password' && type == :digest
216
+ end
217
+
218
+ def inject_options
219
+ "".tap { |s| @attr_options.each { |k,v| s << ", #{k}: #{v.inspect}" } }
220
+ end
221
+
222
+ def inject_index_options
223
+ has_uniq_index? ? ", unique: true" : ""
224
+ end
28
225
  end
29
226
  end
30
227
  end
@@ -0,0 +1,47 @@
1
+ require 'thor'
2
+ require 'active_support/all'
3
+ require 'napa/setup'
4
+ require 'napa/identity'
5
+ require 'dotenv'
6
+
7
+ module Napa
8
+ module Generators
9
+ class ReadmeGenerator < Thor::Group
10
+ include Thor::Actions
11
+
12
+ def load_environment
13
+ Napa.load_environment
14
+ end
15
+
16
+ def service_name
17
+ Napa::Identity.name
18
+ end
19
+
20
+ def routes
21
+ routes = ""
22
+
23
+ if defined? ApplicationApi
24
+ ApplicationApi.routes.each do |api|
25
+ method = api.route_method.ljust(10)
26
+ path = api.route_path.ljust(40)
27
+ description = api.route_description
28
+ routes += " #{method} #{path} # #{description}"
29
+ end
30
+ end
31
+
32
+ routes
33
+ end
34
+
35
+ def output_directory
36
+ '.'
37
+ end
38
+
39
+ def readme
40
+ self.class.source_root "#{File.dirname(__FILE__)}/templates/readme"
41
+ say 'Generating readme...'
42
+ directory '.', output_directory
43
+ say 'Done!', :green
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,19 @@
1
+ class <%= migration_name.camelize %> < ActiveRecord::Migration
2
+ def change
3
+ create_table :<%= table_name %> do |t|
4
+ <% attributes.each do |attribute| -%>
5
+ <% if attribute.password_digest? -%>
6
+ t.string :password_digest<%= attribute.inject_options %>
7
+ <% else -%>
8
+ t.<%= attribute.type %> :<%= attribute.name %><%= attribute.inject_options %>
9
+ <% end -%>
10
+ <% end -%>
11
+ <% if options[:timestamps] %>
12
+ t.timestamps
13
+ <% end -%>
14
+ end
15
+ <% attributes_with_index.each do |attribute| -%>
16
+ add_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %>
17
+ <% end -%>
18
+ end
19
+ end
@@ -1,4 +1,39 @@
1
1
  class <%= migration_name.camelize %> < ActiveRecord::Migration
2
+ <%- if migration_action == 'add' -%>
2
3
  def change
4
+ <% attributes.each do |attribute| -%>
5
+ <%- if attribute.reference? -%>
6
+ add_reference :<%= table_name %>, :<%= attribute.name %><%= attribute.inject_options %>
7
+ <%- else -%>
8
+ add_column :<%= table_name %>, :<%= attribute.name %>, :<%= attribute.type %><%= attribute.inject_options %>
9
+ <%- if attribute.has_index? -%>
10
+ add_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %>
11
+ <%- end -%>
12
+ <%- end -%>
13
+ <%- end -%>
3
14
  end
4
- end
15
+ <%- elsif migration_action == 'join' -%>
16
+ def change
17
+ create_join_table :<%= join_tables.first %>, :<%= join_tables.second %> do |t|
18
+ <%- attributes.each do |attribute| -%>
19
+ <%= '# ' unless attribute.has_index? -%>t.index <%= attribute.index_name %><%= attribute.inject_index_options %>
20
+ <%- end -%>
21
+ end
22
+ end
23
+ <%- else -%>
24
+ def change
25
+ <% attributes.each do |attribute| -%>
26
+ <%- if migration_action -%>
27
+ <%- if attribute.reference? -%>
28
+ remove_reference :<%= table_name %>, :<%= attribute.name %><%= attribute.inject_options %>
29
+ <%- else -%>
30
+ <%- if attribute.has_index? -%>
31
+ remove_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %>
32
+ <%- end -%>
33
+ remove_column :<%= table_name %>, :<%= attribute.name %>, :<%= attribute.type %><%= attribute.inject_options %>
34
+ <%- end -%>
35
+ <%- end -%>
36
+ <%- end -%>
37
+ end
38
+ <%- end -%>
39
+ end
@@ -0,0 +1,55 @@
1
+ # <%= service_name %>
2
+
3
+ :bow: Please put your auspicious [Travis status button](http://docs.travis-ci.com/user/status-images/) here :bow:
4
+
5
+ 1. [Overview](#overview)
6
+ 2. [How Does It Work](#how-does-it-work)
7
+ 3. [Endpoints](#endpoints)
8
+ 4. [Development](#development)
9
+ 5. [Extra Links](#extra-links)
10
+
11
+ ### Overview
12
+
13
+ :bow: Tell us about your wonderful service :bow:
14
+
15
+ In this section, please answer the questions, "What is this service?" or "What does this service do?"
16
+
17
+ ### How Does It Work
18
+
19
+ Ohhh tell us, how does it function? :bow: :bow:
20
+
21
+ Tell us about the __mechanics__ or __logic__ driving the service. Diagrams and pictures are :angel:
22
+
23
+ ### Endpoints
24
+
25
+ How must we interact with your great service? :bow:
26
+
27
+ Try typing `rake routes` into your console, and then paste that here.
28
+
29
+ If those endpoints need to be explained in more detail, please bless us with your wisdom.
30
+
31
+ ### Development
32
+
33
+ ```
34
+ bundle install
35
+
36
+ rake db:reset
37
+
38
+ rspec spec
39
+
40
+ rackup
41
+ ```
42
+
43
+ So wonderful, so informative! :bow:
44
+
45
+ What else do we need to know so that a new developer can start contributing __within 30 minutes__?
46
+
47
+ ### Extra Links
48
+
49
+ What a perfectly constructed service! We're so honored :bow:
50
+
51
+ If your service makes heavy use of other gems or API's, imbue us with that knowledge in the form of
52
+
53
+ - [Link to documentation]()
54
+ - [etc.]()
55
+ - [For information on how to create links in Markdown, please click here](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#links)
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'README' do
4
+ it 'has been filled out' do
5
+ pending 'Please fill out the sections that have a :bow:'
6
+ end
7
+ end
@@ -1,3 +1,6 @@
1
+ # Uncomment when using Napa::Middleware::Authentication
2
+ # HEADER_PASSWORD=''
3
+
1
4
  SERVICE_NAME=<%= app_name %>
2
5
  RACK_ENV=test
3
6
 
@@ -1,3 +1,6 @@
1
+ # Uncomment when using Napa::Middleware::Authentication
2
+ # HEADER_PASSWORD=''
3
+
1
4
  SERVICE_NAME=<%= app_name %>
2
5
 
3
6
  DATABASE_USER='<%= @database_user %>'
@@ -4,6 +4,7 @@
4
4
  .rspec
5
5
  .env
6
6
  !.env.test
7
+ !log/.keep
7
8
  log/*
8
9
  tmp/*
9
10
  coverage
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env rake
2
+ require 'napa/setup'
2
3
  require 'dotenv'
3
- Dotenv.load(ENV['RACK_ENV'] == 'test' ? '.env.test' : '.env')
4
+ Napa.load_environment
4
5
 
5
6
  require './app'
6
7
  require 'json'
@@ -6,7 +6,7 @@ Bundler.require(:default, Napa.env.to_sym)
6
6
  require 'napa'
7
7
 
8
8
  # load environment
9
- Dotenv.load(Napa.env.test? ? '.env.test' : '.env')
9
+ Napa.load_environment
10
10
 
11
11
  # autoload initalizers
12
12
  Dir['./config/initializers/**/*.rb'].map { |file| require file }
@@ -10,11 +10,12 @@ require './app'
10
10
  # end
11
11
  # end
12
12
  #
13
- # use Honeybadger::Rack
13
+ # use Honeybadger::Rack::ErrorNotifier
14
14
  # use Napa::Middleware::Logger
15
15
 
16
16
  use Napa::Middleware::AppMonitor
17
- use Napa::Middleware::Authentication
17
+ # Uncomment to require header passwords for all requestss
18
+ # use Napa::Middleware::Authentication
18
19
  use ActiveRecord::ConnectionAdapters::ConnectionManagement
19
20
 
20
21
  run ApplicationApi
@@ -1,3 +1,4 @@
1
1
  require 'napa/generators/scaffold_generator'
2
2
  require 'napa/generators/api_generator'
3
3
  require 'napa/generators/migration_generator'
4
+ require 'napa/generators/readme_generator'
@@ -7,7 +7,7 @@ module Napa
7
7
 
8
8
  def call(env)
9
9
  # log the request
10
- Napa::Logger.logger.debug format_request(env)
10
+ Napa::Logger.logger.info format_request(env)
11
11
 
12
12
  # process the request
13
13
  status, headers, body = @app.call(env)
@@ -31,9 +31,7 @@ module Napa
31
31
  path = normalize_path(request.path_info)
32
32
 
33
33
  # Emit stats to StatsD
34
- Napa::Stats.emitter.increment('request_count')
35
34
  Napa::Stats.emitter.timing('response_time', response_time)
36
- Napa::Stats.emitter.increment("path.#{Napa::Stats.path_to_key(request.request_method, path)}.request_count")
37
35
  Napa::Stats.emitter.timing("path.#{Napa::Stats.path_to_key(request.request_method, path)}.response_time", response_time)
38
36
 
39
37
  # Return the results
@@ -1,5 +1,9 @@
1
1
  module Napa
2
2
  class Entity < Grape::Entity
3
+ def self.inherited(subclass)
4
+ ActiveSupport::Deprecation.warn 'Use of Napa::Entity is discouraged, please transition your code to Roar representers - https://github.com/bellycard/napa/blob/master/docs/grape_entity_to_roar.md', caller
5
+ end
6
+
3
7
  format_with :to_s do |val|
4
8
  val.to_s
5
9
  end
@@ -12,6 +12,35 @@ module Napa
12
12
  def response_body
13
13
  last_response.body
14
14
  end
15
+
16
+ def result_count
17
+ parsed_response.data.count
18
+ end
19
+
20
+ def first_result
21
+ parsed_response.data.first
22
+ end
23
+
24
+ def result_with_id(id)
25
+ parsed_response.data.select { |r| r.id == id }.first
26
+ end
27
+
28
+ def expect_count_of(count)
29
+ expect(result_count).to eq(count)
30
+ end
31
+
32
+ def expect_only(object)
33
+ expect_count_of 1
34
+ expect(first_result.id).to eq(object.id)
35
+ end
36
+
37
+ def expect_to_have(object)
38
+ expect(!!result_with_id(object.id)).to be_truthy
39
+ end
40
+
41
+ def expect_to_not_have(object)
42
+ expect(!!result_with_id(object.id)).to be_falsy
43
+ end
15
44
  end
16
45
  end
17
46
  end
data/lib/napa/setup.rb CHANGED
@@ -5,6 +5,18 @@ require 'active_support'
5
5
 
6
6
  module Napa
7
7
  class << self
8
+ def load_environment
9
+ Dotenv.load(Napa.env.test? ? '.env.test' : '.env')
10
+ end
11
+
12
+ def skip_initialization
13
+ @_skip_initialization || false
14
+ end
15
+
16
+ def skip_initialization=(value)
17
+ @_skip_initialization = value if [TrueClass, FalseClass].include?(value.class)
18
+ end
19
+
8
20
  def env
9
21
  @_env ||= ActiveSupport::StringInquirer.new(ENV['RACK_ENV'] || 'development')
10
22
  end
@@ -12,5 +24,13 @@ module Napa
12
24
  def env=(environment)
13
25
  @_env = ActiveSupport::StringInquirer.new(environment)
14
26
  end
27
+
28
+ def cache
29
+ @_cache ||= ActiveSupport::Cache.lookup_store(:memory_store)
30
+ end
31
+
32
+ def cache=(store_option)
33
+ @_cache = ActiveSupport::Cache.lookup_store(store_option)
34
+ end
15
35
  end
16
36
  end
@@ -3,7 +3,7 @@ module Napa
3
3
  def report_time(timer_name)
4
4
  start_time = Time.now
5
5
  yield
6
- response_time = Time.now - start_time
6
+ response_time = (Time.now - start_time) * 1000 # statsd reports timers in milliseconds
7
7
  Napa::Stats.emitter.timing(timer_name, response_time)
8
8
  end
9
9
 
data/lib/napa/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Napa
2
- VERSION = '0.3.0'
2
+ VERSION = '0.4.0'
3
3
 
4
4
  class Version
5
5
  class << self
data/lib/napa.rb CHANGED
@@ -16,8 +16,10 @@ require 'napa/logger/parseable'
16
16
  require 'napa/identity'
17
17
  require 'napa/json_error'
18
18
  require 'napa/stats'
19
+ require 'napa/stats_d_timer'
19
20
  require 'napa/active_record_extensions/filter_by_hash'
20
21
  require 'napa/active_record_extensions/stats'
22
+ require 'napa/active_record_extensions/seeder'
21
23
  require 'napa/grape_extensions/error_formatter'
22
24
  require 'napa/grape_extensions/grape_helpers'
23
25
  require 'napa/output_formatters/entity'
@@ -31,10 +33,26 @@ require 'napa/middleware/request_stats'
31
33
  require 'napa/middleware/database_stats'
32
34
  require 'napa/authentication'
33
35
 
36
+ require 'napa/deprecations'
37
+ require 'napa/deploy'
38
+ require 'napa/gem_dependency'
39
+
34
40
  # load rake tasks if Rake installed
35
41
  if defined?(Rake)
36
- load 'tasks/git.rake'
37
42
  load 'tasks/deploy.rake'
38
43
  load 'tasks/routes.rake'
39
44
  load 'tasks/db.rake'
40
45
  end
46
+
47
+ module Napa
48
+ class << self
49
+ def initialize
50
+ unless Napa.skip_initialization
51
+ Napa::Logger.logger.info Napa::GemDependency.log_all if Napa.env.production?
52
+ Napa::Deprecations.initialization_checks
53
+ end
54
+ end
55
+ end
56
+ end
57
+
58
+ Napa.initialize
data/lib/tasks/db.rake CHANGED
@@ -72,5 +72,12 @@ unless defined?(Rails)
72
72
  load(file)
73
73
  end
74
74
  end
75
+
76
+ desc 'Load the seed data from db/seeds.rb'
77
+ task :seed => :environment do
78
+ ActiveRecord::Tasks::DatabaseTasks.seed_loader = Napa::ActiveRecordSeeder.new './db/seeds.rb'
79
+ ActiveRecord::Tasks::DatabaseTasks.load_seed
80
+ end
81
+
75
82
  end
76
83
  end
@@ -1,13 +1,11 @@
1
1
  namespace :deploy do
2
2
  desc "Deploy to production"
3
3
  task :production do
4
- Rake::Task["git:verify"].invoke
5
- Rake::Task["git:set_tag"].invoke
4
+ puts "\033[31mrake deploy:production is deprecated, please use 'napa deploy production'\033[0m"
6
5
  end
7
6
 
8
7
  desc "Deploy to staging"
9
8
  task :staging do
10
- Rake::Task["git:verify"].invoke
11
- Rake::Task["git:set_tag"].invoke("staging")
9
+ puts "\033[31mrake deploy:staging is deprecated, please use 'napa deploy staging'\033[0m"
12
10
  end
13
11
  end
@@ -2,9 +2,10 @@ unless defined?(Rails)
2
2
  desc "display all routes for Grape"
3
3
  task :routes do
4
4
  ApplicationApi.routes.each do |api|
5
- method = api.route_method.ljust(10)
6
- path = api.route_path
7
- puts " #{method} #{path}"
5
+ method = api.route_method.ljust(10)
6
+ path = api.route_path.ljust(40)
7
+ description = api.route_description
8
+ puts " #{method} #{path} # #{description}"
8
9
  end
9
10
  end
10
11
  end