toy-locomotive 0.2.0 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.md +4 -0
- data/Rakefile +27 -3
- data/lib/tasks/toy-locomotive_tasks.rake +4 -0
- data/lib/toy-locomotive.rb +4 -22
- data/lib/toy-locomotive/router.rb +10 -0
- data/lib/toy-locomotive/version.rb +1 -1
- metadata +53 -47
- data/.gitignore +0 -6
- data/Gemfile +0 -4
- data/Gemfile.lock +0 -114
- data/lib/toy-locomotive/attributes/chain.rb +0 -65
- data/lib/toy-locomotive/attributes/model.rb +0 -23
- data/lib/toy-locomotive/attributes/observer.rb +0 -43
- data/lib/toy-locomotive/auto_views/form.rb +0 -54
- data/lib/toy-locomotive/auto_views/show.rb +0 -19
- data/lib/toy-locomotive/initializer.rb +0 -20
- data/lib/toy-locomotive/resources/controller.rb +0 -101
- data/lib/toy-locomotive/router/block.rb +0 -13
- data/lib/toy-locomotive/router/controller.rb +0 -134
- data/lib/toy-locomotive/router/model.rb +0 -40
- data/readme +0 -15
- data/spec/lib/attribute_chain_spec.rb +0 -40
- data/spec/lib/attribute_model_spec.rb +0 -10
- data/spec/lib/resources_controller_spec.rb +0 -39
- data/spec/lib/router_controller_spec.rb +0 -108
- data/spec/lib/router_model_spec.rb +0 -49
- data/spec/lib/toy_locomotive_spec.rb +0 -7
- data/spec/spec_helper.rb +0 -6
- data/spec/support/controllers.rb +0 -30
- data/spec/support/models.rb +0 -16
- data/spec/support/schema.rb +0 -19
- data/spec/support/seeds.rb +0 -1
- data/toy-locomotive.gemspec +0 -28
data/readme
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
TOY LOCOMOTIVE?!
|
2
|
-
================
|
3
|
-
|
4
|
-
Toy locomotive is a gem that runs over Rails....but Why?
|
5
|
-
|
6
|
-
TO-DO
|
7
|
-
=====
|
8
|
-
|
9
|
-
* Better Documentation
|
10
|
-
* Add models like data_mapper
|
11
|
-
* Add a generator
|
12
|
-
* Simplify folder structure
|
13
|
-
* Block for extra routes
|
14
|
-
* Basic crud
|
15
|
-
* Lots more to make rails as simple as sinatra
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ToyLocomotive::Attributes::AttributeChain do
|
4
|
-
|
5
|
-
subject{ ToyLocomotive::Attributes::AttributeChain.new :title, Dog }
|
6
|
-
|
7
|
-
its(:parent){should == Dog}
|
8
|
-
its(:column){should == :title}
|
9
|
-
|
10
|
-
it "defaults as string" do
|
11
|
-
subject._as.should == :string
|
12
|
-
end
|
13
|
-
|
14
|
-
it "changes the type" do
|
15
|
-
subject.as(:text)._as == :text
|
16
|
-
end
|
17
|
-
|
18
|
-
it "use text_field as helper for strings as default" do
|
19
|
-
subject.as(:string).to_helper.should == :text_field
|
20
|
-
end
|
21
|
-
|
22
|
-
it "use text_area as helper for text as default" do
|
23
|
-
subject.as(:text).to_helper.should == :text_area
|
24
|
-
end
|
25
|
-
|
26
|
-
it "use hidden_field as helper for ids as default" do
|
27
|
-
attribute = ToyLocomotive::Attributes::AttributeChain.new :id, Dog
|
28
|
-
attribute.to_helper.should == :hidden_field
|
29
|
-
end
|
30
|
-
|
31
|
-
it "use hidden_field as helper for relational ids as default" do
|
32
|
-
attribute = ToyLocomotive::Attributes::AttributeChain.new :human_id, Dog
|
33
|
-
attribute.to_helper.should == :hidden_field
|
34
|
-
end
|
35
|
-
|
36
|
-
it "acepts new helper" do
|
37
|
-
subject.helper(:text_area).to_helper.should == :text_area
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe DogsController do
|
4
|
-
describe 'extract_resources' do
|
5
|
-
|
6
|
-
it 'acepts :all as param' do
|
7
|
-
DogsController.extract_resources(:all).should == [:index, :new, :create, :show, :edit, :update, :destroy]
|
8
|
-
end
|
9
|
-
it 'acepts :only as param' do
|
10
|
-
DogsController.extract_resources(only: [:index, :show]).should == [:index, :show]
|
11
|
-
end
|
12
|
-
it 'acepts :except as param' do
|
13
|
-
DogsController.extract_resources(except: [:index, :destroy]).should == [:new, :create, :show, :edit, :update]
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
describe 'set_action' do
|
18
|
-
it "executes index" do
|
19
|
-
DogsController.resources(only: [:index])
|
20
|
-
DogsController.new.index.class.should == Array
|
21
|
-
end
|
22
|
-
|
23
|
-
it "executes new" do
|
24
|
-
DogsController.resources(only: [:new])
|
25
|
-
DogsController.new.new.human.should == Human.first
|
26
|
-
end
|
27
|
-
|
28
|
-
it "executes show" do
|
29
|
-
DogsController.resources(only: [:show])
|
30
|
-
DogsController.new.show.should == Dog.first
|
31
|
-
end
|
32
|
-
|
33
|
-
it "executes edit" do
|
34
|
-
DogsController.resources(only: [:edit])
|
35
|
-
DogsController.new.show.should == Dog.first
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
39
|
-
end
|
@@ -1,108 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe DogsController do
|
4
|
-
|
5
|
-
subject { DogsController }
|
6
|
-
|
7
|
-
its(:extract_model) {should == Dog}
|
8
|
-
its(:extract_controller) {should == 'dogs'}
|
9
|
-
|
10
|
-
[:get, :put, :post, :delete].each {|via| it { should respond_to(via) }}
|
11
|
-
|
12
|
-
it "extracts vars" do
|
13
|
-
dog_controller = DogsController.new
|
14
|
-
dog_controller.extract_parent_vars[0].class.should == Alien
|
15
|
-
dog_controller.extract_parent_vars[1].class.should == Human
|
16
|
-
dog_controller.extract_member_var.class.should == Dog
|
17
|
-
dog_controller.extract_collection_var.class.should == Array
|
18
|
-
dog_controller.extract_collection_var.first.class.should == Dog
|
19
|
-
end
|
20
|
-
|
21
|
-
describe '.extract_action' do
|
22
|
-
it "recognizes the root" do
|
23
|
-
DogsController.extract_action('/').should == 'root'
|
24
|
-
end
|
25
|
-
|
26
|
-
it "returns the option :as if declared" do
|
27
|
-
DogsController.extract_action('lorem-ipsum', as: 'dolor-sit').should == 'dolor_sit'
|
28
|
-
end
|
29
|
-
|
30
|
-
it "returns the path if no options" do
|
31
|
-
DogsController.extract_action('lorem-ipsum').should == 'lorem_ipsum'
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
describe '.extract_as' do
|
36
|
-
it "returns the action if its absolute path" do
|
37
|
-
DogsController.extract_as('/lorem-ipsum').should == 'lorem_ipsum'
|
38
|
-
end
|
39
|
-
|
40
|
-
it "returns the chain as method if its relative path" do
|
41
|
-
DogsController.extract_as('lorem').should == 'lorem_alien_human_dog'
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
describe '.extract_path' do
|
46
|
-
it "returns itself if absolute path" do
|
47
|
-
DogsController.extract_path('/lorem').should == '/lorem'
|
48
|
-
end
|
49
|
-
|
50
|
-
it "matches relative path on member" do
|
51
|
-
DogsController.extract_path('lorem', on: 'member').should == '/aliens/:alien_id/humans/:human_id/dogs/:dog_id/lorem'
|
52
|
-
end
|
53
|
-
|
54
|
-
it "matches relative path on collection" do
|
55
|
-
DogsController.extract_path('lorem', on: 'collection').should == '/aliens/:alien_id/humans/:human_id/dogs/lorem'
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
describe '.get' do
|
60
|
-
it "adds a empty method" do
|
61
|
-
DogsController.get('/lorem'){}
|
62
|
-
DogsController.new.should respond_to(:lorem)
|
63
|
-
end
|
64
|
-
|
65
|
-
it "adds a method from a block" do
|
66
|
-
DogsController.get('/lorem') { 'lorem-ipsum' }
|
67
|
-
DogsController.new.lorem.should == 'lorem-ipsum'
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
describe 'resources' do
|
72
|
-
it "gets an index" do
|
73
|
-
DogsController.get('index') { 'index' }
|
74
|
-
DogsController.new.index.should == 'index'
|
75
|
-
end
|
76
|
-
|
77
|
-
it "gets a show" do
|
78
|
-
DogsController.get('show') { 'show' }
|
79
|
-
DogsController.new.show.should == 'show'
|
80
|
-
end
|
81
|
-
|
82
|
-
it "gets a new" do
|
83
|
-
DogsController.get('new') { 'new' }
|
84
|
-
DogsController.new.new.should == 'new'
|
85
|
-
end
|
86
|
-
|
87
|
-
it "gets a edit" do
|
88
|
-
DogsController.get('edit') { 'edit' }
|
89
|
-
DogsController.new.edit.should == 'edit'
|
90
|
-
end
|
91
|
-
|
92
|
-
it "puts a update" do
|
93
|
-
DogsController.put('update') { 'update' }
|
94
|
-
DogsController.new.update.should == 'update'
|
95
|
-
end
|
96
|
-
|
97
|
-
it "posts a create" do
|
98
|
-
DogsController.post('create') { 'create' }
|
99
|
-
DogsController.new.create.should == 'create'
|
100
|
-
end
|
101
|
-
|
102
|
-
it "deletes a destroy" do
|
103
|
-
DogsController.delete('destroy') { 'destroy' }
|
104
|
-
DogsController.new.destroy.should == 'destroy'
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Dog do
|
4
|
-
|
5
|
-
subject { Dog }
|
6
|
-
|
7
|
-
{ to_params: :dog_id,
|
8
|
-
to_collection_var: '@dogs',
|
9
|
-
to_member_var: '@dog',
|
10
|
-
to_route: '/dogs/:dog_id',
|
11
|
-
route_chain: '/aliens/:alien_id/humans/:human_id',
|
12
|
-
belongs_chain: [Human, Alien],
|
13
|
-
belongs_to_route: Human,
|
14
|
-
to_as: 'alien_human_dog'
|
15
|
-
}.each{|method, expectation| its(method) {should == expectation}}
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
describe Human do
|
20
|
-
|
21
|
-
subject { Human }
|
22
|
-
|
23
|
-
{ to_params: :human_id,
|
24
|
-
to_collection_var: '@humans',
|
25
|
-
to_member_var: '@human',
|
26
|
-
to_route: '/humans/:human_id',
|
27
|
-
route_chain: '/aliens/:alien_id',
|
28
|
-
belongs_chain: [Alien],
|
29
|
-
belongs_to_route: Alien,
|
30
|
-
to_as: 'alien_human'
|
31
|
-
}.each{|method, expectation| its(method) {should == expectation}}
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
describe Alien do
|
36
|
-
|
37
|
-
subject { Alien }
|
38
|
-
|
39
|
-
{ to_params: :alien_id,
|
40
|
-
to_collection_var: '@aliens',
|
41
|
-
to_member_var: '@alien',
|
42
|
-
to_route: '/aliens/:alien_id',
|
43
|
-
route_chain: '',
|
44
|
-
belongs_chain: [],
|
45
|
-
belongs_to_route: nil,
|
46
|
-
to_as: 'alien'
|
47
|
-
}.each{|method, expectation| its(method) {should == expectation}}
|
48
|
-
|
49
|
-
end
|
data/spec/spec_helper.rb
DELETED
data/spec/support/controllers.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
class DogsController < ActionController::Base
|
2
|
-
|
3
|
-
def params
|
4
|
-
{alien_id: Alien.first.id, human_id: Human.first.id, dog_id: Dog.first.id}
|
5
|
-
end
|
6
|
-
|
7
|
-
get '/absolute' do
|
8
|
-
'absolute route'
|
9
|
-
end
|
10
|
-
|
11
|
-
get 'member', on: 'member' do
|
12
|
-
'member route'
|
13
|
-
end
|
14
|
-
|
15
|
-
get 'collection', on: 'collection' do
|
16
|
-
'collection route'
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
20
|
-
DogsController.append_filters!
|
21
|
-
|
22
|
-
class HumansController < ActionController::Base
|
23
|
-
|
24
|
-
end
|
25
|
-
HumansController.append_filters!
|
26
|
-
|
27
|
-
class AliensController < ActionController::Base
|
28
|
-
|
29
|
-
end
|
30
|
-
AliensController.append_filters!
|
data/spec/support/models.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
class Dog < ActiveRecord::Base
|
2
|
-
belongs_to :human
|
3
|
-
end
|
4
|
-
|
5
|
-
class Human < ActiveRecord::Base
|
6
|
-
belongs_to :alien
|
7
|
-
has_many :dogs
|
8
|
-
end
|
9
|
-
|
10
|
-
class Alien < ActiveRecord::Base
|
11
|
-
has_many :humans
|
12
|
-
end
|
13
|
-
|
14
|
-
ActiveSupport::Inflector.inflections do |inflect|
|
15
|
-
inflect.irregular 'Human', 'Humans'
|
16
|
-
end
|
data/spec/support/schema.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
ActiveRecord::Schema.define do
|
2
|
-
|
3
|
-
self.verbose = false
|
4
|
-
|
5
|
-
create_table :dogs, :force => true do |t|
|
6
|
-
t.integer :human_id
|
7
|
-
t.timestamps
|
8
|
-
end
|
9
|
-
|
10
|
-
create_table :humans, :force => true do |t|
|
11
|
-
t.integer :alien_id
|
12
|
-
t.timestamps
|
13
|
-
end
|
14
|
-
|
15
|
-
create_table :aliens, :force => true do |t|
|
16
|
-
t.timestamps
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
data/spec/support/seeds.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
Alien.create.humans.create.dogs.create
|
data/toy-locomotive.gemspec
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
$:.push File.expand_path("../lib", __FILE__)
|
3
|
-
require "toy-locomotive/version"
|
4
|
-
|
5
|
-
Gem::Specification.new do |s|
|
6
|
-
|
7
|
-
s.name = "toy-locomotive"
|
8
|
-
s.version = ToyLocomotive::VERSION
|
9
|
-
s.authors = ["Christian Mortaro"]
|
10
|
-
s.email = ["mortaro@towsta.com"]
|
11
|
-
s.homepage = ""
|
12
|
-
s.summary = %q{a Toy Locomotive to run over Rails}
|
13
|
-
s.description = %q{a Different aproach to Rails applications}
|
14
|
-
|
15
|
-
s.rubyforge_project = "toy-locomotive"
|
16
|
-
|
17
|
-
s.files = `git ls-files`.split("\n")
|
18
|
-
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
-
s.require_paths = ["lib"]
|
21
|
-
|
22
|
-
s.add_dependency "rails"
|
23
|
-
|
24
|
-
s.add_development_dependency "rspec-rails"
|
25
|
-
s.add_development_dependency "sqlite3"
|
26
|
-
s.add_development_dependency "shoulda"
|
27
|
-
|
28
|
-
end
|