zertico 0.0.1.alpha1
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/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/zertico.rb +7 -0
- data/lib/zertico/controller.rb +51 -0
- data/lib/zertico/service.rb +41 -0
- data/lib/zertico/version.rb +3 -0
- data/spec/fake_app/user.rb +2 -0
- data/spec/fake_app/user_controller.rb +2 -0
- data/spec/fake_app/user_service.rb +6 -0
- data/spec/spec_helper.rb +7 -0
- data/spec/zertico/controller_spec.rb +109 -0
- data/spec/zertico/service_spec.rb +74 -0
- data/zertico.gemspec +22 -0
- metadata +105 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour --format documentation --profile
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
zertico
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-1.9.3
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Paulo Henrique Lopes Ribeiro
|
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
|
+
# Zertico
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'zertico'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install zertico
|
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 'Add 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 "bundler/gem_tasks"
|
data/lib/zertico.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
module Zertico
|
2
|
+
class Controller
|
3
|
+
def initialize
|
4
|
+
begin
|
5
|
+
extend "::#{self.class.name.chomp("Controller").concat("Service")}".constantize
|
6
|
+
rescue NameError
|
7
|
+
extend Zertico::Service
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def index
|
12
|
+
initialize_object all
|
13
|
+
end
|
14
|
+
|
15
|
+
def new
|
16
|
+
initialize_object build
|
17
|
+
end
|
18
|
+
|
19
|
+
def show
|
20
|
+
initialize_object find(params[:id])
|
21
|
+
end
|
22
|
+
|
23
|
+
def edit
|
24
|
+
initialize_object find(params[:id])
|
25
|
+
end
|
26
|
+
|
27
|
+
def create
|
28
|
+
initialize_object generate(params[interface_name.to_sym])
|
29
|
+
respond_with(instance_variable_get(@object_name))
|
30
|
+
end
|
31
|
+
|
32
|
+
def update
|
33
|
+
initialize_object modify(params[:id], params[interface_name.to_sym])
|
34
|
+
respond_with(instance_variable_get(@object_name))
|
35
|
+
end
|
36
|
+
|
37
|
+
def destroy
|
38
|
+
initialize_object delete(params[:id])
|
39
|
+
respond_with(instance_variable_get(@object_name))
|
40
|
+
end
|
41
|
+
|
42
|
+
protected
|
43
|
+
|
44
|
+
def initialize_object(object = {})
|
45
|
+
object.each do |key, value|
|
46
|
+
@object_name = "@#{key}"
|
47
|
+
instance_variable_set(@object_name, value)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Zertico
|
2
|
+
module Service
|
3
|
+
def all
|
4
|
+
{ interface_name.pluralize.to_sym => interface_class.all }
|
5
|
+
end
|
6
|
+
|
7
|
+
def build
|
8
|
+
{ interface_name.to_sym => interface_class.new }
|
9
|
+
end
|
10
|
+
|
11
|
+
def find(id)
|
12
|
+
{ interface_name.to_sym => interface_class.find(id) }
|
13
|
+
end
|
14
|
+
|
15
|
+
def generate(attributes = {})
|
16
|
+
{ interface_name.to_sym => interface_class.create(attributes) }
|
17
|
+
end
|
18
|
+
|
19
|
+
def modify(id, attributes = {})
|
20
|
+
object = self.find(id)
|
21
|
+
object.update_attributes(attributes)
|
22
|
+
{ interface_name.to_sym => object }
|
23
|
+
end
|
24
|
+
|
25
|
+
def delete(id)
|
26
|
+
object = self.find(id)
|
27
|
+
object.destroy
|
28
|
+
{ interface_name.to_sym => object }
|
29
|
+
end
|
30
|
+
|
31
|
+
protected
|
32
|
+
|
33
|
+
def interface_name
|
34
|
+
self.name.chomp("Service").underscore
|
35
|
+
end
|
36
|
+
|
37
|
+
def interface_class
|
38
|
+
self.interface_name.constantize
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Zertico::Controller do
|
4
|
+
let(:controller) { Zertico::Controller.new }
|
5
|
+
let(:user_controller) { UserController.new }
|
6
|
+
|
7
|
+
context "without a custom service" do
|
8
|
+
it "should extend Zertico::Service" do
|
9
|
+
controller.should respond_to :all
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
context "with a custom service" do
|
14
|
+
it "should extend Zertico::Service" do
|
15
|
+
user_controller.should respond_to :all
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should extend it!" do
|
19
|
+
user_controller.should respond_to :user
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "#index" do
|
24
|
+
before :each do
|
25
|
+
controller.stub(:all).and_return({ :user => "user" })
|
26
|
+
controller.index
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should initialize a collection of objects" do
|
30
|
+
controller.instance_variable_get("@user").should == "user"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "#new" do
|
35
|
+
before :each do
|
36
|
+
controller.stub(:build).and_return({ :user => "user" })
|
37
|
+
controller.new
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should initialize an object" do
|
41
|
+
controller.instance_variable_get("@user").should == "user"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context "#show" do
|
46
|
+
before :each do
|
47
|
+
controller.stub(:params).and_return({ :id => 1 })
|
48
|
+
controller.stub(:find).and_return({ :user => "user" })
|
49
|
+
controller.show
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should initialize an object" do
|
53
|
+
controller.instance_variable_get("@user").should == "user"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "#edit" do
|
58
|
+
before :each do
|
59
|
+
controller.stub(:params).and_return({ :id => 1 })
|
60
|
+
controller.stub(:find).and_return({ :user => "user" })
|
61
|
+
controller.edit
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should initialize an object" do
|
65
|
+
controller.instance_variable_get("@user").should == "user"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context "#create" do
|
70
|
+
before :each do
|
71
|
+
controller.stub_chain(:interface_name, :to_sym).and_return(:user)
|
72
|
+
controller.stub(:params).and_return({ :user => "user" })
|
73
|
+
controller.stub(:generate => { :user => "user" } )
|
74
|
+
controller.stub(:respond_with)
|
75
|
+
controller.create
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should create an object" do
|
79
|
+
controller.instance_variable_get("@user").should == "user"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
context "#update" do
|
84
|
+
before :each do
|
85
|
+
controller.stub(:interface_name, :to_sym).and_return(:user)
|
86
|
+
controller.stub(:params).and_return({:id => 1, :user => "user" })
|
87
|
+
controller.stub(:modify => { :user => "user" })
|
88
|
+
controller.stub(:respond_with)
|
89
|
+
controller.update
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should update an object" do
|
93
|
+
controller.instance_variable_get("@user").should == "user"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context "#destroy" do
|
98
|
+
before :each do
|
99
|
+
controller.stub(:params).and_return({:id => 1})
|
100
|
+
controller.stub(:delete => { :user => "user" })
|
101
|
+
controller.stub(:respond_with)
|
102
|
+
controller.destroy
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should destroy an object" do
|
106
|
+
controller.instance_variable_get("@user").should == "user"
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Zertico::Service do
|
4
|
+
let(:controller) { Zertico::Controller.new }
|
5
|
+
let(:object) { Object.new }
|
6
|
+
|
7
|
+
context "#all" do
|
8
|
+
before :each do
|
9
|
+
controller.stub_chain(:interface_name, :pluralize, :to_sym).and_return(:users)
|
10
|
+
controller.stub_chain(:interface_class, :all).and_return([])
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should return a collection of objects" do
|
14
|
+
controller.all.should == { :users => [] }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context "#build" do
|
19
|
+
before :each do
|
20
|
+
controller.stub_chain(:interface_name, :to_sym).and_return(:user)
|
21
|
+
controller.stub_chain(:interface_class, :new).and_return(object)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should return a new object" do
|
25
|
+
controller.build.should == { :user => object }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "#find" do
|
30
|
+
before :each do
|
31
|
+
controller.stub_chain(:interface_name, :to_sym).and_return(:user)
|
32
|
+
controller.stub_chain(:interface_class, :find).with(1).and_return(object)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should return the specified object" do
|
36
|
+
controller.find(1).should == { :user => object }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "#generate" do
|
41
|
+
before :each do
|
42
|
+
controller.stub_chain(:interface_name, :to_sym).and_return(:user)
|
43
|
+
controller.stub_chain(:interface_class, :create).with({}).and_return(object)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should return the created object" do
|
47
|
+
controller.generate({}).should == { :user => object }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context "#modify" do
|
52
|
+
before :each do
|
53
|
+
controller.stub(:find).with(1).and_return(object)
|
54
|
+
object.stub(:update_attributes).with({}).and_return(true)
|
55
|
+
controller.stub_chain(:interface_name, :to_sym).and_return(:user)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should return the updated object" do
|
59
|
+
controller.modify(1, {}).should == { :user => object }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context "#delete" do
|
64
|
+
before :each do
|
65
|
+
controller.stub(:find).with(1).and_return(object)
|
66
|
+
object.stub(:destroy).and_return(true)
|
67
|
+
controller.stub_chain(:interface_name, :to_sym).and_return(:user)
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should return the destroyed object" do
|
71
|
+
controller.delete(1).should == { :user => object }
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
data/zertico.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'zertico/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "zertico"
|
8
|
+
gem.version = Zertico::VERSION
|
9
|
+
gem.authors = ["Paulo Henrique Lopes Ribeiro"]
|
10
|
+
gem.email = ["plribeiro3000@gmail.com"]
|
11
|
+
gem.description = %q{Easy Rails development using the Zertico Way}
|
12
|
+
gem.summary = %q{Models and patterns used by Zertico}
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_runtime_dependency "rails"
|
21
|
+
gem.add_development_dependency "rspec"
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: zertico
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1.alpha1
|
5
|
+
prerelease: 6
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Paulo Henrique Lopes Ribeiro
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-05-25 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
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: rspec
|
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
|
+
description: Easy Rails development using the Zertico Way
|
47
|
+
email:
|
48
|
+
- plribeiro3000@gmail.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- .rspec
|
55
|
+
- .ruby-gemset
|
56
|
+
- .ruby-version
|
57
|
+
- Gemfile
|
58
|
+
- LICENSE.txt
|
59
|
+
- README.md
|
60
|
+
- Rakefile
|
61
|
+
- lib/zertico.rb
|
62
|
+
- lib/zertico/controller.rb
|
63
|
+
- lib/zertico/service.rb
|
64
|
+
- lib/zertico/version.rb
|
65
|
+
- spec/fake_app/user.rb
|
66
|
+
- spec/fake_app/user_controller.rb
|
67
|
+
- spec/fake_app/user_service.rb
|
68
|
+
- spec/spec_helper.rb
|
69
|
+
- spec/zertico/controller_spec.rb
|
70
|
+
- spec/zertico/service_spec.rb
|
71
|
+
- zertico.gemspec
|
72
|
+
homepage: ''
|
73
|
+
licenses: []
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ! '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
segments:
|
85
|
+
- 0
|
86
|
+
hash: -2073581164426693548
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ! '>'
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: 1.3.1
|
93
|
+
requirements: []
|
94
|
+
rubyforge_project:
|
95
|
+
rubygems_version: 1.8.25
|
96
|
+
signing_key:
|
97
|
+
specification_version: 3
|
98
|
+
summary: Models and patterns used by Zertico
|
99
|
+
test_files:
|
100
|
+
- spec/fake_app/user.rb
|
101
|
+
- spec/fake_app/user_controller.rb
|
102
|
+
- spec/fake_app/user_service.rb
|
103
|
+
- spec/spec_helper.rb
|
104
|
+
- spec/zertico/controller_spec.rb
|
105
|
+
- spec/zertico/service_spec.rb
|