simple_crudify 0.1.0 → 1.0.0

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: 718dd1befdbb4241cd1637dbb76dfe4a679ed8d2
4
- data.tar.gz: 7f7ff71d678c5c702207538a793359c17c2064b1
3
+ metadata.gz: 0d827b5676182edbe02c64dbf17f098abfae5f32
4
+ data.tar.gz: 7e2de6eeb16bdf9d1444fc35ca3b47f22121e9b0
5
5
  SHA512:
6
- metadata.gz: 6f17ae125346ec785c059096b97a800eaaac428dfcd13740fac1c00d8e48113f3442d12dcee02ff56c619362eda3d1cecbd4a9ec009522a401d628603c0ff3e0
7
- data.tar.gz: fd4ee214715f1de42287530b25ac39574b1efeb2dba4a9cf3ce2438b261622f68414188572d3d2e4c3912ca99d0feb2c937873ea93e31913f2a2b9e8de67b45d
6
+ metadata.gz: 7ac701b80ea242812d2cacb436c4361bd6bbf083a296cf70d9b7d2d1490e783b46838e8904c9ad03aaed5dc0b6830639ea1cf888b51ebe161e3444ec4f37076b
7
+ data.tar.gz: 6772b7f623cf4a921175dc9f7e33cc9b9229d6c87f031e787c870e5f93a89065e8a04e88a04727ab87f7c1f4a6a27a234104f15e2205fe59323009977a6572d8
data/README.md CHANGED
@@ -26,9 +26,12 @@ A short example
26
26
  class UsersController < ApplicationController
27
27
  include SimpleCrudify::Crudify
28
28
 
29
- model_klass { User }
30
29
  crud_actions :crud
31
30
 
31
+ def model_klass
32
+ User
33
+ end
34
+
32
35
  private
33
36
 
34
37
  def after_create_path
@@ -61,7 +64,9 @@ crud_actions :crud # an alias for all actions
61
64
  Other settings
62
65
 
63
66
  ```ruby
64
- model_klass User
67
+ def model_klass
68
+ User
69
+ end
65
70
  ```
66
71
 
67
72
  Allow specifying the model class.
@@ -0,0 +1,13 @@
1
+ module SimpleCrudify
2
+ module CommonMethods
3
+ private
4
+
5
+ def resource_params
6
+ raise NotImplementedError
7
+ end
8
+
9
+ def template_path(controller_action=nil)
10
+ "#{params[:controller]}/#{controller_action || params[:action]}"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,68 @@
1
+ module SimpleCrudify
2
+ module CrudActions
3
+ module Index
4
+ def index
5
+ @resources = model_klass.all
6
+
7
+ render template_path
8
+ end
9
+ end
10
+
11
+ module Show
12
+ def show
13
+ @resource = model_klass.find(params[:id])
14
+
15
+ render template_path
16
+ end
17
+ end
18
+
19
+ module New
20
+ def new
21
+ @resource = model_klass.new
22
+
23
+ render template_path
24
+ end
25
+ end
26
+
27
+ module Create
28
+ def create
29
+ @resource = model_klass.new(resource_params)
30
+
31
+ if @resource.save
32
+ redirect_to after_create_path
33
+ else
34
+ render template: template_path(:new)
35
+ end
36
+ end
37
+ end
38
+
39
+ module Edit
40
+ def edit
41
+ @resource = model_klass.find(params[:id])
42
+
43
+ render template_path
44
+ end
45
+ end
46
+
47
+ module Update
48
+ def update
49
+ @resource = model_klass.find(params[:id])
50
+
51
+ if @resource.update(resource_params)
52
+ redirect_to after_update_path
53
+ else
54
+ render template: template_path(:edit)
55
+ end
56
+ end
57
+ end
58
+
59
+ module Destroy
60
+ def destroy
61
+ @resource = model_klass.find(params[:id])
62
+ @resource.destroy
63
+
64
+ redirect_to after_destroy_path
65
+ end
66
+ end
67
+ end
68
+ end
@@ -1,83 +1,4 @@
1
1
  module SimpleCrudify
2
- module CrudActions
3
- module Index
4
- def index
5
- @resources = model_klass.all
6
-
7
- render template_path
8
- end
9
- end
10
-
11
- module Show
12
- def show
13
- @resource = model_klass.find(params[:id])
14
-
15
- render template_path
16
- end
17
- end
18
-
19
- module New
20
- def new
21
- @resource = model_klass.new
22
-
23
- render template_path
24
- end
25
- end
26
-
27
- module Create
28
- def create
29
- @resource = model_klass.new(resource_params)
30
-
31
- if @resource.save
32
- redirect_to after_create_path
33
- else
34
- render template: template_path(:new)
35
- end
36
- end
37
- end
38
-
39
- module Edit
40
- def edit
41
- @resource = model_klass.find(params[:id])
42
-
43
- render template_path
44
- end
45
- end
46
-
47
- module Update
48
- def update
49
- @resource = model_klass.find(params[:id])
50
-
51
- if @resource.update(resource_params)
52
- redirect_to after_update_path
53
- else
54
- render template: template_path(:edit)
55
- end
56
- end
57
- end
58
-
59
- module Destroy
60
- def destroy
61
- @resource = model_klass.find(params[:id])
62
- @resource.destroy
63
-
64
- redirect_to after_destroy_path
65
- end
66
- end
67
- end
68
-
69
- module CommonMethods
70
- private
71
-
72
- def resource_params
73
- raise NotImplementedError
74
- end
75
-
76
- def template_path(controller_action=nil)
77
- "#{params[:controller]}/#{controller_action || params[:action]}"
78
- end
79
- end
80
-
81
2
  module Crudify
82
3
  include CommonMethods
83
4
 
@@ -96,10 +17,6 @@ module SimpleCrudify
96
17
  end
97
18
 
98
19
  module ClassMethods
99
- def model_klass
100
- @model_klass ||= yield
101
- end
102
-
103
20
  private
104
21
 
105
22
  def crud_actions(*actions)
@@ -112,9 +29,5 @@ module SimpleCrudify
112
29
  end
113
30
  end
114
31
  end
115
-
116
- def model_klass
117
- self.class.model_klass
118
- end
119
32
  end
120
33
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleCrudify
2
- VERSION = '0.1.0'
2
+ VERSION = '1.0.0'
3
3
  end
@@ -1,4 +1,7 @@
1
1
  require 'simple_crudify/version'
2
+
3
+ require 'simple_crudify/common_methods'
4
+ require 'simple_crudify/crud_actions'
2
5
  require 'simple_crudify/crudify'
3
6
 
4
7
  module SimpleCrudify
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_crudify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitriy Strukov
@@ -55,6 +55,8 @@ files:
55
55
  - bin/console
56
56
  - bin/setup
57
57
  - lib/simple_crudify.rb
58
+ - lib/simple_crudify/common_methods.rb
59
+ - lib/simple_crudify/crud_actions.rb
58
60
  - lib/simple_crudify/crudify.rb
59
61
  - lib/simple_crudify/version.rb
60
62
  - simple_crudify.gemspec