simple_crudify 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +2 -62
- data/.travis.yml +0 -2
- data/Gemfile.lock +2 -16
- data/README.md +25 -13
- data/lib/simple_crudify/common_methods.rb +49 -9
- data/lib/simple_crudify/crud_actions.rb +18 -4
- data/lib/simple_crudify/crudify.rb +18 -13
- data/lib/simple_crudify/crudify_dynamic_resource.rb +4 -2
- data/lib/simple_crudify/resource_helper.rb +17 -0
- data/lib/simple_crudify/version.rb +1 -1
- data/lib/simple_crudify.rb +5 -1
- data/simple_crudify.gemspec +0 -3
- metadata +4 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 53fde98453d5797fa5e81ff16ff835894ccf298d72ccdb659fafbb56c9140778
|
4
|
+
data.tar.gz: 8a01ab590746cfa9f2faacb36bf6848cc1fc4417b80a204a324e27910985e43b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 329c6d64e83593858b427fdd48e84f14c634f0270e4dbfd2303a8e1b44d5306a48e1fdd1ec655587973a652a5a3607fb9abf7f3873d7b2ded46e0ba0626e9280
|
7
|
+
data.tar.gz: 3580f1032fb084eb81b0dab72a663ebc7b9cd749677c228588fc4159ec8109646c20ce658935a10d509b236c99e3396c48ad154aed8a22c060ee0e1b8c731150
|
data/.rubocop.yml
CHANGED
@@ -1,23 +1,7 @@
|
|
1
|
-
|
2
|
-
AllCops:
|
3
|
-
Exclude:
|
4
|
-
- 'bin/*'
|
5
|
-
- 'spec/support'
|
6
|
-
- 'spec/factories'
|
7
|
-
- 'spec/fixtures'
|
8
|
-
- 'spec/support/*'
|
9
|
-
- 'spec/spec_helper.rb'
|
10
|
-
- 'spec/rails_helper.rb'
|
11
|
-
TargetRubyVersion: 2.4.1
|
12
|
-
DisplayCopNames: true
|
13
|
-
|
14
1
|
Style/Encoding:
|
15
2
|
Enabled: false
|
16
3
|
|
17
|
-
|
18
|
-
Enabled: false
|
19
|
-
|
20
|
-
Style/SpaceAroundEqualsInParameterDefault:
|
4
|
+
Layout/SpaceAroundEqualsInParameterDefault:
|
21
5
|
EnforcedStyle: no_space
|
22
6
|
|
23
7
|
Style/ParallelAssignment:
|
@@ -26,49 +10,5 @@ Style/ParallelAssignment:
|
|
26
10
|
Style/FrozenStringLiteralComment:
|
27
11
|
Enabled: false
|
28
12
|
|
29
|
-
Metrics/ModuleLength:
|
30
|
-
Exclude:
|
31
|
-
- "**/*_spec.rb"
|
32
|
-
|
33
|
-
Metrics/BlockLength:
|
34
|
-
Exclude:
|
35
|
-
- "**/*_spec.rb"
|
36
|
-
|
37
13
|
Metrics/LineLength:
|
38
|
-
Max:
|
39
|
-
|
40
|
-
Metrics/MethodLength:
|
41
|
-
Max: 30
|
42
|
-
|
43
|
-
Metrics/AbcSize:
|
44
|
-
Max: 80
|
45
|
-
|
46
|
-
Metrics/BlockLength:
|
47
|
-
Max: 100
|
48
|
-
|
49
|
-
Metrics/PerceivedComplexity:
|
50
|
-
Max: 20
|
51
|
-
|
52
|
-
Metrics/CyclomaticComplexity:
|
53
|
-
Max: 20
|
54
|
-
|
55
|
-
Metrics/ParameterLists:
|
56
|
-
Max: 10
|
57
|
-
|
58
|
-
Style/ClassAndModuleChildren:
|
59
|
-
Enabled: false
|
60
|
-
|
61
|
-
Layout/IndentationWidth:
|
62
|
-
Enabled: false
|
63
|
-
|
64
|
-
Layout/IndentationConsistency:
|
65
|
-
Enabled: false
|
66
|
-
|
67
|
-
Style/AccessModifierDeclarations:
|
68
|
-
Enabled: false
|
69
|
-
|
70
|
-
Layout/AlignHash:
|
71
|
-
Enabled: false
|
72
|
-
|
73
|
-
Layout/IndentHash:
|
74
|
-
Enabled: false
|
14
|
+
Max: 130
|
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,19 +1,12 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
simple_crudify (1.2.
|
4
|
+
simple_crudify (1.2.2)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
coderay (1.1.2)
|
10
9
|
diff-lcs (1.3)
|
11
|
-
docile (1.3.1)
|
12
|
-
json (2.1.0)
|
13
|
-
method_source (0.9.2)
|
14
|
-
pry (0.12.2)
|
15
|
-
coderay (~> 1.1.0)
|
16
|
-
method_source (~> 0.9.0)
|
17
10
|
rake (10.5.0)
|
18
11
|
rspec (3.8.0)
|
19
12
|
rspec-core (~> 3.8.0)
|
@@ -28,22 +21,15 @@ GEM
|
|
28
21
|
diff-lcs (>= 1.2.0, < 2.0)
|
29
22
|
rspec-support (~> 3.8.0)
|
30
23
|
rspec-support (3.8.0)
|
31
|
-
simplecov (0.16.1)
|
32
|
-
docile (~> 1.1)
|
33
|
-
json (>= 1.8, < 3)
|
34
|
-
simplecov-html (~> 0.10.0)
|
35
|
-
simplecov-html (0.10.2)
|
36
24
|
|
37
25
|
PLATFORMS
|
38
26
|
ruby
|
39
27
|
|
40
28
|
DEPENDENCIES
|
41
29
|
bundler (~> 1.16)
|
42
|
-
pry
|
43
30
|
rake (~> 10.0)
|
44
31
|
rspec (~> 3.0)
|
45
32
|
simple_crudify!
|
46
|
-
simplecov
|
47
33
|
|
48
34
|
BUNDLED WITH
|
49
|
-
1.16.
|
35
|
+
1.16.6
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
[![Build Status](https://secure.travis-ci.org/getsimpleadmin/simple_crudify.svg?branch=master)](http://travis-ci.org/getsimpleadmin/simple_crudify)[![
|
1
|
+
[![Build Status](https://secure.travis-ci.org/getsimpleadmin/simple_crudify.svg?branch=master)](http://travis-ci.org/getsimpleadmin/simple_crudify)[![Gem Version](https://badge.fury.io/rb/simple_crudify.svg)](https://rubygems.org/gems/simple_crudify)
|
2
2
|
# SimpleCrudify
|
3
3
|
|
4
4
|
The simple_crudify gem is a lightweight library for writing simple CRUD controllers.
|
@@ -33,23 +33,27 @@ class UsersController < ApplicationController
|
|
33
33
|
User
|
34
34
|
end
|
35
35
|
|
36
|
+
def controller_notice(action_name)
|
37
|
+
t("resource.#{action_name}.success", resource_name: model_klass)
|
38
|
+
end
|
39
|
+
|
36
40
|
private
|
37
41
|
|
38
|
-
|
39
|
-
|
40
|
-
|
42
|
+
def after_create_path
|
43
|
+
edit_user_path(@resource)
|
44
|
+
end
|
41
45
|
|
42
|
-
|
43
|
-
|
44
|
-
|
46
|
+
def after_update_path
|
47
|
+
users_path
|
48
|
+
end
|
45
49
|
|
46
|
-
|
47
|
-
|
48
|
-
|
50
|
+
def after_destroy_path
|
51
|
+
users_path
|
52
|
+
end
|
49
53
|
|
50
|
-
|
51
|
-
|
52
|
-
|
54
|
+
def resource_params
|
55
|
+
params.require(:user).permit(:password, :phone, :email)
|
56
|
+
end
|
53
57
|
end
|
54
58
|
```
|
55
59
|
|
@@ -72,6 +76,14 @@ end
|
|
72
76
|
|
73
77
|
Allow specifying the model class.
|
74
78
|
|
79
|
+
```ruby
|
80
|
+
def controller_notice(action_name)
|
81
|
+
t("resource.#{action_name}.success", resource_name: model_klass)
|
82
|
+
end
|
83
|
+
```
|
84
|
+
|
85
|
+
Helps to simplify controller redirect notice
|
86
|
+
|
75
87
|
## Contributing
|
76
88
|
|
77
89
|
Bug reports and pull requests are welcome on GitHub at https://github.com/getsimpleadmin/simple_crudify. This project is intended to be a safe, welcoming space for collaboration.
|
@@ -1,17 +1,57 @@
|
|
1
1
|
module SimpleCrudify
|
2
|
+
# Common methods that should implement in each controller
|
3
|
+
#
|
4
|
+
# @since 1.0.0
|
5
|
+
#
|
6
|
+
# @example
|
7
|
+
#
|
8
|
+
# class UsersController < ApplicationController
|
9
|
+
# include SimpleCrudify::Crudify
|
10
|
+
#
|
11
|
+
# actions :crud
|
12
|
+
#
|
13
|
+
# def model_klass
|
14
|
+
# User
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# # Notice for a user after redirect action
|
18
|
+
#
|
19
|
+
# def controller_notice(action_name)
|
20
|
+
# t("resource.#{action_name}.success", resource_name: model_klass)
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# private
|
24
|
+
#
|
25
|
+
# def after_create_path
|
26
|
+
# edit_user_path(@resource)
|
27
|
+
# end
|
28
|
+
#
|
29
|
+
# def after_update_path
|
30
|
+
# users_path
|
31
|
+
# end
|
32
|
+
#
|
33
|
+
# def after_destroy_path
|
34
|
+
# users_path
|
35
|
+
# end
|
36
|
+
#
|
37
|
+
# def resource_params
|
38
|
+
# params.require(:user).permit(:password, :phone, :email)
|
39
|
+
# end
|
40
|
+
# end
|
41
|
+
#
|
2
42
|
module CommonMethods
|
3
43
|
private
|
4
44
|
|
5
|
-
|
6
|
-
|
7
|
-
|
45
|
+
def controller_notice(*_args)
|
46
|
+
raise NotImplementedError, 'You should use a unified interface, add #controller_notice method'
|
47
|
+
end
|
8
48
|
|
9
|
-
|
10
|
-
|
11
|
-
|
49
|
+
def resource_params
|
50
|
+
raise NotImplementedError, 'You should use a unified interface, add #resource_params method'
|
51
|
+
end
|
12
52
|
|
13
|
-
|
14
|
-
|
15
|
-
|
53
|
+
def template_path(controller_action=nil)
|
54
|
+
"#{params[:controller]}/#{controller_action || params[:action]}"
|
55
|
+
end
|
16
56
|
end
|
17
57
|
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
module SimpleCrudify
|
2
2
|
module CrudActions
|
3
|
+
# @since 1.0.0
|
4
|
+
# @api private
|
3
5
|
module Index
|
4
6
|
def index
|
5
7
|
@resources = model_klass.all
|
@@ -8,14 +10,18 @@ module SimpleCrudify
|
|
8
10
|
end
|
9
11
|
end
|
10
12
|
|
13
|
+
# @since 1.0.0
|
14
|
+
# @api private
|
11
15
|
module Show
|
12
16
|
def show
|
13
|
-
@resource =
|
17
|
+
@resource = ResourceHelper.resource(model_klass, params[:id])
|
14
18
|
|
15
19
|
render template_path
|
16
20
|
end
|
17
21
|
end
|
18
22
|
|
23
|
+
# @since 1.0.0
|
24
|
+
# @api private
|
19
25
|
module New
|
20
26
|
def new
|
21
27
|
@resource = model_klass.new
|
@@ -24,6 +30,8 @@ module SimpleCrudify
|
|
24
30
|
end
|
25
31
|
end
|
26
32
|
|
33
|
+
# @since 1.0.0
|
34
|
+
# @api private
|
27
35
|
module Create
|
28
36
|
def create
|
29
37
|
@resource = model_klass.new(resource_params)
|
@@ -36,17 +44,21 @@ module SimpleCrudify
|
|
36
44
|
end
|
37
45
|
end
|
38
46
|
|
47
|
+
# @since 1.0.0
|
48
|
+
# @api private
|
39
49
|
module Edit
|
40
50
|
def edit
|
41
|
-
@resource =
|
51
|
+
@resource = ResourceHelper.resource(model_klass, params[:id])
|
42
52
|
|
43
53
|
render template_path
|
44
54
|
end
|
45
55
|
end
|
46
56
|
|
57
|
+
# @since 1.0.0
|
58
|
+
# @api private
|
47
59
|
module Update
|
48
60
|
def update
|
49
|
-
@resource =
|
61
|
+
@resource = ResourceHelper.resource(model_klass, params[:id])
|
50
62
|
|
51
63
|
if @resource.update(resource_params)
|
52
64
|
redirect_to after_update_path, notice: controller_notice(action_name)
|
@@ -56,9 +68,11 @@ module SimpleCrudify
|
|
56
68
|
end
|
57
69
|
end
|
58
70
|
|
71
|
+
# @since 1.0.0
|
72
|
+
# @api private
|
59
73
|
module Destroy
|
60
74
|
def destroy
|
61
|
-
@resource =
|
75
|
+
@resource = ResourceHelper.resource(model_klass, params[:id])
|
62
76
|
@resource.destroy
|
63
77
|
|
64
78
|
redirect_to after_destroy_path, notice: controller_notice(action_name)
|
@@ -1,14 +1,17 @@
|
|
1
1
|
module SimpleCrudify
|
2
|
+
# Controller actions mapper, each action placed in different modules
|
3
|
+
#
|
4
|
+
# @since 1.0.0
|
2
5
|
module Crudify
|
3
6
|
include CommonMethods
|
4
7
|
|
5
8
|
DEPENDENCIES_MAP = {
|
6
|
-
index:
|
7
|
-
show:
|
8
|
-
new:
|
9
|
-
create:
|
10
|
-
edit:
|
11
|
-
update:
|
9
|
+
index: CrudActions::Index,
|
10
|
+
show: CrudActions::Show,
|
11
|
+
new: CrudActions::New,
|
12
|
+
create: CrudActions::Create,
|
13
|
+
edit: CrudActions::Edit,
|
14
|
+
update: CrudActions::Update,
|
12
15
|
destroy: CrudActions::Destroy
|
13
16
|
}.freeze
|
14
17
|
|
@@ -16,18 +19,20 @@ module SimpleCrudify
|
|
16
19
|
base.extend(ClassMethods)
|
17
20
|
end
|
18
21
|
|
22
|
+
# @since 1.0.0
|
23
|
+
# @api private
|
19
24
|
module ClassMethods
|
20
25
|
private
|
21
26
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
end
|
27
|
+
def actions(*action_names)
|
28
|
+
if action_names.include?(:crud)
|
29
|
+
DEPENDENCIES_MAP.values.each { |action| include(action) }
|
30
|
+
else
|
31
|
+
action_names.each do |action|
|
32
|
+
include(DEPENDENCIES_MAP[action])
|
29
33
|
end
|
30
34
|
end
|
35
|
+
end
|
31
36
|
end
|
32
37
|
end
|
33
38
|
end
|
@@ -1,4 +1,6 @@
|
|
1
1
|
module SimpleCrudify
|
2
|
+
# @since 1.0.0
|
3
|
+
# @api private
|
2
4
|
module CrudifyDynamicResource
|
3
5
|
def create
|
4
6
|
@resource = model_klass.new(resource_params)
|
@@ -10,7 +12,7 @@ module SimpleCrudify
|
|
10
12
|
end
|
11
13
|
|
12
14
|
def update
|
13
|
-
@resource =
|
15
|
+
@resource = ResourceHelper.resource(model_klass, params[:id])
|
14
16
|
@resource.update(resource_params)
|
15
17
|
|
16
18
|
respond_to do |format|
|
@@ -19,7 +21,7 @@ module SimpleCrudify
|
|
19
21
|
end
|
20
22
|
|
21
23
|
def destroy
|
22
|
-
@resource =
|
24
|
+
@resource = ResourceHelper.resource(model_klass, params[:id])
|
23
25
|
@resource.destroy
|
24
26
|
|
25
27
|
respond_to do |format|
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module SimpleCrudify
|
2
|
+
# Module to easily handle additional gems that work with a model, like friendly_id
|
3
|
+
#
|
4
|
+
# @since 1.2.2
|
5
|
+
#
|
6
|
+
module ResourceHelper
|
7
|
+
module_function
|
8
|
+
|
9
|
+
def resource(model_klass, resource_id)
|
10
|
+
if defined?(FriendlyId)
|
11
|
+
model_klass.friendly.find_by_friendly_id(resource_id)
|
12
|
+
else
|
13
|
+
model_klass.find(resource_id)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/simple_crudify.rb
CHANGED
@@ -1,10 +1,14 @@
|
|
1
1
|
require 'simple_crudify/version'
|
2
2
|
|
3
|
+
require 'simple_crudify/resource_helper'
|
3
4
|
require 'simple_crudify/common_methods'
|
5
|
+
|
4
6
|
require 'simple_crudify/crud_actions'
|
5
7
|
require 'simple_crudify/crudify'
|
6
|
-
|
7
8
|
require 'simple_crudify/crudify_dynamic_resource'
|
8
9
|
|
10
|
+
# Lightweight library for writing simple CRUD controllers.
|
11
|
+
#
|
12
|
+
# @since 1.0.0
|
9
13
|
module SimpleCrudify
|
10
14
|
end
|
data/simple_crudify.gemspec
CHANGED
@@ -25,7 +25,4 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.add_development_dependency 'bundler', '~> 1.16'
|
26
26
|
spec.add_development_dependency 'rake', '~> 10.0'
|
27
27
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
28
|
-
|
29
|
-
spec.add_development_dependency 'pry'
|
30
|
-
spec.add_development_dependency 'simplecov'
|
31
28
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_crudify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmitriy Strukov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-05-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,34 +52,6 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: pry
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: simplecov
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
55
|
description: simple_crudify
|
84
56
|
email:
|
85
57
|
- dmitiry_strukov2011@mail.ru
|
@@ -103,6 +75,7 @@ files:
|
|
103
75
|
- lib/simple_crudify/crud_actions.rb
|
104
76
|
- lib/simple_crudify/crudify.rb
|
105
77
|
- lib/simple_crudify/crudify_dynamic_resource.rb
|
78
|
+
- lib/simple_crudify/resource_helper.rb
|
106
79
|
- lib/simple_crudify/version.rb
|
107
80
|
- simple_crudify.gemspec
|
108
81
|
homepage: https://github.com/getsimpleadmin/simple_crudify
|
@@ -124,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
97
|
version: '0'
|
125
98
|
requirements: []
|
126
99
|
rubyforge_project:
|
127
|
-
rubygems_version: 2.
|
100
|
+
rubygems_version: 2.7.9
|
128
101
|
signing_key:
|
129
102
|
specification_version: 4
|
130
103
|
summary: simple_crudify
|