json_voorhees 0.3.0 → 0.3.5

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: 188b8da5f4822765363d1bed45872c3e93f56c80
4
- data.tar.gz: 8b4bdd912df6949686114540c868e9e35152e635
3
+ metadata.gz: bcfe1caaeb6586f4e3e4b4295d4b28b29cd395d9
4
+ data.tar.gz: 94f373f7621a5e277f1a051429083df3dcf4a24b
5
5
  SHA512:
6
- metadata.gz: 26652b4904e24acb9106bf9d3ffdc279d508f22bd261ff1174e8cf2dfcf676e4876cfaba8ddfe327bee648226d60779b1093acca9986b8daf9cfe59fa2b650a4
7
- data.tar.gz: aefcbe4c6455204e40216c43bf0c079f06da6ea4e1c6a9129d9dbc4a675218c514b4332c4f8d8afe0f24d9ab893abb6b66ce9226f140cb47d8dce888ee81a6e0
6
+ metadata.gz: 07fe048f2bf236e5c8f52300aa18fc080d2b4d7f10ffef0bbb82875d3ac8bcab8c622bb17f02ab28be5356814f75b37ef5de995f6cb9786fb3f864674fa24733
7
+ data.tar.gz: 7ba4289ba29db5734968f5c680224069b558f716a927dfcab95cccb39e23a3021e65dd0a922cbafcbbb093dc83fae300be10a8c68b1a222b598503fdef750bca
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # JsonVoorhees
1
+ # JsonVoorhees 0.3.5
2
2
 
3
3
  ## Introduction
4
4
 
@@ -10,12 +10,14 @@ helps build the project if you follow the conventions.
10
10
 
11
11
  ## Scaffold Use
12
12
 
13
- To install, put this in your main_app
13
+ 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
- To setup your application use
18
+ To setup your application use the command below. It takes options that allow you
19
+ to do things like skip active_admin, skip a generic admin page, skip arcadex, and even
20
+ skip a user class. The default runs with active_admin, a user class and arcadex.
19
21
 
20
22
  ```bash
21
23
  rails g json_voorhees:setup_app
@@ -33,13 +35,15 @@ s.add_development_dependency "json_voorhees"
33
35
  rails g json_voorhees:setup_engine [engine name]
34
36
  ```
35
37
  Make sure the engine is mounted in your app and it's in the main apps gemfile.
36
- Go to the main_app and create your resources
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.
37
41
  ```bash
38
42
  rails g json_voorhees:massive_scaffold [engine name] [resource name] [api_version] [scaffold parameters]
39
43
  ```
40
- Make sure the resource is in the correct scoping in the Engines routing file.
41
- Make sure everything is setup correctly by running rspec from the main_app.
42
- The factory girl factory may not be setup correction depending on your passed type.
44
+ Make sure the resource is in the correct scoping in the Engines routing file. Then
45
+ copy over the engines migrations and migrate the main app. Check if everything is fine by
46
+ running rspec from the main app.
43
47
 
44
48
  ## Project Flow
45
49
 
@@ -54,79 +58,31 @@ The factory girl factory may not be setup correction depending on your passed ty
54
58
  9. Copy migrations to main app and run db migrations in main app
55
59
  10. (in app) Run rspec to check for errors
56
60
 
57
- ## Individual Generator Use
58
-
59
- To install, put this in your main_app
60
-
61
- ```bash
62
- gem "json_voorhees"
63
- ```
64
-
65
- To setup your application use
66
-
67
- ```bash
68
- rails g json_voorhees:setup_app
69
- ```
70
- It will install commonly used gems, enforce a layout for your app and even
71
- a user class if you want it.
72
-
73
- My APIs all use a series of engines hooked into the main_app. The main_app is
74
- the caretaker for things like specs and the admin page. It's also where the api_controller
75
- and application_controller reside. Their counterparts in an engine all inherit from
76
- one of these controllers. Since the engines need to be mounted into the route file,
77
- engines can version themselves and it helps to increment the project little by litter.
78
- This separation of concerns if done by logic can help break a project into smaller bitesized
79
- pieces which can then if need be go under their own version control and managed by different
80
- teams.
81
-
82
- Go to the engines folder and create an engine like so.
83
-
84
- ```bash
85
- rails plugin new [engine name] --mountable
86
- cd [engine name]
87
- ```
88
- Now add the gem to your gemspec like so and execute the following command
61
+ Steps 1 through 2 are only done once. You need to run massive_scaffold for each
62
+ resource.
89
63
 
90
- ```bash
91
- s.add_development_dependency "json_voorhees"
92
- rails g json_voorhees:setup_engine [engine name]
93
- ```
94
- After scaffolding out your resource, generate the necessary api controller
95
- and its serializer
96
-
97
- ```bash
98
- rails g json_voorhees:engine_scaffold [engine name] [resource name] [api_version] [field:type field:type]
99
-
100
- or
101
-
102
- rails g json_voorhees:engine_create_controller [engine name] [resource name] [api_version] [field:type field:type]
103
- rails g json_voorhees:engine_create_serializer [engine name] [resource name] [field:type field:type]
104
- ```
105
-
106
- Authorizations are all handled in a gem called authorization.
107
- Specs are also ran through RSpec and FactoryGirl, Go to the main_app and run
108
-
109
- ```bash
110
- rails g json_voorhees:app_scaffold [engine name] [resource name] [api_version] [field:type field:type]
111
-
112
- or
113
-
114
- rails g json_voorhees:app_make_authorizations [engine name] [resource name] [field:type field:type]
115
- rails g json_voorhees:app_make_tests [engine name] [resource name] [api_version] [field:type field:type]
116
- ```
117
-
118
- For every resource created, those 4 are ran in their respective locations.
119
-
120
- ## Notes
64
+ ## Individual Generator Use
121
65
 
122
- 1. After scaffolding and migrating, make sure to run rspec to make sure everything is setup correctly
123
- 2. For advanced use, check out the description of each generators options
66
+ If massive scaffold is too bulky for you, you have the option of running the
67
+ generators individually. Use rails g to see the generators that come with
68
+ the gem and the options. They each have a multitude of arguments and options.
69
+
70
+ 1. rails g json_voorhees:app_make_admin
71
+ 2. rails g json_voorhees:app_make_authorizations
72
+ 3. rails g json_voorhees:app_make_tests
73
+ 4. rails g json_voorhees:app_make_user
74
+ 5. rails g json_voorhees:app_scaffold
75
+ 6. rails g json_voorhees:engine_create_controller
76
+ 7. rails g json_voorhees:engine_create_model
77
+ 8. rails g json_voorhees:engine_create_serializer
78
+ 9. rails g json_voorhees:engine_scaffold
79
+ 10. rails g json_voorhees:massive_scaffold
80
+ 11. rails g json_voorhees:setup_app
81
+ 12. rails g json_voorhees:setup_engine
124
82
 
125
83
  ## To Do
126
84
 
127
85
  1. Figure out a better way to test this thing
128
86
  2. Use option for namespaced engine or no engine
129
- 3. Build on admin page
130
- 4. Maybe give an option to include pagination?
131
- 5. Option for websockets
132
- 6. Update README
87
+ 3. Maybe give an option to include pagination?
88
+ 4. Option for websockets and paperclip?
@@ -3,13 +3,59 @@ module JsonVoorhees
3
3
  source_root File.expand_path('../templates', __FILE__)
4
4
  class_option :arcadex, :type => :boolean, :default => true, :description => "Include arcadex gem and authentication in api_controller"
5
5
  class_option :user, :type => :boolean, :default => true, :description => "Create an admin page with user class"
6
+ class_option :active_admin, :type => :boolean, :default => true, :description => "Setup the active_admin gem, the gem needs to be already added"
6
7
 
7
8
  def sprint
8
- make_admin
9
+ if options.active_admin?
10
+ make_active_admin
11
+ else
12
+ make_admin
13
+ end
9
14
  end
10
15
 
11
16
  private
12
17
 
18
+ def make_active_admin
19
+ run "rails g active_admin:install --skip-users"
20
+ inject_into_file 'app/controllers/application_controller.rb', after: "protect_from_forgery with: :exception\n" do <<-'RUBY'
21
+
22
+ #This needs to be put inside a config file. but this is good for now
23
+ #This only requires the password for the admin section of the website
24
+ protected
25
+
26
+ def authenticate
27
+ authenticate_or_request_with_http_basic do |username, password|
28
+ username == "admin" && password == "password"
29
+ end
30
+ end
31
+
32
+ RUBY
33
+ end
34
+ find_and_replace_initializer
35
+ end
36
+
37
+ def find_and_replace_initializer
38
+ gsub_file 'config/initializers/active_admin.rb',
39
+ 'config.authentication_method = :authenticate_admin_user!',
40
+ '#config.authentication_method = :authenticate_admin_user!'
41
+ gsub_file 'config/initializers/active_admin.rb',
42
+ 'config.current_user_method = :current_admin_user',
43
+ '#config.current_user_method = :current_admin_user'
44
+ gsub_file 'config/initializers/active_admin.rb',
45
+ 'config.logout_link_path = :destroy_admin_user_session_path',
46
+ '#config.logout_link_path = :destroy_admin_user_session_path'
47
+ inject_into_file 'config/initializers/active_admin.rb', after: "ActiveAdmin.setup do |config|\n" do <<-'RUBY'
48
+
49
+ # http auth for admin area
50
+ config.before_filter :authenticate
51
+ config.authentication_method = false
52
+ config.current_user_method = false
53
+ config.allow_comments = false
54
+
55
+ RUBY
56
+ end
57
+ end
58
+
13
59
  def make_admin
14
60
  if options.user? && options.arcadex?
15
61
  #copy admin page with user engine
@@ -2,9 +2,13 @@ module JsonVoorhees
2
2
  class AppMakeUserGenerator < Rails::Generators::Base
3
3
  source_root File.expand_path('../templates', __FILE__)
4
4
  class_option :arcadex, :type => :boolean, :default => true, :description => "Include arcadex tokens"
5
-
5
+ class_option :active_admin, :type => :boolean, :default => true, :description => "Include admin scoping in routes file"
6
+
6
7
  def sprint
7
8
  people
9
+ if options.active_admin?
10
+ run "rails g active_admin:resource people::user"
11
+ end
8
12
  end
9
13
 
10
14
  private
@@ -22,7 +22,10 @@ module People
22
22
  if user.save
23
23
  #If the user is saved, return a token
24
24
  token = user.tokens[0]
25
- render :json => {user: user, token: token}
25
+ ::Arcadex::Create.set_token(token,360,request)
26
+ userHash = {id: user.id, username: user.username, email: user.email}
27
+ tokenHash = {auth_token: token.auth_token}
28
+ render :json => {user: userHash,token: tokenHash}
26
29
  else
27
30
  #Return an error if not saved
28
31
  render :json => {errors: user.errors}, status: :unprocessable_entity
@@ -36,7 +39,10 @@ module People
36
39
  user = ::People::V1::User.find_by(email: params[:email])
37
40
  if user && user.authenticate(params[:password])
38
41
  token = user.tokens.create
39
- render :json => {user: user, token: token}
42
+ ::Arcadex::Create.set_token(token,360,request)
43
+ userHash = {id: user.id, username: user.username, email: user.email}
44
+ tokenHash = {auth_token: token.auth_token}
45
+ render :json => {user: userHash,token: tokenHash}
40
46
  else
41
47
  render :json => {errors: "Email and/or Password is incorrect"}, status: :unauthorized
42
48
  end
@@ -2,9 +2,11 @@ People::Engine.routes.draw do
2
2
 
3
3
  root to: "users#index"
4
4
 
5
+ <% if !options.active_admin? %>
5
6
  scope 'admin' do
6
7
  resources :users
7
8
  end
9
+ <% end %>
8
10
 
9
11
  scope 'api' do
10
12
  scope '1' do
@@ -10,6 +10,7 @@ module JsonVoorhees
10
10
  class_option :request, :type => :boolean, :default => true, :description => "Create request stub tests"
11
11
  class_option :routing, :type => :boolean, :default => true, :description => "Create routing stub tests"
12
12
  class_option :arcadex, :type => :boolean, :default => true, :description => "Send requests with an arcadex header"
13
+ class_option :active_admin, :type => :boolean, :default => true, :description => "Generate the admin resource"
13
14
 
14
15
  def sprint
15
16
  inside "engines/#{module_name.underscore}" do
@@ -32,6 +33,9 @@ module JsonVoorhees
32
33
  else
33
34
  run "rails g json_voorhees:app_scaffold --skip-arcadex #{module_name} #{resource_name} #{api_version} #{attributes.join(" ")}"
34
35
  end
36
+ if options.active_admin?
37
+ run "rails generate active_admin:resource #{module_name.underscore.downcase}::#{resource_name.underscore.downcase}"
38
+ end
35
39
  end
36
40
 
37
41
  private
@@ -1,3 +1,5 @@
1
+ require 'bundler'
2
+
1
3
  module JsonVoorhees
2
4
  class SetupAppGenerator < Rails::Generators::Base
3
5
  source_root File.expand_path('../templates', __FILE__)
@@ -5,6 +7,7 @@ module JsonVoorhees
5
7
  class_option :user, :type => :boolean, :default => true, :description => "Create an engine for the user class"
6
8
  class_option :test, :type => :boolean, :default => false, :description => "Set true if running tests to skip things like bundle update and git"
7
9
  class_option :admin, :type => :boolean, :default => true, :description => "Create an admin page"
10
+ class_option :active_admin, :type => :boolean, :default => true, :description => "Setup the active_admin gem"
8
11
 
9
12
  def sprint
10
13
  create_file_structure
@@ -17,39 +20,65 @@ module JsonVoorhees
17
20
  make_admin
18
21
  end
19
22
  if options.user?
20
- make_user
23
+ make_user
21
24
  end
25
+ run "rake railties:install:migrations"
26
+ run_db_migrations
22
27
  routes
23
28
  make_controllers
29
+ if options.arcadex? && options.active_admin?
30
+ run "rails generate active_admin:resource arcadex::token"
31
+ end
24
32
  run_git
25
33
  end
26
34
 
27
35
  private
28
36
 
29
37
  def make_admin
30
- if !options.arcadex? && !options.user?
31
- run "rails g json_voorhees:app_make_admin --skip-arcadex --skip-user"
32
- end
33
- if !options.arcadex? && options.user?
34
- run "rails g json_voorhees:app_make_admin --skip-arcadex"
35
- end
36
- if !options.user? && options.arcadex?
37
- run "rails g json_voorhees:app_make_admin --skip-user"
38
- end
39
- if options.user? && options.arcadex?
40
- run "rails g json_voorhees:app_make_admin"
38
+ if !options.active_admin?
39
+ if !options.arcadex? && !options.user?
40
+ run "rails g json_voorhees:app_make_admin --skip-arcadex --skip-user --skip-active_admin"
41
+ end
42
+ if !options.arcadex? && options.user?
43
+ run "rails g json_voorhees:app_make_admin --skip-arcadex --skip-active_admin"
44
+ end
45
+ if !options.user? && options.arcadex?
46
+ run "rails g json_voorhees:app_make_admin --skip-user --skip-active_admin"
47
+ end
48
+ if options.user? && options.arcadex?
49
+ run "rails g json_voorhees:app_make_admin --skip-active_admin"
50
+ end
51
+ else
52
+ if !options.arcadex? && !options.user?
53
+ run "rails g json_voorhees:app_make_admin --skip-arcadex --skip-user"
54
+ end
55
+ if !options.arcadex? && options.user?
56
+ run "rails g json_voorhees:app_make_admin --skip-arcadex"
57
+ end
58
+ if !options.user? && options.arcadex?
59
+ run "rails g json_voorhees:app_make_admin --skip-user"
60
+ end
61
+ if options.user? && options.arcadex?
62
+ run "rails g json_voorhees:app_make_admin"
63
+ end
41
64
  end
42
65
  end
43
66
 
44
67
  def make_user
45
- if !options.arcadex?
46
- run "rails g json_voorhees:app_make_user --skip-arcadex"
68
+ if !options.active_admin?
69
+ if !options.arcadex?
70
+ run "rails g json_voorhees:app_make_user --skip-arcadex --skip-active_admin"
71
+ else
72
+ run "rails g json_voorhees:app_make_user --skip-active_admin"
73
+ end
47
74
  else
48
- run "rails g json_voorhees:app_make_user"
75
+ if !options.arcadex?
76
+ run "rails g json_voorhees:app_make_user --skip-arcadex"
77
+ else
78
+ run "rails g json_voorhees:app_make_user"
79
+ end
49
80
  end
50
81
  run_bundle
51
- run "rake railties:install:migrations"
52
- run_db_migrations
53
82
  end
54
83
 
55
84
  def include_middleware
@@ -64,16 +93,19 @@ module JsonVoorhees
64
93
 
65
94
  def routes
66
95
  route "root to: \"app_index#app\""
67
- route "get \'admin\' => \'main#admin\', as: \"admin\" #admin_path"
96
+ if !options.active_admin? && options.admin?
97
+ route "get \'admin\' => \'main#admin\', as: \"admin\" #admin_path"
98
+ end
68
99
  end
69
100
 
70
101
  def make_controllers
71
102
  generate "controller", "app_index app"
72
103
  run "rm -f app/controllers/app_index_controller.rb"
73
104
  copy_file "app_index_controller.rb", "app/controllers/app_index_controller.rb"
74
- generate "controller", "main admin"
75
- #Copy admin views
76
- run "rm -f spec/controllers/main_controller_spec.rb"
105
+ if !options.active_admin? && options.admin?
106
+ generate "controller", "main admin"
107
+ run "rm -f spec/controllers/main_controller_spec.rb"
108
+ end
77
109
  #Copy the views over
78
110
  copy_file "views/app", "app/views/app_index/app.html.erb"
79
111
  copy_file "views/app_index", "app/views/layouts/app_index.html.erb"
@@ -108,15 +140,16 @@ module JsonVoorhees
108
140
  #gem 'sqlite3', '~> 1.3.9' # dev & test database
109
141
  gem 'figaro', '~> 0.7.0' # env variables
110
142
  gem 'annotate', ">=2.6.0"
111
- gem "better_errors", '~> 1.1.0'
112
- gem "binding_of_caller", "~> 0.7.1" # needed by better_errors or variable inspection
113
143
  gem 'rspec-rails', '~> 3.0.0'
114
144
  gem 'byebug', '~> 3.2.0'
115
145
  gem "factory_girl_rails", "~> 4.0"
116
146
  gem "database_cleaner", '~> 1.3.0'
117
147
  end
148
+ gem_group :development do
149
+ gem "better_errors", '~> 1.1.0'
150
+ gem "binding_of_caller", "~> 0.7.1" # needed by better_errors or variable inspection
151
+ end
118
152
  # Other gems
119
- gem 'authorization', :path => "gems/authorization"
120
153
  # This ties in nicely with Ember, 0.8.0 is the stable version
121
154
  gem "active_model_serializers", "~> 0.8.0"
122
155
  # This is the api of choice now
@@ -126,12 +159,16 @@ module JsonVoorhees
126
159
  gem 'type_cartographer'
127
160
  gem 'devise', "~> 3.2.4"
128
161
  if options.arcadex?
129
- gem 'arcadex'#, '~> 1.0.4'
162
+ gem 'arcadex', '~> 1.1.0'
130
163
  end
131
164
  if options.admin?
132
165
  gem 'autoprefixer-rails'
133
166
  gem 'bootstrap-sass', '~> 3.2.0'
134
167
  end
168
+ if options.active_admin?
169
+ gem 'activeadmin', :git => 'https://github.com/activeadmin/activeadmin.git', :branch => "master"
170
+ end
171
+ gem 'authorization', :path => "gems/authorization"
135
172
  end
136
173
 
137
174
  def create_file_structure
@@ -146,8 +183,9 @@ module JsonVoorhees
146
183
 
147
184
  def run_bundle
148
185
  if !options.test?
149
- run "bundle update"
150
- run "bundle install"
186
+ Bundler.with_clean_env do
187
+ run "bundle install"
188
+ end
151
189
  end
152
190
  end
153
191
 
@@ -6,7 +6,7 @@ class Api::V1::ApiController < ::ActionController::API
6
6
 
7
7
  def authenticate_user
8
8
  #["current_user","current_token"] Make this true to check for email also
9
- @instance_hash = ::Arcadex.full_authentication(params,request,false)
9
+ @instance_hash = ::Arcadex::Authentication.full_authentication(params,request,false)
10
10
  if @instance_hash.nil?
11
11
  render :json => {errors: "User is not logged in, register or log in"} , status: :unauthorized
12
12
  end
@@ -28,9 +28,9 @@ module JsonVoorhees
28
28
  inject_into_file "config/routes.rb", after: "#{module_name.camelize}::Engine.routes.draw do\n" do <<-'RUBY'
29
29
 
30
30
  #root to: "controller_name#index"
31
- scope 'admin' do
31
+ #scope 'admin' do
32
32
 
33
- end
33
+ #end
34
34
 
35
35
  scope 'api' do
36
36
  scope '1' do
@@ -1,3 +1,3 @@
1
1
  module JsonVoorhees
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_voorhees
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cleophus Robinson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-09 00:00:00.000000000 Z
11
+ date: 2014-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails