lazy_crud 0.9.7.1 → 0.9.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +0 -0
  3. data/.gitignore +0 -0
  4. data/.travis.yml +0 -0
  5. data/Gemfile +0 -0
  6. data/Gemfile.lock +46 -43
  7. data/LICENSE +0 -0
  8. data/README.md +14 -5
  9. data/Rakefile +0 -0
  10. data/lazy_crud.gemspec +0 -0
  11. data/lib/lazy_crud/before_hook_methods.rb +0 -0
  12. data/lib/lazy_crud/class_methods.rb +21 -0
  13. data/lib/lazy_crud/constants.rb +0 -0
  14. data/lib/lazy_crud/instance_methods.rb +0 -0
  15. data/lib/lazy_crud/version.rb +1 -1
  16. data/lib/lazy_crud.rb +3 -0
  17. data/lib/responders/json_responder.rb +0 -0
  18. data/spec/integration/discounts_controller_spec.rb +0 -0
  19. data/spec/integration/events_controller_spec.rb +0 -0
  20. data/spec/integration/users_controller_spec.rb +0 -0
  21. data/spec/rails_helper.rb +0 -0
  22. data/spec/spec_helper.rb +0 -0
  23. data/spec/support/factories.rb +0 -0
  24. data/spec/support/factory_girl.rb +0 -0
  25. data/spec/support/rails_app/Rakefile +0 -0
  26. data/spec/support/rails_app/app/assets/images/.keep +0 -0
  27. data/spec/support/rails_app/app/assets/javascripts/application.js +0 -0
  28. data/spec/support/rails_app/app/assets/javascripts/some_resources.js +0 -0
  29. data/spec/support/rails_app/app/assets/javascripts/users.js +0 -0
  30. data/spec/support/rails_app/app/assets/stylesheets/application.css +0 -0
  31. data/spec/support/rails_app/app/assets/stylesheets/scaffold.css +0 -0
  32. data/spec/support/rails_app/app/assets/stylesheets/some_resources.css +0 -0
  33. data/spec/support/rails_app/app/assets/stylesheets/users.css +0 -0
  34. data/spec/support/rails_app/app/controllers/application_controller.rb +0 -0
  35. data/spec/support/rails_app/app/controllers/discounts_controller.rb +0 -0
  36. data/spec/support/rails_app/app/controllers/events_controller.rb +0 -0
  37. data/spec/support/rails_app/app/controllers/users_controller.rb +0 -0
  38. data/spec/support/rails_app/app/helpers/application_helper.rb +0 -0
  39. data/spec/support/rails_app/app/helpers/events_helper.rb +0 -0
  40. data/spec/support/rails_app/app/helpers/users_helper.rb +0 -0
  41. data/spec/support/rails_app/app/models/collaboration.rb +0 -0
  42. data/spec/support/rails_app/app/models/concerns/.keep +0 -0
  43. data/spec/support/rails_app/app/models/discount.rb +0 -0
  44. data/spec/support/rails_app/app/models/event.rb +0 -0
  45. data/spec/support/rails_app/app/models/user.rb +0 -0
  46. data/spec/support/rails_app/app/views/discounts/edit.html.erb +0 -0
  47. data/spec/support/rails_app/app/views/discounts/index.html.erb +0 -0
  48. data/spec/support/rails_app/app/views/discounts/new.html.erb +0 -0
  49. data/spec/support/rails_app/app/views/discounts/show.html.erb +0 -0
  50. data/spec/support/rails_app/app/views/events/_form.html.erb +0 -0
  51. data/spec/support/rails_app/app/views/events/edit.html.erb +0 -0
  52. data/spec/support/rails_app/app/views/events/index.html.erb +0 -0
  53. data/spec/support/rails_app/app/views/events/new.html.erb +0 -0
  54. data/spec/support/rails_app/app/views/events/show.html.erb +0 -0
  55. data/spec/support/rails_app/app/views/layouts/application.html.erb +0 -0
  56. data/spec/support/rails_app/app/views/users/_form.html.erb +0 -0
  57. data/spec/support/rails_app/app/views/users/edit.html.erb +0 -0
  58. data/spec/support/rails_app/app/views/users/index.html.erb +0 -0
  59. data/spec/support/rails_app/app/views/users/new.html.erb +0 -0
  60. data/spec/support/rails_app/app/views/users/show.html.erb +0 -0
  61. data/spec/support/rails_app/config/application.rb +0 -0
  62. data/spec/support/rails_app/config/boot.rb +0 -0
  63. data/spec/support/rails_app/config/database.yml +0 -0
  64. data/spec/support/rails_app/config/environment.rb +0 -0
  65. data/spec/support/rails_app/config/environments/development.rb +0 -0
  66. data/spec/support/rails_app/config/environments/production.rb +0 -0
  67. data/spec/support/rails_app/config/environments/test.rb +0 -0
  68. data/spec/support/rails_app/config/initializers/assets.rb +0 -0
  69. data/spec/support/rails_app/config/initializers/backtrace_silencers.rb +0 -0
  70. data/spec/support/rails_app/config/initializers/cookies_serializer.rb +0 -0
  71. data/spec/support/rails_app/config/initializers/filter_parameter_logging.rb +0 -0
  72. data/spec/support/rails_app/config/initializers/inflections.rb +0 -0
  73. data/spec/support/rails_app/config/initializers/mime_types.rb +0 -0
  74. data/spec/support/rails_app/config/initializers/session_store.rb +0 -0
  75. data/spec/support/rails_app/config/initializers/wrap_parameters.rb +0 -0
  76. data/spec/support/rails_app/config/locales/en.yml +0 -0
  77. data/spec/support/rails_app/config/routes.rb +0 -0
  78. data/spec/support/rails_app/config/secrets.yml +0 -0
  79. data/spec/support/rails_app/config.ru +0 -0
  80. data/spec/support/rails_app/db/development.sqlite3 +0 -0
  81. data/spec/support/rails_app/db/migrate/20141231134904_create_users.rb +0 -0
  82. data/spec/support/rails_app/db/migrate/20150102225507_create_events.rb +0 -0
  83. data/spec/support/rails_app/db/migrate/20150104171110_create_discounts.rb +0 -0
  84. data/spec/support/rails_app/db/schema.rb +0 -0
  85. data/spec/support/rails_app/db/seeds.rb +0 -0
  86. data/spec/support/rails_app/db/test.sqlite3 +0 -0
  87. data/spec/support/rails_app/public/404.html +0 -0
  88. data/spec/support/rails_app/public/422.html +0 -0
  89. data/spec/support/rails_app/public/500.html +0 -0
  90. data/spec/support/rails_app/public/favicon.ico +0 -0
  91. data/spec/support/rails_app/public/robots.txt +0 -0
  92. data/spec/unit/lazy_crud_spec.rb +36 -5
  93. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f3e13ca08b320660d44d7d8ac8b8f3bb33a2df1b
4
- data.tar.gz: e97d2e24fc186fd8bd637d39082c607f0a898744
3
+ metadata.gz: 6f2d4bc24ae30d8d9c2d836d0038bc933c33324f
4
+ data.tar.gz: 8bc3051d77b626db265387fae3a1628bdf64a0a4
5
5
  SHA512:
6
- metadata.gz: 05a5f5d91802e70226832106d981638a325947a4fe4b0b9b38cbf2242efde963f234bbd80f56c16ced670c54ba9549432f21b1628a69fb168f714ee0e705d9c7
7
- data.tar.gz: 4ff29d78038805f8f13341f0cba9853dadf04c54dc5ac1bec6eae1a327a0b28b622b43c8de755e16b102887e5e0336a5b5da23004c84259e86e947e359bb159c
6
+ metadata.gz: fda7d1d74a22b370d0b30014bdc7eb45129032f1fbd0595f92a025f72bc0798b70858307f107f0307f62829e0270b4e72065c578ad39bab44e932233ed90bbce
7
+ data.tar.gz: 92661b8c6d655ebe3ba38ce32414e01d3def0ef7bbabbce4ca95f51084f271ba21b6378776215093d471fcbb9c6c7847863dc5ed2b9070588981a5d4b6208066
data/.codeclimate.yml CHANGED
File without changes
data/.gitignore CHANGED
File without changes
data/.travis.yml CHANGED
File without changes
data/Gemfile CHANGED
File without changes
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lazy_crud (0.9.7.1)
4
+ lazy_crud (0.9.8.0)
5
5
  activesupport
6
6
  i18n
7
7
  responders
@@ -9,45 +9,45 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- actionmailer (4.2.3)
13
- actionpack (= 4.2.3)
14
- actionview (= 4.2.3)
15
- activejob (= 4.2.3)
12
+ actionmailer (4.2.4)
13
+ actionpack (= 4.2.4)
14
+ actionview (= 4.2.4)
15
+ activejob (= 4.2.4)
16
16
  mail (~> 2.5, >= 2.5.4)
17
17
  rails-dom-testing (~> 1.0, >= 1.0.5)
18
- actionpack (4.2.3)
19
- actionview (= 4.2.3)
20
- activesupport (= 4.2.3)
18
+ actionpack (4.2.4)
19
+ actionview (= 4.2.4)
20
+ activesupport (= 4.2.4)
21
21
  rack (~> 1.6)
22
22
  rack-test (~> 0.6.2)
23
23
  rails-dom-testing (~> 1.0, >= 1.0.5)
24
24
  rails-html-sanitizer (~> 1.0, >= 1.0.2)
25
- actionview (4.2.3)
26
- activesupport (= 4.2.3)
25
+ actionview (4.2.4)
26
+ activesupport (= 4.2.4)
27
27
  builder (~> 3.1)
28
28
  erubis (~> 2.7.0)
29
29
  rails-dom-testing (~> 1.0, >= 1.0.5)
30
30
  rails-html-sanitizer (~> 1.0, >= 1.0.2)
31
- activejob (4.2.3)
32
- activesupport (= 4.2.3)
31
+ activejob (4.2.4)
32
+ activesupport (= 4.2.4)
33
33
  globalid (>= 0.3.0)
34
- activemodel (4.2.3)
35
- activesupport (= 4.2.3)
34
+ activemodel (4.2.4)
35
+ activesupport (= 4.2.4)
36
36
  builder (~> 3.1)
37
- activerecord (4.2.3)
38
- activemodel (= 4.2.3)
39
- activesupport (= 4.2.3)
37
+ activerecord (4.2.4)
38
+ activemodel (= 4.2.4)
39
+ activesupport (= 4.2.4)
40
40
  arel (~> 6.0)
41
- activesupport (4.2.3)
41
+ activesupport (4.2.4)
42
42
  i18n (~> 0.7)
43
43
  json (~> 1.7, >= 1.7.7)
44
44
  minitest (~> 5.1)
45
45
  thread_safe (~> 0.3, >= 0.3.4)
46
46
  tzinfo (~> 1.1)
47
- arel (6.0.0)
47
+ arel (6.0.3)
48
48
  awesome_print (1.6.1)
49
49
  builder (3.2.2)
50
- byebug (4.0.5)
50
+ byebug (5.0.0)
51
51
  columnize (= 0.9.0)
52
52
  codeclimate-test-reporter (0.4.7)
53
53
  simplecov (>= 0.7.1, < 1.0.0)
@@ -61,18 +61,18 @@ GEM
61
61
  factory_girl_rails (4.5.0)
62
62
  factory_girl (~> 4.5.0)
63
63
  railties (>= 3.0.0)
64
- globalid (0.3.5)
64
+ globalid (0.3.6)
65
65
  activesupport (>= 4.1.0)
66
66
  i18n (0.7.0)
67
67
  json (1.8.3)
68
- loofah (2.0.2)
68
+ loofah (2.0.3)
69
69
  nokogiri (>= 1.5.9)
70
70
  mail (2.6.3)
71
71
  mime-types (>= 1.16, < 3)
72
72
  method_source (0.8.2)
73
73
  mime-types (2.6.1)
74
74
  mini_portile (0.6.2)
75
- minitest (5.7.0)
75
+ minitest (5.8.0)
76
76
  nokogiri (1.6.6.2)
77
77
  mini_portile (~> 0.6.0)
78
78
  paranoia (2.1.3)
@@ -81,34 +81,34 @@ GEM
81
81
  coderay (~> 1.1.0)
82
82
  method_source (~> 0.8.1)
83
83
  slop (~> 3.4)
84
- pry-byebug (3.1.0)
85
- byebug (~> 4.0)
84
+ pry-byebug (3.2.0)
85
+ byebug (~> 5.0)
86
86
  pry (~> 0.10)
87
87
  rack (1.6.4)
88
88
  rack-test (0.6.3)
89
89
  rack (>= 1.0)
90
- rails (4.2.3)
91
- actionmailer (= 4.2.3)
92
- actionpack (= 4.2.3)
93
- actionview (= 4.2.3)
94
- activejob (= 4.2.3)
95
- activemodel (= 4.2.3)
96
- activerecord (= 4.2.3)
97
- activesupport (= 4.2.3)
90
+ rails (4.2.4)
91
+ actionmailer (= 4.2.4)
92
+ actionpack (= 4.2.4)
93
+ actionview (= 4.2.4)
94
+ activejob (= 4.2.4)
95
+ activemodel (= 4.2.4)
96
+ activerecord (= 4.2.4)
97
+ activesupport (= 4.2.4)
98
98
  bundler (>= 1.3.0, < 2.0)
99
- railties (= 4.2.3)
99
+ railties (= 4.2.4)
100
100
  sprockets-rails
101
101
  rails-deprecated_sanitizer (1.0.3)
102
102
  activesupport (>= 4.2.0.alpha)
103
- rails-dom-testing (1.0.6)
103
+ rails-dom-testing (1.0.7)
104
104
  activesupport (>= 4.2.0.beta, < 5.0)
105
105
  nokogiri (~> 1.6.0)
106
106
  rails-deprecated_sanitizer (>= 1.0.1)
107
107
  rails-html-sanitizer (1.0.2)
108
108
  loofah (~> 2.0)
109
- railties (4.2.3)
110
- actionpack (= 4.2.3)
111
- activesupport (= 4.2.3)
109
+ railties (4.2.4)
110
+ actionpack (= 4.2.4)
111
+ activesupport (= 4.2.4)
112
112
  rake (>= 0.8.7)
113
113
  thor (>= 0.18.1, < 2.0)
114
114
  rake (10.4.2)
@@ -118,15 +118,15 @@ GEM
118
118
  rspec-core (~> 3.3.0)
119
119
  rspec-expectations (~> 3.3.0)
120
120
  rspec-mocks (~> 3.3.0)
121
- rspec-core (3.3.1)
121
+ rspec-core (3.3.2)
122
122
  rspec-support (~> 3.3.0)
123
- rspec-expectations (3.3.0)
123
+ rspec-expectations (3.3.1)
124
124
  diff-lcs (>= 1.2.0, < 2.0)
125
125
  rspec-support (~> 3.3.0)
126
- rspec-mocks (3.3.1)
126
+ rspec-mocks (3.3.2)
127
127
  diff-lcs (>= 1.2.0, < 2.0)
128
128
  rspec-support (~> 3.3.0)
129
- rspec-rails (3.3.2)
129
+ rspec-rails (3.3.3)
130
130
  actionpack (>= 3.0, < 4.3)
131
131
  activesupport (>= 3.0, < 4.3)
132
132
  railties (>= 3.0, < 4.3)
@@ -141,7 +141,7 @@ GEM
141
141
  simplecov-html (~> 0.10.0)
142
142
  simplecov-html (0.10.0)
143
143
  slop (3.6.0)
144
- sprockets (3.2.0)
144
+ sprockets (3.3.3)
145
145
  rack (~> 1.0)
146
146
  sprockets-rails (2.3.2)
147
147
  actionpack (>= 3.0)
@@ -168,3 +168,6 @@ DEPENDENCIES
168
168
  rspec
169
169
  rspec-rails
170
170
  sqlite3
171
+
172
+ BUNDLED WITH
173
+ 1.10.3
data/LICENSE CHANGED
File without changes
data/README.md CHANGED
@@ -35,15 +35,14 @@ Terminal
35
35
 
36
36
  ### Basic setup
37
37
 
38
- Include all of the basic actions, `create`, `edit`, `destroy`, etc
38
+ To include all of the basic actions, `create`, `edit`, `destroy`, etc,
39
+ just add `include LazyCrud` to any controller.
39
40
 
40
- class SomeObjectController < ApplicationController
41
+ class SomeObjectsController < ApplicationController
41
42
  include LazyCrud
42
43
 
43
- At a bare minimum, you'll need to specify the class the controller is acting upon.
44
-
45
- set_resource SomeObject
46
44
 
45
+ Just make sure the model `SomeObject` exists.
47
46
 
48
47
  **Optional**
49
48
 
@@ -58,6 +57,16 @@ See specs for details.
58
57
 
59
58
  set_resource_parent Event
60
59
 
60
+ However, if you follow standard naming conventions, you can omit the above line
61
+ and have a controller that looks like this:
62
+
63
+ Parent::ExamplesController < ApplicationController
64
+ include LazyCrud
65
+
66
+ and the `Parent` class would be set as the resource parent.
67
+
68
+ Just make sure that a `Parent` `has_many :examples`
69
+
61
70
  **Sort of Optional**
62
71
 
63
72
  If you want to be able to update / create objects, you'll want to
data/Rakefile CHANGED
File without changes
data/lazy_crud.gemspec CHANGED
File without changes
File without changes
@@ -16,6 +16,27 @@ module LazyCrud
16
16
  self.parent_class = klass
17
17
  end
18
18
 
19
+ # determine default resource / pareent resource (if applicable)
20
+ # based on the naming convention
21
+ # e.g.: Parent::ModelController
22
+ def set_default_resources
23
+ name = self.name
24
+ namespaced_names = name.split(/::|Controller/)
25
+
26
+ model_name = namespaced_names.pop.try(:singularize)
27
+ parent_name = namespaced_names.join('::').try(:singularize)
28
+
29
+ if model_name.present?
30
+ set_resource model_name.constantize
31
+ else
32
+ raise "#{model_name} based on #{name} does not exist."
33
+ end
34
+
35
+ if parent_name.present?
36
+ set_resource_parent parent_name.constantize
37
+ end
38
+ end
39
+
19
40
  # the list of parameters to allow through the strong parameter filter
20
41
  def set_param_whitelist(*param_list)
21
42
  self.param_whitelist = param_list
File without changes
File without changes
@@ -1,3 +1,3 @@
1
1
  module LazyCrud
2
- VERSION = "0.9.7.1"
2
+ VERSION = "0.9.8.0"
3
3
  end
data/lib/lazy_crud.rb CHANGED
@@ -33,6 +33,9 @@ module LazyCrud
33
33
  # setting instance variables for actions and views
34
34
  before_action :set_resource, only: [:show, :edit, :update, :destroy]
35
35
  before_action :set_resource_instance, only: [:show, :edit, :update, :destroy]
36
+
37
+ # set default Resource / Parent Resource if applicable
38
+ set_default_resources
36
39
  end
37
40
 
38
41
  end
File without changes
File without changes
File without changes
File without changes
data/spec/rails_helper.rb CHANGED
File without changes
data/spec/spec_helper.rb CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -2,7 +2,23 @@ require 'spec_helper'
2
2
 
3
3
  describe LazyCrud do
4
4
 
5
- class Example < ActionController::Base
5
+ class Parent # < ActiveRecord::Base
6
+
7
+ end
8
+
9
+
10
+ class Example # < ActiveRecord::Base
11
+
12
+ end
13
+
14
+ # Controller with both parent and plural resource name
15
+ # plural resource name is standard for CRUD operations
16
+ class Parent::ExamplesController < ActionController::Base
17
+ include LazyCrud
18
+ end
19
+
20
+ # Controller with singular resource name
21
+ class ExampleController < ActionController::Base
6
22
  include LazyCrud
7
23
 
8
24
  before_create -> (resource){ 2+2 }
@@ -11,11 +27,26 @@ describe LazyCrud do
11
27
 
12
28
  end
13
29
 
30
+ describe '#set_default_resources' do
31
+ it 'sets the model based on the controller name' do
32
+ example = ExampleController.new
33
+
34
+ expect(example.send(:resource_proxy)).to eq Example
35
+ end
36
+
37
+ it 'sets the model and parent based on the controller name' do
38
+ parent_example = Parent::ExamplesController.new
39
+
40
+ expect(parent_example.class.send(:resource_class)).to eq Example
41
+ expect(parent_example.class.send(:parent_class)).to eq Parent
42
+ end
43
+ end
44
+
14
45
 
15
46
  describe '#build_method' do
16
47
 
17
48
  it 'uses build when the resource_proxy is a class' do
18
- example = Example.new
49
+ example = ExampleController.new
19
50
  allow(example).to receive(:resource_proxy){ Example }
20
51
 
21
52
  expect(example.send(:build_method)).to eq :new
@@ -27,17 +58,17 @@ describe LazyCrud do
27
58
  context 'calling a hook adds it to the hook list' do
28
59
 
29
60
  it 'before_create appends to the hook list' do
30
- hooks = Example.before_create_hooks
61
+ hooks = ExampleController.before_create_hooks
31
62
  expect(hooks.count).to eq 1
32
63
  end
33
64
 
34
65
  it 'before_update appends to the hook list' do
35
- hooks = Example.before_update_hooks
66
+ hooks = ExampleController.before_update_hooks
36
67
  expect(hooks.count).to eq 1
37
68
  end
38
69
 
39
70
  it 'before_destroy appends to the hook list' do
40
- hooks = Example.before_destroy_hooks
71
+ hooks = ExampleController.before_destroy_hooks
41
72
  expect(hooks.count).to eq 1
42
73
  end
43
74
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lazy_crud
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.7.1
4
+ version: 0.9.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - L. Preston Sego III
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-07 00:00:00.000000000 Z
11
+ date: 2015-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -313,10 +313,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
313
313
  version: '0'
314
314
  requirements: []
315
315
  rubyforge_project:
316
- rubygems_version: 2.4.6
316
+ rubygems_version: 2.4.7
317
317
  signing_key:
318
318
  specification_version: 4
319
- summary: LazyCrud-0.9.7.1
319
+ summary: LazyCrud-0.9.8.0
320
320
  test_files:
321
321
  - spec/integration/discounts_controller_spec.rb
322
322
  - spec/integration/events_controller_spec.rb