crud_for 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +4 -0
- data/Gemfile +3 -0
- data/Rakefile +3 -0
- data/crud_for.gemspec +23 -0
- data/lib/crud_for/methods.rb +61 -0
- data/lib/crud_for/railtie.rb +11 -0
- data/lib/crud_for/version.rb +3 -0
- data/lib/crud_for.rb +4 -0
- metadata +90 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
data/crud_for.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "crud_for/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "crud_for"
|
7
|
+
s.version = CrudFor::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Marcello Milhomem Albuquerque"]
|
10
|
+
s.email = ["marcello.m.albuquerque@gmail.com"]
|
11
|
+
s.homepage = "https://github.com/marcelloma/crud_for"
|
12
|
+
s.summary = %q{Simplifies CRUD development}
|
13
|
+
s.description = %q{Simplifies CRUD development}
|
14
|
+
|
15
|
+
s.rubyforge_project = "crud_for"
|
16
|
+
|
17
|
+
s.add_dependency('decent_exposure', "~> 1.0.1")
|
18
|
+
|
19
|
+
s.files = `git ls-files`.split("\n")
|
20
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
21
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
22
|
+
s.require_paths = ["lib"]
|
23
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Methods
|
2
|
+
|
3
|
+
def crud_for(model, options)
|
4
|
+
|
5
|
+
_options = {
|
6
|
+
:create => true,
|
7
|
+
:update => true,
|
8
|
+
:destroy => true,
|
9
|
+
:search => defined?(MetaSearch),
|
10
|
+
:paginate => defined?(WillPaginate)
|
11
|
+
}
|
12
|
+
|
13
|
+
_options.merge!(options)
|
14
|
+
|
15
|
+
expose(model.to_sym)
|
16
|
+
|
17
|
+
if _options[:paginate] && _options[:search]
|
18
|
+
expose(model.to_s.pluralize.to_sym) { search.paginate(:page => params[:page]) }
|
19
|
+
else
|
20
|
+
if _options[:paginate]
|
21
|
+
expose(model.to_s.pluralize.to_sym) { model.to_s.capitalize.constantize.paginate(:page => params[:page]) }
|
22
|
+
else
|
23
|
+
if _options[:search]
|
24
|
+
expose(model.to_s.pluralize.to_sym) { search.all }
|
25
|
+
else
|
26
|
+
expose(model.to_s.pluralize.to_sym) { model.to_s.capitalize.constantize.all }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
expose(:search) { model.to_s.capitalize.constantize.search(params[:search]) } if _options[:search]
|
32
|
+
|
33
|
+
self.class_eval %"
|
34
|
+
def create
|
35
|
+
if #{model}.save
|
36
|
+
redirect_to #{model.to_s.pluralize}_url, I18n.t(:create_success, :model => #{model.to_s.capitalize.constantize}.human_name)
|
37
|
+
else
|
38
|
+
render 'new'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
" if _options[:create]
|
42
|
+
|
43
|
+
self.class_eval %"
|
44
|
+
def update
|
45
|
+
if #{model}.update_attributes(params['#{model.to_sym}'])
|
46
|
+
redirect_to #{model.to_s.pluralize}_url, I18n.t(:update_success, :model => #{model.to_s.capitalize.constantize}.human_name)
|
47
|
+
else
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
51
|
+
" if _options[:update]
|
52
|
+
|
53
|
+
self.class_eval %"
|
54
|
+
def destroy
|
55
|
+
#{model}.destroy
|
56
|
+
redirect_to #{model.to_s.pluralize}_url, I18n.t(:destroy_success, :model => #{model.to_s.capitalize.constantize}.human_name)
|
57
|
+
end
|
58
|
+
" if _options[:destroy]
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
data/lib/crud_for.rb
ADDED
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: crud_for
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Marcello Milhomem Albuquerque
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-06-11 00:00:00 -03:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: decent_exposure
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 21
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 0
|
33
|
+
- 1
|
34
|
+
version: 1.0.1
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
description: Simplifies CRUD development
|
38
|
+
email:
|
39
|
+
- marcello.m.albuquerque@gmail.com
|
40
|
+
executables: []
|
41
|
+
|
42
|
+
extensions: []
|
43
|
+
|
44
|
+
extra_rdoc_files: []
|
45
|
+
|
46
|
+
files:
|
47
|
+
- .gitignore
|
48
|
+
- Gemfile
|
49
|
+
- Rakefile
|
50
|
+
- crud_for.gemspec
|
51
|
+
- lib/crud_for.rb
|
52
|
+
- lib/crud_for/methods.rb
|
53
|
+
- lib/crud_for/railtie.rb
|
54
|
+
- lib/crud_for/version.rb
|
55
|
+
has_rdoc: true
|
56
|
+
homepage: https://github.com/marcelloma/crud_for
|
57
|
+
licenses: []
|
58
|
+
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
hash: 3
|
70
|
+
segments:
|
71
|
+
- 0
|
72
|
+
version: "0"
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
hash: 3
|
79
|
+
segments:
|
80
|
+
- 0
|
81
|
+
version: "0"
|
82
|
+
requirements: []
|
83
|
+
|
84
|
+
rubyforge_project: crud_for
|
85
|
+
rubygems_version: 1.6.2
|
86
|
+
signing_key:
|
87
|
+
specification_version: 3
|
88
|
+
summary: Simplifies CRUD development
|
89
|
+
test_files: []
|
90
|
+
|