simple_crudify 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +20 -0
- data/README.md +76 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/simple_crudify/crudify.rb +120 -0
- data/lib/simple_crudify/version.rb +3 -0
- data/lib/simple_crudify.rb +5 -0
- data/simple_crudify.gemspec +27 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4c388fad87f596bde2919a8907ed79841a4c1a3f
|
4
|
+
data.tar.gz: 0bc1580b2fa50dc93017a57db4449e44b4a073b0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f63c088aef9aff148d0608577499968bea22050cd739736017806a0872dc53de8f08989eae1e63cda26dc2182dae763dfaa131354959b5b764ac6f357e201a88
|
7
|
+
data.tar.gz: 4d1dd7c95288022ee22c2957a660de466a88269f48b6d45898be2c7c9b0f00db28a0f65fd8ae77aa0049341becf43da5143e142bb9225b00b7c319208d1c91fb
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at dmitiry_strukov2011@mail.ru. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
simple_crudify (0.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
rake (10.5.0)
|
10
|
+
|
11
|
+
PLATFORMS
|
12
|
+
ruby
|
13
|
+
|
14
|
+
DEPENDENCIES
|
15
|
+
bundler (~> 1.16)
|
16
|
+
rake (~> 10.0)
|
17
|
+
simple_crudify!
|
18
|
+
|
19
|
+
BUNDLED WITH
|
20
|
+
1.16.1
|
data/README.md
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
# SimpleCrudify
|
2
|
+
|
3
|
+
The simple_crudify gem is a lightweight library for writing simple CRUD controllers.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'simple_crudify'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install simple_crudify
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
A short example
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
class UsersController < ApplicationController
|
27
|
+
include SimpleCrudify::Crudify
|
28
|
+
|
29
|
+
model_klass { User }
|
30
|
+
crud_actions :crud
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def after_create_path
|
35
|
+
edit_user_path(@resource)
|
36
|
+
end
|
37
|
+
|
38
|
+
def after_update_path
|
39
|
+
users_path
|
40
|
+
end
|
41
|
+
|
42
|
+
def after_destroy_path
|
43
|
+
users_path
|
44
|
+
end
|
45
|
+
|
46
|
+
def resource_params
|
47
|
+
params.require(:user).permit(:password, :phone, :email)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
```
|
51
|
+
|
52
|
+
### Controller configuration
|
53
|
+
|
54
|
+
The first required configuration is an action name.
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
crud_actions :index, :show, :new, :create
|
58
|
+
crud_actions :crud # an alias for all actions
|
59
|
+
```
|
60
|
+
|
61
|
+
Other settings
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
model_klass User
|
65
|
+
```
|
66
|
+
|
67
|
+
Allow specifying the model class.
|
68
|
+
|
69
|
+
## Contributing
|
70
|
+
|
71
|
+
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.
|
72
|
+
|
73
|
+
|
74
|
+
## License
|
75
|
+
|
76
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "simple_crudify"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,120 @@
|
|
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
|
+
module Crudify
|
82
|
+
include CommonMethods
|
83
|
+
|
84
|
+
DEPENDENCIES_MAP = {
|
85
|
+
index: CrudActions::Index,
|
86
|
+
show: CrudActions::Show,
|
87
|
+
new: CrudActions::New,
|
88
|
+
create: CrudActions::Create,
|
89
|
+
edit: CrudActions::Edit,
|
90
|
+
update: CrudActions::Update,
|
91
|
+
destroy: CrudActions::Destroy
|
92
|
+
}
|
93
|
+
|
94
|
+
def self.included(base)
|
95
|
+
base.extend(ClassMethods)
|
96
|
+
end
|
97
|
+
|
98
|
+
module ClassMethods
|
99
|
+
def model_klass
|
100
|
+
@model_klass ||= yield
|
101
|
+
end
|
102
|
+
|
103
|
+
private
|
104
|
+
|
105
|
+
def crud_actions(*actions)
|
106
|
+
if actions.include?(:crud)
|
107
|
+
DEPENDENCIES_MAP.values.each { |action| self.include(action) }
|
108
|
+
else
|
109
|
+
actions.each do |action|
|
110
|
+
self.include(DEPENDENCIES_MAP[action])
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def model_klass
|
117
|
+
self.class.model_klass
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
require 'simple_crudify/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'simple_crudify'
|
9
|
+
spec.version = SimpleCrudify::VERSION
|
10
|
+
spec.authors = ['Dmitriy Strukov']
|
11
|
+
spec.email = ['dmitiry_strukov2011@mail.ru']
|
12
|
+
|
13
|
+
spec.summary = 'simple_crudify'
|
14
|
+
spec.description = 'simple_crudify'
|
15
|
+
spec.homepage = 'https://github.com/getsimpleadmin/simple_crudify'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
|
21
|
+
spec.bindir = 'exe'
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ['lib']
|
24
|
+
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
26
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simple_crudify
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dmitriy Strukov
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-01-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: simple_crudify
|
42
|
+
email:
|
43
|
+
- dmitiry_strukov2011@mail.ru
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- ".rspec"
|
50
|
+
- CODE_OF_CONDUCT.md
|
51
|
+
- Gemfile
|
52
|
+
- Gemfile.lock
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- bin/console
|
56
|
+
- bin/setup
|
57
|
+
- lib/simple_crudify.rb
|
58
|
+
- lib/simple_crudify/crudify.rb
|
59
|
+
- lib/simple_crudify/version.rb
|
60
|
+
- simple_crudify.gemspec
|
61
|
+
homepage: https://github.com/getsimpleadmin/simple_crudify
|
62
|
+
licenses: []
|
63
|
+
metadata: {}
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 2.6.11
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: simple_crudify
|
84
|
+
test_files: []
|