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
@@ -0,0 +1,99 @@
1
+ ActiveAdmin.register Defcon::AdminUser do
2
+
3
+ menu :label => "AdminUsers"
4
+ config.per_page = 50
5
+
6
+ form do |f|
7
+ f.semantic_errors # shows errors on :base
8
+ #f.inputs # builds an input field for every attribute
9
+ f.inputs do
10
+ f.input :id
11
+ f.input :username
12
+ f.input :password
13
+ f.input :password_confirmation
14
+ f.input :email
15
+ f.input :read_only
16
+ f.input :attempts
17
+ f.input :max_attempts
18
+ f.input :master
19
+ f.input :updated_at
20
+ f.input :created_at
21
+ end
22
+ f.actions # adds the 'Submit' and 'Cancel' buttons
23
+ end
24
+
25
+ controller do
26
+ def create
27
+ @admin_user = ::Defcon::AdminUser.new(admin_user_params)
28
+ if @admin_user.save
29
+ flash[:notice] = "Created Successfully!"
30
+ redirect_to resource_path @admin_user
31
+ else
32
+ flash[:notice] = "#{@admin_user.errors.full_messages}"
33
+ redirect_to new_resource_path @admin_user
34
+ #super
35
+ #render :new
36
+ end
37
+ end
38
+
39
+ def update
40
+ @admin_user = ::Defcon::AdminUser.find(params[:id])
41
+ if @admin_user.update(admin_user_params)
42
+ flash[:notice] = "Updated Successfully!"
43
+ redirect_to resource_path @admin_user
44
+ else
45
+ flash.now[:notice] = "#{@admin_user.errors.full_messages}"
46
+ render :edit
47
+ #super
48
+ end
49
+ end
50
+
51
+ def destroy
52
+ =begin
53
+ @admin_user = ::Defcon::AdminUser.find(params[:id])
54
+ @admin_user.destroy
55
+ flash.now[:notice] = "Deleted Successfully!"
56
+ render :index
57
+ =end
58
+ flash.now[:notice] = "Deleting an Admin is serious business, update your policy first"
59
+ render :index
60
+ end
61
+
62
+ private
63
+
64
+ def admin_user_params
65
+ params.require(:admin_user).permit(:username,:email,:password,:password_confirmation,:read_only,:attempts,:max_attempts,:master)
66
+ end
67
+ end
68
+
69
+ index do
70
+ column :id
71
+ column :username
72
+ column :email
73
+ #column :password_digest
74
+ #column :read_only
75
+ column :attempts
76
+ #column :max_attempts
77
+ #column :master
78
+ column :updated_at
79
+ column :created_at
80
+ actions
81
+ end
82
+
83
+ show do
84
+ attributes_table do
85
+ row :id
86
+ row :username
87
+ row :email
88
+ row :password_digest
89
+ row :read_only
90
+ row :attempts
91
+ row :max_attempts
92
+ row :master
93
+ row :updated_at
94
+ row :created_at
95
+ end
96
+ end
97
+
98
+
99
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate model Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,21 @@
1
+ module HorsePower
2
+ class ModelGenerator < 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 "model.rb.erb", "app/models/#{HorsePower.get_singular(resource_name)}.rb"
10
+ # We only need this to create the migration
11
+ if api_version == "1"
12
+ run "rails g model #{HorsePower.get_singular(resource_name)} #{attributes.join(" ")} --no-fixture --skip"
13
+ run "rm -rf spec/factories/oceans.rb"
14
+ run "rm -rf spec/models/ocean_spec.rb"
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ end
21
+ end
@@ -0,0 +1,5 @@
1
+ require 'type_cartographer'
2
+
3
+ class <%= HorsePower.get_camel(resource_name) %> < ActiveRecord::Base
4
+
5
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate scaffold Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,54 @@
1
+ module HorsePower
2
+ class ScaffoldGenerator < 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
+ create_model
10
+ create_controller
11
+ create_serializer
12
+ create_authorizations
13
+ create_tests
14
+ create_admin
15
+ correct_routes
16
+ end
17
+
18
+ private
19
+
20
+ def create_model
21
+ run "rails g horse_power:model #{HorsePower.get_singular(resource_name)} #{api_version} #{attributes.join(" ")}"
22
+ end
23
+
24
+ def create_controller
25
+ run "rails g horse_power:controller #{HorsePower.get_singular(resource_name)} #{api_version} #{attributes.join(" ")}"
26
+ end
27
+
28
+ def create_serializer
29
+ run "rails g horse_power:serializer #{HorsePower.get_singular(resource_name)} #{api_version} #{attributes.join(" ")}"
30
+ end
31
+
32
+ def create_authorizations
33
+ run "rails g horse_power:authorization #{HorsePower.get_singular(resource_name)} #{api_version} #{attributes.join(" ")}"
34
+ end
35
+
36
+ def create_tests
37
+ run "rails g horse_power:tests #{HorsePower.get_singular(resource_name)} #{api_version} #{attributes.join(" ")}"
38
+ end
39
+
40
+ def create_admin
41
+ if api_version == "1"
42
+ template "active_admin_register.rb.erb", "app/admin/#{HorsePower.get_singular(resource_name)}.rb"
43
+ end
44
+ end
45
+
46
+ def correct_routes
47
+ # Expects the routes to already be setup
48
+ gsub_file 'config/routes.rb',
49
+ "scope \'#{api_version}\' do\n",
50
+ "scope \'#{api_version}\' do\n\t\t\tresources :#{HorsePower.get_plural(resource_name)}, except: [:new, :edit], controller: \'api/v#{api_version}/#{HorsePower.get_plural(resource_name)}\'\n"
51
+ end
52
+
53
+ end
54
+ end
@@ -0,0 +1,6 @@
1
+ ActiveAdmin.register <%= HorsePower.get_camel(resource_name) %> do
2
+ permit_params <%= HorsePower.params_list(attributes) %>
3
+
4
+ config.per_page = 50
5
+
6
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate serializer Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,15 @@
1
+ module HorsePower
2
+ class SerializerGenerator < 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 "serializer.rb.erb", "app/serializers/v#{api_version}/#{HorsePower.get_singular(resource_name)}_serializer.rb"
10
+ end
11
+
12
+ private
13
+
14
+ end
15
+ end
@@ -0,0 +1,38 @@
1
+ require 'authorization'
2
+
3
+ class V<%= api_version %>::<%= HorsePower.get_camel(resource_name) %>Serializer < ActiveModel::Serializer
4
+ embed :ids, include: true
5
+
6
+ attributes :id
7
+ <% attributes.each do |pair| -%>
8
+ attributes :<%= HorsePower.get_column(pair) %>
9
+ <% end -%>
10
+ attributes :created_at
11
+ attributes :updated_at
12
+ #has_one :bulletin
13
+ #has_many :posts
14
+
15
+ def include_id?
16
+ return ::Authorization::V<%= api_version %>::<%= HorsePower.get_camel(resource_name) %>.include_id?(current_user,object,@options)
17
+ end
18
+
19
+ <% attributes.each do |pair| -%>
20
+ def include_<%= HorsePower.get_column(pair) %>?
21
+ return ::Authorization::V<%= api_version %>::<%= HorsePower.get_camel(resource_name) %>.include_<%= HorsePower.get_column(pair) %>?(current_user,object,@options)
22
+ end
23
+
24
+ <% end -%>
25
+ def include_created_at?
26
+ return ::Authorization::V<%= api_version %>::<%= HorsePower.get_camel(resource_name) %>.include_created_at?(current_user,object,@options)
27
+ end
28
+
29
+ def include_updated_at?
30
+ return ::Authorization::V<%= api_version %>::<%= HorsePower.get_camel(resource_name) %>.include_updated_at?(current_user,object,@options)
31
+ end
32
+
33
+ def include_associations!
34
+ #include! :bulletin if ::Authorization::V<%= api_version %>::<%= HorsePower.get_camel(resource_name) %>.include_bulletin?(current_user,object,@options)
35
+ #include! :posts if ::Authorization::V<%= api_version %>::<%= HorsePower.get_camel(resource_name) %>.include_posts?(current_user,object,@options)
36
+ end
37
+
38
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate setup Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,188 @@
1
+ module HorsePower
2
+ class SetupGenerator < Rails::Generators::Base
3
+ source_root File.expand_path('../templates', __FILE__)
4
+
5
+ def sprint
6
+ create_file_structure
7
+ all_gems
8
+ run_bundle
9
+ rspec
10
+ api_controller
11
+ include_middleware
12
+ make_admin
13
+ routes
14
+ setup_routes
15
+ make_user
16
+ run "rake railties:install:migrations"
17
+ run_db_migrations
18
+ make_controllers
19
+ custom_active_admin
20
+ seed_database
21
+ initializers
22
+ run "wheneverize"
23
+ #run_git
24
+ end
25
+
26
+ private
27
+
28
+ def setup_routes
29
+ inject_into_file "config/routes.rb", after: "root to: \"app_index#app\"\n" do <<-'RUBY'
30
+
31
+ #root to: "controller_name#index"
32
+
33
+ scope 'api' do
34
+ scope '1' do
35
+ #/api/1/controller_name
36
+ #resources :controller_name, controller: 'api/v1/controller_name'
37
+ #resources :controller_name2, controller: 'api/v1/controller_name2' do
38
+ #collection do
39
+ #/api/1/controller_name2/action
40
+ #post 'action', to: "api/v1/controller_name2#action"
41
+ #end
42
+ #end
43
+ end
44
+ end
45
+
46
+ #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-
47
+
48
+ RUBY
49
+ end
50
+ end
51
+
52
+ def initializers
53
+ run "rails g horse_power:app_environment"
54
+ end
55
+
56
+ def seed_database
57
+ #db/seeds.rb
58
+ inject_into_file "db/seeds.rb", after: "# Mayor.create(name: 'Emanuel', city: cities.first)\n" do <<-'RUBY'
59
+
60
+ ::Defcon::AdminUser.create({username: "admin", password: "password", password_confirmation: "password"})
61
+
62
+ RUBY
63
+ end
64
+ run "rake db:seed"
65
+ end
66
+
67
+ def custom_active_admin
68
+ template "active_admin_token_register.rb.erb", "app/admin/arcadex_token.rb"
69
+ end
70
+
71
+ def make_admin
72
+ run "rails g horse_power:make_admin"
73
+ end
74
+
75
+ def make_user
76
+ run "rails g horse_power:user"
77
+ run_bundle
78
+ end
79
+
80
+ def include_middleware
81
+ inject_into_file 'config/application.rb', after: "class Application < Rails::Application\n" do <<-'RUBY'
82
+
83
+ #So Rails-Api doesn't remove all of the middleware
84
+ config.api_only = false
85
+
86
+ RUBY
87
+ end
88
+ end
89
+
90
+ def routes
91
+ route "mount Defcon::Engine, at: \'/\'"
92
+ route "root to: \"app_index#app\""
93
+ end
94
+
95
+ def make_controllers
96
+ generate "controller", "app_index app"
97
+ run "rm -f app/controllers/app_index_controller.rb"
98
+ copy_file "app_index_controller.rb", "app/controllers/app_index_controller.rb"
99
+ #Copy the views over
100
+ copy_file "views/app", "app/views/app_index/app.html.erb"
101
+ copy_file "views/app_index", "app/views/layouts/app_index.html.erb"
102
+ end
103
+
104
+ def api_controller
105
+ template "application_controller.rb", "app/controllers/api/v1/application_controller.rb"
106
+ end
107
+
108
+ def rspec
109
+ generate "rspec:install"
110
+ run "rm -f .rspec"
111
+ copy_file "hidden_rspec.rb", ".rspec"
112
+ copy_file "rspec_factory_girl.rb", "spec/support/factory_girl.rb"
113
+ inject_into_file 'spec/rails_helper.rb', after: "RSpec.configure do |config|\n" do <<-'RUBY'
114
+
115
+ config.include ::Requests::JsonHelpers, :type => :request
116
+ config.include ::Requests::JsonHelpers, :type => :controller
117
+
118
+ RUBY
119
+ end
120
+ copy_file "json_helpers.rb", "spec/support/request_helpers.rb"
121
+ end
122
+
123
+ def all_gems
124
+ # Dev gems
125
+ gem_group :development, :test do
126
+ gem 'figaro', '~> 0.7.0' # env variables
127
+ gem 'annotate', ">=2.6.0"
128
+ gem 'rspec-rails', '~> 3.0.0'
129
+ gem 'byebug', '~> 3.2.0'
130
+ gem 'factory_girl_rails', '~> 4.0'
131
+ gem 'database_cleaner', '~> 1.3.0'
132
+ end
133
+ gem_group :development do
134
+ gem 'better_errors', '~> 1.1.0'
135
+ gem 'binding_of_caller', '~> 0.7.1' # needed by better_errors or variable inspection
136
+ end
137
+ gem 'active_model_serializers', '~> 0.8.0'
138
+ # This is the api of choice now
139
+ gem 'rails-api'
140
+ gem 'kaminari'
141
+ gem 'bcrypt', '~> 3.1.7'
142
+ gem 'type_cartographer'
143
+ gem 'devise', "~> 3.2.4"
144
+ gem 'arcadex'
145
+ gem 'autoprefixer-rails'
146
+ gem 'bootstrap-sass', '~> 3.2.0'
147
+ gem 'activeadmin', :git => 'https://github.com/activeadmin/activeadmin.git', :branch => "master"
148
+ gem 'defcon'
149
+ gem 'authorization', :path => "gems/authorization"
150
+ gem 'whenever', :require => false
151
+ gem 'rack-cors', :require => 'rack/cors'
152
+ gem 'httparty'
153
+ gem 'paperclip', '~> 4.2'
154
+ gem 'aws-sdk', '~> 1.5.7'
155
+ gem 'rails_config', '~> 0.4.2'
156
+ #gem 'websocket-rails'
157
+ end
158
+
159
+ def create_file_structure
160
+ run "rm -rf test"
161
+ run "rm -f README.rdoc"
162
+ run "echo '# Describe your application here' > README.md"
163
+ run "mkdir engines && touch engines/.gitkeep"
164
+ run "mkdir gems && touch gems/.gitkeep"
165
+ run "mkdir notes && touch notes/.gitkeep"
166
+ run "rails plugin new gems/authorization"
167
+ end
168
+
169
+ def run_bundle
170
+ Bundler.with_clean_env do
171
+ run "bundle install"
172
+ end
173
+ end
174
+
175
+ def run_db_migrations
176
+ run "rake db:migrate RAILS_ENV=development"
177
+ run "rake db:migrate RAILS_ENV=test"
178
+ #run "rake db:migrate RAILS_ENV=production"
179
+ end
180
+
181
+ def run_git
182
+ git :init
183
+ git add: "."
184
+ run "git commit -m \"Initial commit\""
185
+ end
186
+
187
+ end
188
+ end
@@ -0,0 +1,102 @@
1
+ ActiveAdmin.register Arcadex::Token do
2
+
3
+ menu :label => "Tokens"
4
+ config.per_page = 50
5
+
6
+ =begin
7
+ batch_action :flag do |selection|
8
+ Arcadex::Token.find(selection).each { |p| p.flag! }
9
+ redirect_to collection_path, :notice => "Tokens flagged!"
10
+ end
11
+ =end
12
+
13
+ form do |f|
14
+ f.semantic_errors # shows errors on :base
15
+ #f.inputs # builds an input field for every attribute
16
+ f.inputs do
17
+ f.input :id
18
+ f.input :imageable_id
19
+ f.input :imageable_type
20
+ f.input :times_used
21
+ f.input :first_ip_address
22
+ f.input :current_ip_address
23
+ f.input :auth_token
24
+ f.input :expiration_minutes
25
+ f.input :updated_at
26
+ f.input :created_at
27
+ end
28
+ f.actions # adds the 'Submit' and 'Cancel' buttons
29
+ end
30
+
31
+ controller do
32
+ def create
33
+ @token = ::Arcadex::Token.new(token_params)
34
+ if @token.save
35
+ flash[:notice] = "Created Successfully!"
36
+ redirect_to resource_path @token
37
+ else
38
+ flash[:notice] = "#{@token.errors.full_messages}"
39
+ redirect_to new_resource_path @token
40
+ #super
41
+ #render :new
42
+ end
43
+ end
44
+
45
+ def update
46
+ @token = ::Arcadex::Token.find(params[:id])
47
+ if @token.update(token_params)
48
+ flash[:notice] = "Updated Successfully!"
49
+ redirect_to resource_path @token
50
+ else
51
+ flash.now[:notice] = "#{@token.errors.full_messages}"
52
+ render :edit
53
+ #super
54
+ end
55
+ end
56
+
57
+ def destroy
58
+ @token = ::Arcadex::Token.find(params[:id])
59
+ @token.destroy
60
+ flash.now[:notice] = "Deleted Successfully!"
61
+ render :index
62
+ end
63
+
64
+ private
65
+
66
+ def token_params
67
+ params.require(:token).permit(:times_used,:imageable_id,:imageable_type,:password_confirmation,:first_ip_address,:current_ip_address,:auth_token,:expiration_minutes)
68
+ end
69
+ end
70
+
71
+ index do
72
+ selectable_column
73
+ column :id
74
+ column :imageable_id
75
+ column :imageable_type
76
+ column :times_used
77
+ column :first_ip_address
78
+ column :current_ip_address
79
+ column :auth_token
80
+ column :expiration_minutes
81
+ column :updated_at
82
+ column :created_at
83
+ actions
84
+ end
85
+
86
+ show do
87
+ attributes_table do
88
+ row :id
89
+ row :imageable_id
90
+ row :imageable_type
91
+ row :times_used
92
+ row :first_ip_address
93
+ row :current_ip_address
94
+ row :auth_token
95
+ row :expiration_minutes
96
+ row :updated_at
97
+ row :created_at
98
+ end
99
+ end
100
+
101
+
102
+ end
@@ -0,0 +1,6 @@
1
+ class AppIndexController < ActionController::Base
2
+ def app
3
+ #This might come in handy if using the backend for a website
4
+ #render :file => "#{RAILS_ROOT}/public/index.html"
5
+ end
6
+ end
@@ -0,0 +1,45 @@
1
+ class Api::V1::ApplicationController < ::ActionController::API
2
+
3
+ before_action :authenticate_app
4
+ before_action :authenticate_user
5
+
6
+ private
7
+
8
+ def authenticate_app
9
+ api_key = ::Arcadex::Header.grab_param_header(params,request,::Settings.main_api_header,false)
10
+ if api_key.nil? || api_key != ::Settings.main_api_key
11
+ render :json => {errors: "App is not authorized"} , status: :forbidden
12
+ end
13
+ end
14
+
15
+ def authenticate_user
16
+ set_hash
17
+ if @instance_hash.nil?
18
+ response.headers["Logged-In-Status"] = "false"
19
+ render :json => {errors: "User is not logged in, register or log in"} , status: :unauthorized
20
+ else
21
+ response.headers["Logged-In-Status"] = "true"
22
+ end
23
+ end
24
+
25
+ def set_hash
26
+ @instance_hash = ::Arcadex::Authentication.get_instance(params,request,::Settings.token_header)
27
+ end
28
+
29
+ def current_user
30
+ if !@instance_hash.nil?
31
+ return @instance_hash["current_owner"]
32
+ else
33
+ return nil
34
+ end
35
+ end
36
+
37
+ def current_token
38
+ if !@instance_hash.nil?
39
+ return @instance_hash["current_token"]
40
+ else
41
+ return nil
42
+ end
43
+ end
44
+
45
+ end
@@ -0,0 +1,3 @@
1
+ --color
2
+ warnings = false
3
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ module Requests
2
+ module JsonHelpers
3
+ def json
4
+ @json = JSON.parse(response.body)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,16 @@
1
+ RSpec.configure do |config|
2
+ #additional factory_girl configuration
3
+
4
+ # Factory girl methods don't need to be prefaced with FactoryGirl
5
+ config.include FactoryGirl::Syntax::Methods
6
+
7
+ # Best each test suite is run, make sure the factories are valid
8
+ config.before(:suite) do
9
+ begin
10
+ DatabaseCleaner.start
11
+ FactoryGirl.lint
12
+ ensure
13
+ DatabaseCleaner.clean
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,9 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title></title>
5
+ </head>
6
+ <body>
7
+ <%= yield %>
8
+ </body>
9
+ </html>
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate tests Thing
6
+
7
+ This will create:
8
+ what/will/it/create