restful-controller 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 +17 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/lib/action_controller/base.rb +5 -0
- data/lib/restful-controller.rb +1 -0
- data/lib/restful_controller.rb +18 -0
- data/lib/restful_controller/actions/create.rb +9 -0
- data/lib/restful_controller/actions/destroy.rb +9 -0
- data/lib/restful_controller/actions/edit.rb +8 -0
- data/lib/restful_controller/actions/index.rb +9 -0
- data/lib/restful_controller/actions/new.rb +10 -0
- data/lib/restful_controller/actions/show.rb +8 -0
- data/lib/restful_controller/actions/update.rb +9 -0
- data/lib/restful_controller/base.rb +33 -0
- data/lib/restful_controller/filters.rb +8 -0
- data/lib/restful_controller/helpers.rb +28 -0
- data/lib/restful_controller/version.rb +3 -0
- data/restful-controller.gemspec +22 -0
- data/spec/restful-controller/base_spec.rb +1 -0
- data/spec/spec_helper.rb +3 -0
- metadata +140 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 TODO: Write your name
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# RestfulController
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'rest_controller'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install rest_controller
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'restful_controller'
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'action_controller/base'
|
2
|
+
|
3
|
+
require 'restful_controller/base'
|
4
|
+
require 'restful_controller/filters'
|
5
|
+
require 'restful_controller/helpers'
|
6
|
+
require 'restful_controller/version'
|
7
|
+
|
8
|
+
module RestfulController
|
9
|
+
module Actions
|
10
|
+
autoload :Show, 'restful_controller/actions/show'
|
11
|
+
autoload :Index, 'restful_controller/actions/index'
|
12
|
+
autoload :New, 'restful_controller/actions/new'
|
13
|
+
autoload :Edit, 'restful_controller/actions/edit'
|
14
|
+
autoload :Update, 'restful_controller/actions/update'
|
15
|
+
autoload :Destroy, 'restful_controller/actions/destroy'
|
16
|
+
autoload :Create, 'restful_controller/actions/create'
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module RestfulController
|
2
|
+
class Base
|
3
|
+
ACTIONS = [:index, :show, :edit, :update, :create, :destroy, :new]
|
4
|
+
|
5
|
+
def self.inject(base, actions = nil)
|
6
|
+
actions_to_include = actions_to_include(actions)
|
7
|
+
base.class_eval do
|
8
|
+
include Helpers
|
9
|
+
include Filters
|
10
|
+
actions_to_include.each do |action|
|
11
|
+
include "RestfulController::Actions::#{action.capitalize}".constantize
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
def self.actions_to_include(actions)
|
18
|
+
if actions.empty?
|
19
|
+
ACTIONS
|
20
|
+
elsif actions.length == 1 && actions.first.is_a?(Hash)
|
21
|
+
hash = actions.first
|
22
|
+
key = hash.keys.first
|
23
|
+
if key == :except
|
24
|
+
ACTIONS - Array(hash[key])
|
25
|
+
elsif key == :only
|
26
|
+
Array(hash[key])
|
27
|
+
end
|
28
|
+
else
|
29
|
+
actions
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module RestfulController
|
2
|
+
module Helpers
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
# set_post
|
7
|
+
define_method "set_#{model_name}" do
|
8
|
+
model = self.class.model_class.find(params[:id])
|
9
|
+
instance_variable_set("@#{self.class.model_name}", model)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def model_params
|
14
|
+
send("#{self.class.model_name}_params")
|
15
|
+
end
|
16
|
+
|
17
|
+
module ClassMethods
|
18
|
+
def model_name
|
19
|
+
controller_name.classify.downcase
|
20
|
+
end
|
21
|
+
|
22
|
+
def model_class
|
23
|
+
controller_name.classify.constantize
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/restful_controller/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Alexander Zaytsev"]
|
6
|
+
gem.email = ["alexander@say26.com"]
|
7
|
+
gem.description = %q{Restful Controllers for your Rails app}
|
8
|
+
gem.summary = %q{It's like scaffolding, but invisible}
|
9
|
+
gem.homepage = "https://github.com/AlexanderZaytsev/restful-controller"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "restful-controller"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = RestfulController::VERSION
|
17
|
+
|
18
|
+
gem.add_development_dependency 'rspec'
|
19
|
+
gem.add_development_dependency 'rake'
|
20
|
+
gem.add_development_dependency 'pry'
|
21
|
+
gem.add_development_dependency 'actionpack'
|
22
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'spec_helper'
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: restful-controller
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Alexander Zaytsev
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-19 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: pry
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: actionpack
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: Restful Controllers for your Rails app
|
79
|
+
email:
|
80
|
+
- alexander@say26.com
|
81
|
+
executables: []
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files: []
|
84
|
+
files:
|
85
|
+
- .gitignore
|
86
|
+
- .rspec
|
87
|
+
- Gemfile
|
88
|
+
- LICENSE
|
89
|
+
- README.md
|
90
|
+
- Rakefile
|
91
|
+
- lib/action_controller/base.rb
|
92
|
+
- lib/restful-controller.rb
|
93
|
+
- lib/restful_controller.rb
|
94
|
+
- lib/restful_controller/actions/create.rb
|
95
|
+
- lib/restful_controller/actions/destroy.rb
|
96
|
+
- lib/restful_controller/actions/edit.rb
|
97
|
+
- lib/restful_controller/actions/index.rb
|
98
|
+
- lib/restful_controller/actions/new.rb
|
99
|
+
- lib/restful_controller/actions/show.rb
|
100
|
+
- lib/restful_controller/actions/update.rb
|
101
|
+
- lib/restful_controller/base.rb
|
102
|
+
- lib/restful_controller/filters.rb
|
103
|
+
- lib/restful_controller/helpers.rb
|
104
|
+
- lib/restful_controller/version.rb
|
105
|
+
- restful-controller.gemspec
|
106
|
+
- spec/restful-controller/base_spec.rb
|
107
|
+
- spec/spec_helper.rb
|
108
|
+
homepage: https://github.com/AlexanderZaytsev/restful-controller
|
109
|
+
licenses: []
|
110
|
+
post_install_message:
|
111
|
+
rdoc_options: []
|
112
|
+
require_paths:
|
113
|
+
- lib
|
114
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
115
|
+
none: false
|
116
|
+
requirements:
|
117
|
+
- - ! '>='
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
segments:
|
121
|
+
- 0
|
122
|
+
hash: 1210353539489951881
|
123
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
+
none: false
|
125
|
+
requirements:
|
126
|
+
- - ! '>='
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
segments:
|
130
|
+
- 0
|
131
|
+
hash: 1210353539489951881
|
132
|
+
requirements: []
|
133
|
+
rubyforge_project:
|
134
|
+
rubygems_version: 1.8.24
|
135
|
+
signing_key:
|
136
|
+
specification_version: 3
|
137
|
+
summary: It's like scaffolding, but invisible
|
138
|
+
test_files:
|
139
|
+
- spec/restful-controller/base_spec.rb
|
140
|
+
- spec/spec_helper.rb
|