horse_power 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +3 -0
  4. data/Rakefile +34 -0
  5. data/app/assets/javascripts/horse_power/application.js +13 -0
  6. data/app/assets/stylesheets/horse_power/application.css +15 -0
  7. data/app/controllers/horse_power/application_controller.rb +4 -0
  8. data/app/helpers/horse_power/application_helper.rb +4 -0
  9. data/app/views/layouts/horse_power/application.html.erb +14 -0
  10. data/config/routes.rb +2 -0
  11. data/lib/generators/horse_power/app_environment/USAGE +8 -0
  12. data/lib/generators/horse_power/app_environment/app_environment_generator.rb +128 -0
  13. data/lib/generators/horse_power/authorization/USAGE +8 -0
  14. data/lib/generators/horse_power/authorization/authorization_generator.rb +20 -0
  15. data/lib/generators/horse_power/authorization/templates/auth_file.rb.erb +59 -0
  16. data/lib/generators/horse_power/controller/USAGE +8 -0
  17. data/lib/generators/horse_power/controller/controller_generator.rb +15 -0
  18. data/lib/generators/horse_power/controller/templates/controller_template.rb.erb +96 -0
  19. data/lib/generators/horse_power/make_admin/USAGE +8 -0
  20. data/lib/generators/horse_power/make_admin/make_admin_generator.rb +67 -0
  21. data/lib/generators/horse_power/make_admin/templates/dashboard.rb.erb +25 -0
  22. data/lib/generators/horse_power/make_admin/templates/defcon_admin_register.rb.erb +99 -0
  23. data/lib/generators/horse_power/model/USAGE +8 -0
  24. data/lib/generators/horse_power/model/model_generator.rb +21 -0
  25. data/lib/generators/horse_power/model/templates/model.rb.erb +5 -0
  26. data/lib/generators/horse_power/scaffold/USAGE +8 -0
  27. data/lib/generators/horse_power/scaffold/scaffold_generator.rb +54 -0
  28. data/lib/generators/horse_power/scaffold/templates/active_admin_register.rb.erb +6 -0
  29. data/lib/generators/horse_power/serializer/USAGE +8 -0
  30. data/lib/generators/horse_power/serializer/serializer_generator.rb +15 -0
  31. data/lib/generators/horse_power/serializer/templates/serializer.rb.erb +38 -0
  32. data/lib/generators/horse_power/setup/USAGE +8 -0
  33. data/lib/generators/horse_power/setup/setup_generator.rb +188 -0
  34. data/lib/generators/horse_power/setup/templates/active_admin_token_register.rb.erb +102 -0
  35. data/lib/generators/horse_power/setup/templates/app_index_controller.rb +6 -0
  36. data/lib/generators/horse_power/setup/templates/application_controller.rb +45 -0
  37. data/lib/generators/horse_power/setup/templates/hidden_rspec.rb +3 -0
  38. data/lib/generators/horse_power/setup/templates/json_helpers.rb +7 -0
  39. data/lib/generators/horse_power/setup/templates/rspec_factory_girl.rb +16 -0
  40. data/lib/generators/horse_power/setup/templates/views/app +0 -0
  41. data/lib/generators/horse_power/setup/templates/views/app_index +9 -0
  42. data/lib/generators/horse_power/tests/USAGE +8 -0
  43. data/lib/generators/horse_power/tests/templates/factory.rb.erb +12 -0
  44. data/lib/generators/horse_power/tests/templates/model.rb.erb +35 -0
  45. data/lib/generators/horse_power/tests/templates/request.rb.erb +136 -0
  46. data/lib/generators/horse_power/tests/templates/routing.rb.erb +46 -0
  47. data/lib/generators/horse_power/tests/tests_generator.rb +18 -0
  48. data/lib/generators/horse_power/user/USAGE +8 -0
  49. data/lib/generators/horse_power/user/templates/admin.rb.erb +20 -0
  50. data/lib/generators/horse_power/user/templates/authorization.rb.erb +97 -0
  51. data/lib/generators/horse_power/user/templates/controller.rb.erb +135 -0
  52. data/lib/generators/horse_power/user/templates/model.rb.erb +56 -0
  53. data/lib/generators/horse_power/user/templates/serializer.rb.erb +44 -0
  54. data/lib/generators/horse_power/user/templates/specs/factory.rb.erb +14 -0
  55. data/lib/generators/horse_power/user/templates/specs/model.rb.erb +61 -0
  56. data/lib/generators/horse_power/user/templates/specs/requests.rb.erb +220 -0
  57. data/lib/generators/horse_power/user/templates/specs/routing.rb.erb +58 -0
  58. data/lib/generators/horse_power/user/user_generator.rb +67 -0
  59. data/lib/horse_power/engine.rb +5 -0
  60. data/lib/horse_power/version.rb +3 -0
  61. data/lib/horse_power.rb +72 -0
  62. data/lib/tasks/horse_power_tasks.rake +4 -0
  63. data/test/dummy/README.rdoc +28 -0
  64. data/test/dummy/Rakefile +6 -0
  65. data/test/dummy/app/assets/javascripts/application.js +13 -0
  66. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  67. data/test/dummy/app/controllers/application_controller.rb +5 -0
  68. data/test/dummy/app/helpers/application_helper.rb +2 -0
  69. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  70. data/test/dummy/bin/bundle +3 -0
  71. data/test/dummy/bin/rails +4 -0
  72. data/test/dummy/bin/rake +4 -0
  73. data/test/dummy/config/application.rb +23 -0
  74. data/test/dummy/config/boot.rb +5 -0
  75. data/test/dummy/config/database.yml +25 -0
  76. data/test/dummy/config/environment.rb +5 -0
  77. data/test/dummy/config/environments/development.rb +37 -0
  78. data/test/dummy/config/environments/production.rb +78 -0
  79. data/test/dummy/config/environments/test.rb +39 -0
  80. data/test/dummy/config/initializers/assets.rb +8 -0
  81. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  82. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  83. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  84. data/test/dummy/config/initializers/inflections.rb +16 -0
  85. data/test/dummy/config/initializers/mime_types.rb +4 -0
  86. data/test/dummy/config/initializers/session_store.rb +3 -0
  87. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  88. data/test/dummy/config/locales/en.yml +23 -0
  89. data/test/dummy/config/routes.rb +4 -0
  90. data/test/dummy/config/secrets.yml +22 -0
  91. data/test/dummy/config.ru +4 -0
  92. data/test/dummy/public/404.html +67 -0
  93. data/test/dummy/public/422.html +67 -0
  94. data/test/dummy/public/500.html +66 -0
  95. data/test/dummy/public/favicon.ico +0 -0
  96. data/test/fresh/test_app/Gemfile +41 -0
  97. data/test/fresh/test_app/Gemfile.lock +127 -0
  98. data/test/fresh/test_app/README.rdoc +28 -0
  99. data/test/fresh/test_app/Rakefile +6 -0
  100. data/test/fresh/test_app/app/assets/javascripts/application.js +16 -0
  101. data/test/fresh/test_app/app/assets/stylesheets/application.css +15 -0
  102. data/test/fresh/test_app/app/controllers/application_controller.rb +5 -0
  103. data/test/fresh/test_app/app/helpers/application_helper.rb +2 -0
  104. data/test/fresh/test_app/app/views/layouts/application.html.erb +14 -0
  105. data/test/fresh/test_app/bin/bundle +3 -0
  106. data/test/fresh/test_app/bin/rails +8 -0
  107. data/test/fresh/test_app/bin/rake +8 -0
  108. data/test/fresh/test_app/bin/spring +18 -0
  109. data/test/fresh/test_app/config/application.rb +23 -0
  110. data/test/fresh/test_app/config/boot.rb +4 -0
  111. data/test/fresh/test_app/config/database.yml +25 -0
  112. data/test/fresh/test_app/config/environment.rb +5 -0
  113. data/test/fresh/test_app/config/environments/development.rb +37 -0
  114. data/test/fresh/test_app/config/environments/production.rb +78 -0
  115. data/test/fresh/test_app/config/environments/test.rb +39 -0
  116. data/test/fresh/test_app/config/initializers/assets.rb +8 -0
  117. data/test/fresh/test_app/config/initializers/backtrace_silencers.rb +7 -0
  118. data/test/fresh/test_app/config/initializers/cookies_serializer.rb +3 -0
  119. data/test/fresh/test_app/config/initializers/filter_parameter_logging.rb +4 -0
  120. data/test/fresh/test_app/config/initializers/inflections.rb +16 -0
  121. data/test/fresh/test_app/config/initializers/mime_types.rb +4 -0
  122. data/test/fresh/test_app/config/initializers/session_store.rb +3 -0
  123. data/test/fresh/test_app/config/initializers/wrap_parameters.rb +14 -0
  124. data/test/fresh/test_app/config/locales/en.yml +23 -0
  125. data/test/fresh/test_app/config/routes.rb +56 -0
  126. data/test/fresh/test_app/config/secrets.yml +22 -0
  127. data/test/fresh/test_app/config.ru +4 -0
  128. data/test/fresh/test_app/db/seeds.rb +7 -0
  129. data/test/fresh/test_app/public/404.html +67 -0
  130. data/test/fresh/test_app/public/422.html +67 -0
  131. data/test/fresh/test_app/public/500.html +66 -0
  132. data/test/fresh/test_app/public/favicon.ico +0 -0
  133. data/test/fresh/test_app/public/robots.txt +5 -0
  134. data/test/fresh/test_app/test/test_helper.rb +10 -0
  135. data/test/horse_power_test.rb +7 -0
  136. data/test/integration/navigation_test.rb +10 -0
  137. data/test/lib/generators/horse_power/app_environment_generator_test.rb +16 -0
  138. data/test/lib/generators/horse_power/authorization_generator_test.rb +16 -0
  139. data/test/lib/generators/horse_power/controller_generator_test.rb +16 -0
  140. data/test/lib/generators/horse_power/make_admin_generator_test.rb +16 -0
  141. data/test/lib/generators/horse_power/model_generator_test.rb +16 -0
  142. data/test/lib/generators/horse_power/scaffold_generator_test.rb +16 -0
  143. data/test/lib/generators/horse_power/serializer_generator_test.rb +16 -0
  144. data/test/lib/generators/horse_power/setup_generator_test.rb +16 -0
  145. data/test/lib/generators/horse_power/tests_generator_test.rb +16 -0
  146. data/test/lib/generators/horse_power/user_generator_test.rb +16 -0
  147. data/test/test_helper.rb +15 -0
  148. metadata +313 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d6757502c2b6ad55d70f8c7614ee92270bc85713
4
+ data.tar.gz: b357c8627065e761ecf4b07084b5200074e80177
5
+ SHA512:
6
+ metadata.gz: eb582f257a5e8d17a077e5bc2cc9b498e543f6aef26248d864c7e73e098dfff4530898e90557370d741d584cd13e62d548eaca96f48eaa47c8364835009da7f7
7
+ data.tar.gz: 62439515e52b76adadbe0c363d1b276dd66eafebc4a59415da1eb5a036e26cf80fb97a3aa1ed674a57faecdce10f3fd77bc5ba66eca7cd20a3aeae03a0e2a354
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2014 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = HorsePower
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,34 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'HorsePower'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+
22
+ Bundler::GemHelper.install_tasks
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'lib'
28
+ t.libs << 'test'
29
+ t.pattern = 'test/**/*_test.rb'
30
+ t.verbose = false
31
+ end
32
+
33
+
34
+ task default: :test
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,4 @@
1
+ module HorsePower
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module HorsePower
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>HorsePower</title>
5
+ <%= stylesheet_link_tag "horse_power/application", media: "all" %>
6
+ <%= javascript_include_tag "horse_power/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,2 @@
1
+ HorsePower::Engine.routes.draw do
2
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate app_environment Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,128 @@
1
+ module HorsePower
2
+ class AppEnvironmentGenerator < Rails::Generators::Base
3
+ source_root File.expand_path('../templates', __FILE__)
4
+
5
+ def sprint
6
+ createSettings
7
+ createDev
8
+ createTest
9
+ createPro
10
+ addToApplication
11
+ end
12
+
13
+ private
14
+
15
+ def createSettings
16
+ run "rails g rails_config:install"
17
+ prepend_to_file 'config/settings.yml' do
18
+ "token_header: \"Auth-Token\"\nmain_api_header: \"Main-Api-Header\"\n"
19
+ end
20
+ createEnvSettings
21
+ end
22
+
23
+ def createEnvSettings
24
+ prepend_to_file 'config/settings/development.yml' do
25
+ "main_api_key: \"123456789\"\n"
26
+ end
27
+ prepend_to_file 'config/settings/test.yml' do
28
+ "main_api_key: \"123456789\"\n"
29
+ end
30
+ prepend_to_file 'config/settings/production.yml' do
31
+ "main_api_key: \"123456789\"\n"
32
+ end
33
+ end
34
+
35
+ def addToApplication
36
+ inject_into_file 'config/application.rb', after: "class Application < Rails::Application\n" do <<-'RUBY'
37
+
38
+ #So url_for works in the mailer
39
+ config.action_mailer.default_url_options = { host: 'localhost:3000' }
40
+ #config.middleware.insert_before "ActionDispatch::Static", "Rack::Cors" do
41
+ config.middleware.use Rack::Cors do
42
+ allow do
43
+ origins '*'
44
+ resource '*',
45
+ :headers => :any,
46
+ :methods => [:get, :post, :put, :delete, :options],
47
+ :expose => ['Logged-In-Status','Auth-Token','Main-Api-Header']
48
+ end
49
+ end
50
+
51
+ RUBY
52
+ end
53
+ end
54
+
55
+ def createDev
56
+ ::Settings.reload!
57
+ gsub_file "config/environments/development.rb", "config.action_mailer.raise_delivery_errors = false\n", "#config.action_mailer.raise_delivery_errors = false\n"
58
+ inject_into_file 'config/environments/development.rb', after: "configure do\n" do <<-'RUBY'
59
+
60
+ config.action_mailer.perform_deliveries = false
61
+ config.action_mailer.raise_delivery_errors = false
62
+ config.action_mailer.default_options = {from: ENV['GMAIL_USERNAME']}
63
+ config.action_mailer.delivery_method = :smtp
64
+ config.action_mailer.smtp_settings = {
65
+ address: 'smtp.gmail.com',
66
+ port: 587,
67
+ domain: 'localhost:3000',
68
+ user_name: ENV['GMAIL_USERNAME'],
69
+ password: ENV['GMAIL_PASSWORD'],
70
+ authentication: 'plain',
71
+ enable_starttls_auto: true }
72
+ ::Paperclip.options[:command_path] = "/usr/bin/"
73
+ #Set Paperclip defaults here
74
+ #Paperclip::Attachment.default_options[:storage] = :fog
75
+
76
+ RUBY
77
+ end
78
+ end
79
+
80
+ def createTest
81
+ ::Settings.reload!
82
+ gsub_file "config/environments/test.rb", "config.action_mailer.delivery_method = :test\n", "#config.action_mailer.delivery_method = :test\n"
83
+ inject_into_file 'config/environments/test.rb', after: "configure do\n" do <<-'RUBY'
84
+
85
+ #config.action_mailer.perform_deliveries = false
86
+ config.action_mailer.raise_delivery_errors = true
87
+ config.action_mailer.default_options = {from: 'testing123@example.com'}
88
+ # Emails get sent here ::ActionMailer::Base.deliveries array.
89
+ config.action_mailer.delivery_method = :test
90
+ config.action_mailer.smtp_settings = {
91
+ address: 'smtp.gmail.com',
92
+ port: 587,
93
+ domain: 'localhost:3000',
94
+ user_name: 'testing123',
95
+ password: 'testing123',
96
+ authentication: 'plain',
97
+ enable_starttls_auto: true }
98
+ ::Paperclip.options[:command_path] = "/usr/bin/"
99
+ #Set Paperclip defaults here
100
+ #Paperclip::Attachment.default_options[:storage] = :fog
101
+
102
+ RUBY
103
+ end
104
+ end
105
+
106
+ def createPro
107
+ ::Settings.reload!
108
+ inject_into_file 'config/environments/production.rb', after: "configure do\n" do <<-'RUBY'
109
+
110
+ config.action_mailer.perform_deliveries = true
111
+ config.action_mailer.raise_delivery_errors = true
112
+ config.action_mailer.default_options = {from: ENV['GMAIL_USERNAME']}
113
+ config.action_mailer.delivery_method = :smtp
114
+ config.action_mailer.smtp_settings = {
115
+ address: 'smtp.gmail.com',
116
+ port: 587,
117
+ domain: 'example.com',
118
+ user_name: ENV['GMAIL_USERNAME'],
119
+ password: ENV['GMAIL_PASSWORD'],
120
+ authentication: 'plain',
121
+ enable_starttls_auto: true }
122
+ #May need to set Paperclip defaults here
123
+
124
+ RUBY
125
+ end
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate authorization Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,20 @@
1
+ module HorsePower
2
+ class AuthorizationGenerator < Rails::Generators::Base
3
+ source_root File.expand_path('../templates', __FILE__)
4
+ argument :resource_name, :type => :string
5
+ argument :api_version, :type => :string, :default => "1"
6
+ argument :attributes, type: :array, default: [], banner: "field:type field:type"
7
+
8
+ def sprint
9
+ template "auth_file.rb.erb", "gems/authorization/lib/authorization/v#{api_version}/#{HorsePower.get_singular(resource_name)}.rb"
10
+ require_authfile
11
+ end
12
+
13
+ private
14
+
15
+ def require_authfile
16
+ prepend_file 'gems/authorization/lib/authorization.rb', "require \'authorization/v#{api_version}/#{HorsePower.get_singular(resource_name)}\'\n"
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,59 @@
1
+ module Authorization
2
+ module V<%= api_version %>
3
+ module <%= HorsePower.get_camel(resource_name) %>
4
+
5
+ #Used in the controller
6
+
7
+ def self.index?(tokenUser)
8
+ return true
9
+ end
10
+
11
+ def self.show?(<%= HorsePower.get_singular(resource_name) %>,tokenUser)
12
+ return true
13
+ end
14
+
15
+ def self.create?(<%= HorsePower.get_singular(resource_name) %>_params,tokenUser)
16
+ return true
17
+ end
18
+
19
+ def self.update?(<%= HorsePower.get_singular(resource_name) %>,<%= HorsePower.get_singular(resource_name) %>_params,tokenUser)
20
+ return true
21
+ end
22
+
23
+ def self.destroy?(<%= HorsePower.get_singular(resource_name) %>,tokenUser)
24
+ return true
25
+ end
26
+
27
+ #Used in the serializer
28
+
29
+ def self.include_id?(current_user,<%= HorsePower.get_singular(resource_name) %>_object,options)
30
+ action = options[:url_options][:_recall][:action]
31
+ controller = options[:url_options][:_recall][:controller]
32
+ return true
33
+ end
34
+
35
+ <% attributes.each do |pair| -%>
36
+ def self.include_<%= HorsePower.get_column(pair) %>?(current_user,<%= HorsePower.get_singular(resource_name) %>_object,options)
37
+ action = options[:url_options][:_recall][:action]
38
+ controller = options[:url_options][:_recall][:controller]
39
+ return true
40
+ end
41
+
42
+ <% end -%>
43
+ def self.include_created_at?(current_user,<%= HorsePower.get_singular(resource_name) %>_object,options)
44
+ action = options[:url_options][:_recall][:action]
45
+ controller = options[:url_options][:_recall][:controller]
46
+ return true
47
+ end
48
+
49
+ def self.include_updated_at?(current_user,<%= HorsePower.get_singular(resource_name) %>_object,options)
50
+ action = options[:url_options][:_recall][:action]
51
+ controller = options[:url_options][:_recall][:controller]
52
+ return true
53
+ end
54
+
55
+ private
56
+
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate controller Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,15 @@
1
+ module HorsePower
2
+ class ControllerGenerator < Rails::Generators::Base
3
+ source_root File.expand_path('../templates', __FILE__)
4
+ argument :resource_name, :type => :string
5
+ argument :api_version, :type => :string, :default => "1"
6
+ argument :attributes, type: :array, default: [], banner: "field:type field:type"
7
+
8
+ def sprint
9
+ template "controller_template.rb.erb", "app/controllers/api/v#{api_version}/#{HorsePower.get_plural(resource_name)}_controller.rb"
10
+ end
11
+
12
+ private
13
+
14
+ end
15
+ end
@@ -0,0 +1,96 @@
1
+ require_dependency "api/v<%= api_version %>/application_controller"
2
+ require 'authorization'
3
+
4
+ class Api::V<%= api_version %>::<%= HorsePower.get_camel_plural(resource_name) %>Controller < Api::V<%= api_version %>::ApplicationController
5
+ before_action :set_<%= HorsePower.get_singular(resource_name) %>, only: [:show, :update, :destroy]
6
+ before_action :index_authorize, only: [:index]
7
+ before_action :show_authorize, only: [:show]
8
+ before_action :create_authorize, only: [:create]
9
+ before_action :update_authorize, only: [:update]
10
+ before_action :destroy_authorize, only: [:destroy]
11
+
12
+ # GET /api/<%= api_version %>/<%= HorsePower.get_plural(resource_name) %>
13
+ def index
14
+ @<%= HorsePower.get_plural(resource_name) %> = ::<%= HorsePower.get_camel(resource_name) %>.all
15
+ render json: @<%= HorsePower.get_plural(resource_name) %>, each_serializer: ::V<%= api_version %>::<%= HorsePower.get_camel(resource_name) %>Serializer
16
+ end
17
+
18
+ # GET /api/<%= api_version %>/<%= HorsePower.get_plural(resource_name) %>/1
19
+ def show
20
+ render json: @<%= HorsePower.get_singular(resource_name) %>, serializer: ::V<%= api_version %>::<%= HorsePower.get_camel(resource_name) %>Serializer
21
+ end
22
+
23
+ # POST /api/<%= api_version %>/<%= HorsePower.get_plural(resource_name) %>
24
+ def create
25
+ @<%= HorsePower.get_singular(resource_name) %> = ::<%= HorsePower.get_camel(resource_name) %>.new(<%= HorsePower.get_singular(resource_name) %>_params)
26
+ if @<%= HorsePower.get_singular(resource_name) %>.save
27
+ render json: @<%= HorsePower.get_singular(resource_name) %>, serializer: ::V<%= api_version %>::<%= HorsePower.get_camel(resource_name) %>Serializer
28
+ else
29
+ render :json => {errors: @<%= HorsePower.get_singular(resource_name) %>.errors.full_messages}, status: :unprocessable_entity
30
+ end
31
+ end
32
+
33
+ # PATCH/PUT /api/<%= api_version %>/<%= HorsePower.get_plural(resource_name) %>/1
34
+ def update
35
+ if @<%= HorsePower.get_singular(resource_name) %>.update(<%= HorsePower.get_singular(resource_name) %>_params)
36
+ render json: @<%= HorsePower.get_singular(resource_name) %>, serializer: ::V<%= api_version %>::<%= HorsePower.get_camel(resource_name) %>Serializer
37
+ else
38
+ render :json => {errors: @<%= HorsePower.get_singular(resource_name) %>.errors.full_messages}, status: :unprocessable_entity
39
+ end
40
+ end
41
+
42
+ # DELETE /api/<%= api_version %>/<%= HorsePower.get_plural(resource_name) %>/1
43
+ def destroy
44
+ @<%= HorsePower.get_singular(resource_name) %>.destroy
45
+ render json: {}
46
+ end
47
+
48
+ private
49
+
50
+ # Use callbacks to share common setup or constraints between actions.
51
+
52
+ def set_<%= HorsePower.get_singular(resource_name) %>
53
+ @<%= HorsePower.get_singular(resource_name) %> = ::<%= HorsePower.get_camel(resource_name) %>.find_by_id(params[:id])
54
+ if @<%= HorsePower.get_singular(resource_name) %>.nil?
55
+ render :json => {errors: "<%= HorsePower.get_camel(resource_name) %> was not found"}, status: :not_found
56
+ end
57
+ end
58
+
59
+ # Only allow a trusted parameter "white list" through.
60
+
61
+ def <%= HorsePower.get_singular(resource_name) %>_params
62
+ params.require(:<%= HorsePower.get_singular(resource_name) %>).permit(<%= HorsePower.params_list(attributes) %>)
63
+ end
64
+
65
+ # Authorizations below here
66
+
67
+ def index_authorize
68
+ if !::Authorization::V<%= api_version %>::<%= HorsePower.get_camel(resource_name) %>.index?(current_user)
69
+ render :json => {errors: "User is not authorized for this action"}, status: :forbidden
70
+ end
71
+ end
72
+
73
+ def show_authorize
74
+ if !::Authorization::V<%= api_version %>::<%= HorsePower.get_camel(resource_name) %>.show?(@<%= HorsePower.get_singular(resource_name) %>,current_user)
75
+ render :json => {errors: "User is not authorized for this action"}, status: :forbidden
76
+ end
77
+ end
78
+
79
+ def create_authorize
80
+ if !::Authorization::V<%= api_version %>::<%= HorsePower.get_camel(resource_name) %>.create?(<%= HorsePower.get_singular(resource_name) %>_params,current_user)
81
+ render :json => {errors: "User is not authorized for this action"}, status: :forbidden
82
+ end
83
+ end
84
+
85
+ def update_authorize
86
+ if !::Authorization::V<%= api_version %>::<%= HorsePower.get_camel(resource_name) %>.update?(@<%= HorsePower.get_singular(resource_name) %>,<%= HorsePower.get_singular(resource_name) %>_params,current_user)
87
+ render :json => {errors: "User is not authorized for this action"}, status: :forbidden
88
+ end
89
+ end
90
+
91
+ def destroy_authorize
92
+ if !::Authorization::V<%= api_version %>::<%= HorsePower.get_camel(resource_name) %>.destroy?(@<%= HorsePower.get_singular(resource_name) %>,current_user)
93
+ render :json => {errors: "User is not authorized for this action"}, status: :forbidden
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate make_admin Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,67 @@
1
+ module HorsePower
2
+ class MakeAdminGenerator < Rails::Generators::Base
3
+ source_root File.expand_path('../templates', __FILE__)
4
+
5
+ def sprint
6
+ make_active_admin
7
+ make_dashboard
8
+ end
9
+
10
+ private
11
+
12
+ def make_dashboard
13
+ run "rm -f app/admin/dashboard.rb"
14
+ copy_file "dashboard.rb.erb", "app/admin/dashboard.rb"
15
+ end
16
+
17
+ def make_active_admin
18
+ run "rails g active_admin:install --skip-users"
19
+ template "defcon_admin_register.rb.erb", "app/admin/defcon_admin_user.rb"
20
+ inject_into_file 'app/controllers/application_controller.rb', after: "protect_from_forgery with: :exception\n" do <<-'RUBY'
21
+
22
+ protected
23
+
24
+ def authenticate_admin_user!
25
+ if ::Defcon.authenticate_admin_user!(session)
26
+ return true
27
+ else
28
+ redirect_to defcon.defcon_login_path, alert: "Login!"
29
+ return false
30
+ end
31
+ end
32
+
33
+ def current_admin_user
34
+ return ::Defcon.current_admin_user(session)
35
+ end
36
+
37
+ RUBY
38
+ end
39
+ find_and_replace_initializer
40
+ end
41
+
42
+ def find_and_replace_initializer
43
+ gsub_file 'config/initializers/active_admin.rb',
44
+ 'config.authentication_method = :authenticate_admin_user!',
45
+ '#config.authentication_method = :authenticate_admin_user!'
46
+ gsub_file 'config/initializers/active_admin.rb',
47
+ 'config.current_user_method = :current_admin_user',
48
+ '#config.current_user_method = :current_admin_user'
49
+ gsub_file 'config/initializers/active_admin.rb',
50
+ 'config.logout_link_path = :destroy_admin_user_session_path',
51
+ '#config.logout_link_path = :destroy_admin_user_session_path'
52
+ inject_into_file 'config/initializers/active_admin.rb', after: "ActiveAdmin.setup do |config|\n" do <<-'RUBY'
53
+
54
+ # http auth for admin area
55
+ config.authentication_method = :authenticate_admin_user!
56
+ config.current_user_method = :current_admin_user
57
+ config.logout_link_path = "/sessions/destroy"
58
+ config.logout_link_method = :post
59
+ config.allow_comments = false
60
+ config.site_title_link = "/"
61
+
62
+ RUBY
63
+ end
64
+ end
65
+
66
+ end
67
+ end
@@ -0,0 +1,25 @@
1
+ ActiveAdmin.register_page "Dashboard" do
2
+
3
+ menu priority: 1, label: proc{ I18n.t("active_admin.dashboard") }
4
+
5
+ content title: proc{ I18n.t("active_admin.dashboard") } do
6
+
7
+ columns do
8
+
9
+ column do
10
+ panel "Recent Signups" do
11
+ table_for User.order("created_at desc").limit(50) do
12
+ column :username do |user|
13
+ link_to user.username, admin_user_path(user)
14
+ end
15
+ column :email
16
+ column :created_at
17
+ end
18
+ strong { link_to "View All Users", admin_users_path }
19
+ end
20
+ end
21
+
22
+ end
23
+
24
+ end
25
+ end