json_voorhees 0.5.5 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b042ee66e3328f4870f3e78b768dcb2c1438bb73
4
- data.tar.gz: 1009ea01dae0b8aaae0faa233321357d00715a26
3
+ metadata.gz: e2c926864334abb5b22eb0fc430e9055a048dffc
4
+ data.tar.gz: 3813492073e69ea5b0b3db2c032c58dda4c42a18
5
5
  SHA512:
6
- metadata.gz: 0fbdd8f41b9d344eeb731bf8117aba9da21cb2fc991d5f4e682798af12b6a13f4a6b7905d54a05456dae7c6c865d7e7c52033a24c0205a6a960f9c26bc57d6f6
7
- data.tar.gz: 476bdab6ef62ee34e16dbd436933b871b4e8ef48e4e89e6a9363c438c616d7fb17d3ac39ff93d5ae7e4f7ae5937b8dc3d84dc0f7734816d04c0592295a4f3eaa
6
+ metadata.gz: 579cf7928420d787ecd5a9faaa7eaabb9b51b7e87b41bec0edb153ded265d96eebf4703dc5ba8912db88edcc09383559d0005228d76509b574e1f1b792bfbfc6
7
+ data.tar.gz: dcfb1a56bd048626ef630a5bee36013924d7442b753fcfc3acf0aef983d76e93992cfa149ca7669d5b3a81270bf014a158b57e4a85efe407a9b362f77dfa0fdd
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # JsonVoorhees 0.5.1
1
+ # JsonVoorhees 1.0.0
2
2
 
3
3
  ## Introduction
4
4
 
@@ -14,7 +14,7 @@ To install, put this in your main_app and run bundle install.
14
14
 
15
15
  ```bash
16
16
  gem "json_voorhees"
17
- ```
17
+ ```
18
18
  To setup your application use the command below. It takes options that allow you
19
19
  to do things like skip active_admin, skip a generic admin page, skip arcadex, and even
20
20
  skip a user class. The default runs with active_admin, a user class and arcadex.
@@ -22,22 +22,17 @@ skip a user class. The default runs with active_admin, a user class and arcadex.
22
22
  ```bash
23
23
  rails g json_voorhees:setup_app
24
24
  ```
25
- Go to the engines folder and create an engine like so.
26
25
 
27
- ```bash
28
- rails plugin new [engine name] --mountable
29
- cd [engine name]
30
- ```
31
- Add the gem to your gemspec and execute the following command
26
+ Now when you want to create an engine run the below command from the main app.
27
+ It takes care of mounting the engine, setting up the controllers, routes and gemspecs.
32
28
 
33
29
  ```bash
34
- s.add_development_dependency "json_voorhees"
35
- rails g json_voorhees:setup_engine [engine name]
30
+ rails g json_voorhees:create_engine [engine name]
36
31
  ```
37
- Make sure the engine is mounted in your app and it's in the main apps gemfile.
38
- Go to the main_app and run this scaffold to create your resource. It runs on
39
- top of rails scaffold and in the process creates the api counterpart. You have
40
- the option of skipping the normal rails scaffold.
32
+
33
+ Now we can create resources, run the below command from the main_app. Specs will be created
34
+ and the routes for that resource are setup.
35
+
41
36
  ```bash
42
37
  rails g json_voorhees:massive_scaffold [engine name] [resource name] [api_version] [scaffold parameters]
43
38
 
@@ -45,27 +40,17 @@ example
45
40
 
46
41
  rails g json_voorhees:massive_scaffold chat message 1 user_id:integer message:text
47
42
  ```
48
- Make sure the resource is in the correct scoping in the Engines routing file. Then
49
- copy over the engines migrations and migrate the main app. Check if everything is fine by
50
- running rspec from the main app.
51
43
 
52
44
  ## Project Flow
53
45
 
54
46
  1. Create main app
55
- 2. (in app) rails g json_voorhees:setup_app
56
- 3. Create engine (and add relative path to gemfile)
57
- 4. Mount engine
58
- 5. (in engine) rails g json_voorhees:setup_engine [engine name] and make sure rails is the same version
59
- 6. Add json_voorhees to the engines gemspec
60
- 7. (in app) rails g json_voorhees:massive_scaffod [engine name] [resource name] [api_version] [field:type field:type]
61
- 8. Fix the engines route file
62
- 9. Copy migrations to main app and run db migrations in main app
63
- 10. (in app) Run rspec to check for errors
64
-
65
- Steps 1 through 2 are only done once. You need to run massive_scaffold for each
66
- resource.
47
+ 2. (in main_app root) rails g json_voorhees:setup_app
48
+ 3. (in main_app root) rails g json_voorhees:create_engine [engine name]
49
+ 4. (in main_app root) rails g json_voorhees:massive_scaffold [engine name] [resource name] [api_version] [field:type field:type]
50
+ 5. (in main_app root) Copy migrations to main app and run db migrations in main app like so. "rake railties:install:migrations && rake db:migrate RAILS_ENV=development"
51
+ 6. (in main_app root) Run "rspec" to check for errors
67
52
 
68
- I usually set the app up, and then design the database. I make a list of all the models I need, then separate them into engines. Then I run 20 or so massive scaffolds using "&&". The result is a functioning backend that only needs the model relationships wired together. The default tests get you pretty far.
53
+ I usually set the app up, and then design the database. I make a list of all the models I need, then separate them into engines. Then I run 20 or so massive scaffolds using "&&". The result is a modular functioning backend that only needs the model relationships wired together. The default tests get you pretty far.
69
54
 
70
55
  ## Individual Generator Use
71
56
 
@@ -85,6 +70,7 @@ the gem and the options. They each have a multitude of arguments and options.
85
70
  10. rails g json_voorhees:massive_scaffold
86
71
  11. rails g json_voorhees:setup_app
87
72
  12. rails g json_voorhees:setup_engine
73
+ 13. rails g json_voorhees:create_engine
88
74
 
89
75
  ## Versioning
90
76
 
@@ -95,9 +81,7 @@ else resides in engines for good modularity.
95
81
 
96
82
  ## Recent Additions
97
83
 
98
- If the api has routes that can be accessed without a logged in user, skip
99
- the authenticate_user filter and call set_hash before the method. Now current_user
100
- will return the current user or nil and the application will not render a 401.
84
+ Create the create_engine generator and made hooking the engine up to the main_app painless.
101
85
 
102
86
  ## Reminder
103
87
 
@@ -113,13 +97,12 @@ If active admin is used (it is by default) the admin section username is admin a
113
97
 
114
98
  ## To Do
115
99
 
116
- 1. Figure out a better way to test this thing
117
- 2. Use option for namespaced engine or no engine
118
- 3. Maybe give an option to include pagination?
119
- 4. Option for websockets and paperclip?
120
- 5. Make the non defaults easier to user
121
- 6. Use Devise as the default user and admin user? This will make it easier for users to reset their password as this is already setup.
122
- 7. Git clone arcadex, type_validator and defcon to make it easier for users to customize?
123
- 8. Move the people engine into it's own gem?
124
- 9. Create a whenever task to destroy expired tokens.
125
- 10. Fix the breadcrumbs link in ActiveAdmin.
100
+ 1. Maybe give an option to include pagination?
101
+ 2. Option for websockets and paperclip?
102
+ 3. Make the non defaults easier to user
103
+ 4. Use Devise as the default user and admin user? This will make it easier for users to reset their password as this is already setup.
104
+ 5. Git clone arcadex, type_validator and defcon to make it easier for users to customize?
105
+ 6. Move the people engine into it's own gem?
106
+ 7. Create a whenever task to destroy expired tokens.
107
+ 8. Fix the breadcrumbs link in ActiveAdmin.
108
+ 9. Add a mailgun and support for forgotten passwords
@@ -10,6 +10,8 @@ RSpec.describe ::<%= module_camel %>::V<%= api_version %>::<%= resource_camel %>
10
10
  FactoryGirl.create_list(:<%= module_snake %>_<%= resource_singular %>_<%= api_version %>, 10)
11
11
  get 'api/<%= api_version %>/<%= resource_plural %>'
12
12
  expect(response.status).to eq(200) #ok
13
+ expect(::<%= module_camel %>::V<%= api_version %>::<%= resource_camel %>.count).to eq(10)
14
+ expect(json["<%= resource_plural %>"].length).to eq(10)
13
15
  end
14
16
  end
15
17
  end
@@ -13,6 +13,8 @@ RSpec.describe ::<%= module_camel %>::V<%= api_version %>::<%= resource_camel %>
13
13
  FactoryGirl.create_list(:<%= module_snake %>_<%= resource_singular %>_<%= api_version %>, 10)
14
14
  get 'api/<%= api_version %>/<%= resource_plural %>', nil, @header
15
15
  expect(response.status).to eq(200) #ok
16
+ expect(::<%= module_camel %>::V<%= api_version %>::<%= resource_camel %>.count).to eq(10)
17
+ expect(json["<%= resource_plural %>"].length).to eq(10)
16
18
  end
17
19
  end
18
20
  end
@@ -65,7 +65,7 @@ module People
65
65
 
66
66
  # POST /api/1/users/authenticate
67
67
  def authenticate
68
- if authenticate_password
68
+ if user_authenticate_password
69
69
  return
70
70
  end
71
71
  render json: {}
@@ -84,7 +84,7 @@ module People
84
84
 
85
85
  # PATCH/PUT /api/1/users/1
86
86
  def update
87
- if authenticate_password
87
+ if user_authenticate_password
88
88
  return
89
89
  end
90
90
  if @user.update(user_params)
@@ -97,8 +97,8 @@ module People
97
97
  private
98
98
  # Use callbacks to share common setup or constraints between actions.
99
99
 
100
- def authenticate_password
101
- if !@user.authenticate(params[:user][:password])
100
+ def user_authenticate_password
101
+ if authenticate_password
102
102
  render :json => {errors: "Email and/or Password is incorrect"}, status: :unauthorized
103
103
  return true
104
104
  end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate create_engine Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,45 @@
1
+ module JsonVoorhees
2
+ class CreateEngineGenerator < Rails::Generators::Base
3
+ source_root File.expand_path('../templates', __FILE__)
4
+ argument :module_name, :type => :string
5
+
6
+ def sprint
7
+ inside "" do
8
+ run "rails plugin new engines/#{module_snake} --mountable"
9
+ end
10
+ inside "engines/#{module_snake}" do
11
+ add_dependency
12
+ run "rails g json_voorhees:setup_engine #{module_snake}"
13
+ end
14
+ inside "config" do
15
+ mount
16
+ end
17
+ inside "" do
18
+ gem "#{module_snake}", :path => "engines/#{module_snake}"
19
+ run "bundle install"
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def mount
26
+ gsub_file "routes.rb", "root to: \"app_index#app\"\n", "root to: \"app_index#app\"\n mount #{module_camel}::Engine, at: '/'\n"
27
+ end
28
+
29
+ def add_dependency
30
+ inject_into_file "#{module_snake}.gemspec", after: "s.add_development_dependency \"sqlite3\"\n" do <<-'RUBY'
31
+ s.add_development_dependency "json_voorhees"
32
+ RUBY
33
+ end
34
+ end
35
+
36
+ def module_camel
37
+ module_name.camelize
38
+ end
39
+
40
+ def module_snake
41
+ module_name.underscore.downcase
42
+ end
43
+
44
+ end
45
+ end
@@ -27,6 +27,7 @@ module JsonVoorhees
27
27
  else
28
28
  run "rails g json_voorhees:engine_scaffold #{module_name} #{resource_name} #{api_version} #{attributes.join(" ")} --skip-arcadex"
29
29
  end
30
+ correct_routes
30
31
  end
31
32
  if options.arcadex?
32
33
  run "rails g json_voorhees:app_scaffold #{module_name} #{resource_name} #{api_version} #{attributes.join(" ")}"
@@ -37,10 +38,16 @@ module JsonVoorhees
37
38
  #run "rails generate active_admin:resource #{module_name.underscore.downcase}::#{resource_name.singularize.underscore.downcase}"
38
39
  make_custom_active_admin
39
40
  end
41
+
40
42
  end
41
43
 
42
44
  private
43
45
 
46
+ def correct_routes
47
+ gsub_file 'config/routes.rb', "resources :#{resource_plural}", "#resources :#{resource_plural}"
48
+ gsub_file 'config/routes.rb', "scope '1' do\n", "scope '1' do\nresources :#{resource_plural}, controller: \'api/v1/#{resource_plural}\'\n"
49
+ end
50
+
44
51
  def make_custom_active_admin
45
52
  template "active_admin_register.rb.erb", "app/admin/#{module_name.underscore}_#{resource_singular}.rb"
46
53
  end
@@ -17,6 +17,17 @@ class Api::V1::ApiController < ::ActionController::API
17
17
  end
18
18
  end
19
19
 
20
+ def authenticate_password
21
+ if current_user.nil?
22
+ return true
23
+ end
24
+ if !current_user.authenticate(params[:user][:password])
25
+ return true
26
+ else
27
+ return false
28
+ end
29
+ end
30
+
20
31
  def set_hash
21
32
  #["current_user","current_token"] Make this true to check for email also
22
33
  @instance_hash = ::Arcadex::Authentication.full_authentication(params,request,false)
@@ -1,3 +1,3 @@
1
1
  module JsonVoorhees
2
- VERSION = "0.5.5"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -0,0 +1,16 @@
1
+ require 'test_helper'
2
+ require 'generators/create_engine/create_engine_generator'
3
+
4
+ module JsonVoorhees
5
+ class CreateEngineGeneratorTest < Rails::Generators::TestCase
6
+ tests CreateEngineGenerator
7
+ destination Rails.root.join('tmp/generators')
8
+ setup :prepare_destination
9
+
10
+ # test "generator runs without errors" do
11
+ # assert_nothing_raised do
12
+ # run_generator ["arguments"]
13
+ # end
14
+ # end
15
+ end
16
+ end
@@ -0,0 +1,18 @@
1
+ Go to the test directory and run this script. Make sure rspec tests are green.
2
+
3
+ cp fresh_copy/test_app . &&
4
+ cd test_app &&
5
+ rails g json_voorhees:setup_app &&
6
+ rails g json_voorhees:create_engine ocean &&
7
+ rails g json_voorhees:massive_scaffold ocean atlantic 1 cold:boolean hot:boolean &&
8
+ rake railties:install:migrations &&
9
+ rake db:migrate RAILS_ENV=development &&
10
+ rake db:migrate RAILS_ENV=test &&
11
+ rake db:migrate RAILS_ENV=production &&
12
+ rspec
13
+
14
+ Remember to delete the copied test_app before commiting!
15
+ From the test/test_app directory
16
+
17
+ cd .. &&
18
+ rm -rf test_app
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_voorhees
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.5
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cleophus Robinson
@@ -91,6 +91,8 @@ files:
91
91
  - lib/generators/json_voorhees/app_make_user/templates/user/user_serializer.rb
92
92
  - lib/generators/json_voorhees/app_scaffold/USAGE
93
93
  - lib/generators/json_voorhees/app_scaffold/app_scaffold_generator.rb
94
+ - lib/generators/json_voorhees/create_engine/USAGE
95
+ - lib/generators/json_voorhees/create_engine/create_engine_generator.rb
94
96
  - lib/generators/json_voorhees/engine_create_controller/USAGE
95
97
  - lib/generators/json_voorhees/engine_create_controller/engine_create_controller_generator.rb
96
98
  - lib/generators/json_voorhees/engine_create_controller/templates/controller_template.rb.erb
@@ -200,12 +202,14 @@ files:
200
202
  - test/lib/generators/json_voorhees/app_make_admin_generator_test.rb
201
203
  - test/lib/generators/json_voorhees/app_make_user_generator_test.rb
202
204
  - test/lib/generators/json_voorhees/app_scaffold_generator_test.rb
205
+ - test/lib/generators/json_voorhees/create_engine_generator_test.rb
203
206
  - test/lib/generators/json_voorhees/engine_create_model_generator_test.rb
204
207
  - test/lib/generators/json_voorhees/engine_make_model_generator_test.rb
205
208
  - test/lib/generators/json_voorhees/engine_scaffold_generator_test.rb
206
209
  - test/lib/generators/json_voorhees/engine_serializer_generator_test.rb
207
210
  - test/lib/generators/json_voorhees/massive_scaffold_generator_test.rb
208
211
  - test/test_helper.rb
212
+ - test/test_script.txt
209
213
  homepage: https://github.com/cleor41/json_voorhees
210
214
  licenses:
211
215
  - MIT
@@ -238,6 +242,7 @@ test_files:
238
242
  - test/lib/generators/json_voorhees/app_scaffold_generator_test.rb
239
243
  - test/lib/generators/json_voorhees/engine_scaffold_generator_test.rb
240
244
  - test/lib/generators/json_voorhees/massive_scaffold_generator_test.rb
245
+ - test/lib/generators/json_voorhees/create_engine_generator_test.rb
241
246
  - test/lib/generators/json_voorhees/app_make_admin_generator_test.rb
242
247
  - test/lib/generators/json_voorhees/engine_serializer_generator_test.rb
243
248
  - test/json_voorhees_test.rb
@@ -276,6 +281,7 @@ test_files:
276
281
  - test/dummy/app/assets/stylesheets/application.css
277
282
  - test/dummy/log/development.log
278
283
  - test/test_helper.rb
284
+ - test/test_script.txt
279
285
  - test/fresh_copy/test_app/Gemfile.lock
280
286
  - test/fresh_copy/test_app/bin/rake
281
287
  - test/fresh_copy/test_app/bin/rails