guise 0.2.0 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Appraisals +7 -0
- data/README.md +14 -17
- data/Rakefile +9 -1
- data/gemfiles/3.1.gemfile +7 -0
- data/gemfiles/3.1.gemfile.lock +56 -0
- data/gemfiles/3.2.gemfile +7 -0
- data/gemfiles/3.2.gemfile.lock +56 -0
- data/guise.gemspec +8 -3
- data/lib/guise/introspection.rb +1 -1
- data/lib/guise/version.rb +1 -1
- data/lib/guise.rb +4 -2
- metadata +42 -15
data/Appraisals
ADDED
data/README.md
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
|
3
3
|
An alternative to storing role resources in the database.
|
4
4
|
|
5
|
-
guise delegates type information to
|
6
|
-
can be instantiated as. In essence, it's similar to
|
7
|
-
but with multiple inheritances possible.
|
5
|
+
guise delegates type information to a `has_many` association that stores the
|
6
|
+
class names a resource can be instantiated as. In essence, it's similar to
|
7
|
+
single table inheritance, but with multiple inheritances possible.
|
8
8
|
|
9
9
|
|
10
10
|
## Installation
|
@@ -33,16 +33,19 @@ $ gem install guise
|
|
33
33
|
Create a table to store your type information:
|
34
34
|
|
35
35
|
```
|
36
|
-
rails generate model
|
36
|
+
rails generate model user_role user:references title:string
|
37
37
|
rake db:migrate
|
38
38
|
```
|
39
39
|
|
40
40
|
Then add call the `has_guises` method in your model. This will setup the
|
41
|
-
`has_many` association for you.
|
41
|
+
`has_many` association for you. It requires the name of the association and
|
42
|
+
name of the column that the sublcass name will be stored in.
|
42
43
|
|
43
44
|
```ruby
|
44
45
|
class User < ActiveRecord::Base
|
45
|
-
has_guises :DeskWorker, :MailFowarder
|
46
|
+
has_guises :DeskWorker, :MailFowarder,
|
47
|
+
:association => :user_roles,
|
48
|
+
:attribute => :title
|
46
49
|
end
|
47
50
|
```
|
48
51
|
|
@@ -55,13 +58,13 @@ This adds the following methods to the `User` class:
|
|
55
58
|
And creates classes `DeskWorker` and `MailForwarder` that:
|
56
59
|
* Inherit from `User`.
|
57
60
|
* Have default scopes for `:desk_workers` and `:mail_forwarders` respectively.
|
58
|
-
* Create users with the right associated
|
61
|
+
* Create users with the right associated type.
|
59
62
|
|
60
63
|
|
61
64
|
To configure the other end of the association, add `guise_for`:
|
62
65
|
|
63
66
|
```ruby
|
64
|
-
class
|
67
|
+
class UserRole < ActiveRecord::Base
|
65
68
|
guise_for :user
|
66
69
|
end
|
67
70
|
```
|
@@ -74,8 +77,9 @@ This method does the following:
|
|
74
77
|
|
75
78
|
### Customization
|
76
79
|
|
77
|
-
If the association doesn't
|
78
|
-
`has_many` into `has_guises`. The same applies to `guise_for`
|
80
|
+
If the association doesn't standard association assumptions, you can pass in
|
81
|
+
the options for `has_many` into `has_guises`. The same applies to `guise_for`
|
82
|
+
with the addition that you can specify not to validate attributes.
|
79
83
|
|
80
84
|
```ruby
|
81
85
|
class Person < ActiveRecord::Base
|
@@ -92,10 +96,3 @@ class JobTitle < ActiveRecord::Base
|
|
92
96
|
:validate => false # skip setting up validations
|
93
97
|
end
|
94
98
|
```
|
95
|
-
|
96
|
-
|
97
|
-
## The Future
|
98
|
-
|
99
|
-
* Provide generators for roles table
|
100
|
-
* Update `has_guises` method to setup `has_many` association
|
101
|
-
* Adding validations on `guise_attribute` column into association class
|
data/Rakefile
CHANGED
@@ -1,2 +1,10 @@
|
|
1
1
|
#!/usr/bin/env rake
|
2
|
-
require
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
require 'appraisal'
|
6
|
+
|
7
|
+
desc "Run specs"
|
8
|
+
RSpec::Core::RakeTask.new('spec') do |task|
|
9
|
+
task.pattern = 'spec/**/*_spec.rb'
|
10
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
PATH
|
2
|
+
remote: /Users/edd_d/dev/guise
|
3
|
+
specs:
|
4
|
+
guise (0.2.0)
|
5
|
+
activerecord (~> 3.1)
|
6
|
+
activesupport (~> 3.1)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activemodel (3.1.4)
|
12
|
+
activesupport (= 3.1.4)
|
13
|
+
builder (~> 3.0.0)
|
14
|
+
i18n (~> 0.6)
|
15
|
+
activerecord (3.1.4)
|
16
|
+
activemodel (= 3.1.4)
|
17
|
+
activesupport (= 3.1.4)
|
18
|
+
arel (~> 2.2.3)
|
19
|
+
tzinfo (~> 0.3.29)
|
20
|
+
activesupport (3.1.4)
|
21
|
+
multi_json (~> 1.0)
|
22
|
+
appraisal (0.4.1)
|
23
|
+
bundler
|
24
|
+
rake
|
25
|
+
arel (2.2.3)
|
26
|
+
builder (3.0.0)
|
27
|
+
diff-lcs (1.1.3)
|
28
|
+
factory_girl (3.2.0)
|
29
|
+
activesupport (>= 3.0.0)
|
30
|
+
i18n (0.6.0)
|
31
|
+
multi_json (1.3.4)
|
32
|
+
rake (0.9.2.2)
|
33
|
+
rspec (2.10.0)
|
34
|
+
rspec-core (~> 2.10.0)
|
35
|
+
rspec-expectations (~> 2.10.0)
|
36
|
+
rspec-mocks (~> 2.10.0)
|
37
|
+
rspec-core (2.10.0)
|
38
|
+
rspec-expectations (2.10.0)
|
39
|
+
diff-lcs (~> 1.1.3)
|
40
|
+
rspec-mocks (2.10.1)
|
41
|
+
shoulda-matchers (1.1.0)
|
42
|
+
activesupport (>= 3.0.0)
|
43
|
+
sqlite3 (1.3.6)
|
44
|
+
tzinfo (0.3.33)
|
45
|
+
|
46
|
+
PLATFORMS
|
47
|
+
ruby
|
48
|
+
|
49
|
+
DEPENDENCIES
|
50
|
+
activerecord (= 3.1.4)
|
51
|
+
appraisal
|
52
|
+
factory_girl (~> 3.2)
|
53
|
+
guise!
|
54
|
+
rspec (~> 2.9)
|
55
|
+
shoulda-matchers (~> 1.1)
|
56
|
+
sqlite3 (~> 1.3.3)
|
@@ -0,0 +1,56 @@
|
|
1
|
+
PATH
|
2
|
+
remote: /Users/edd_d/dev/guise
|
3
|
+
specs:
|
4
|
+
guise (0.2.0)
|
5
|
+
activerecord (~> 3.1)
|
6
|
+
activesupport (~> 3.1)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activemodel (3.2.3)
|
12
|
+
activesupport (= 3.2.3)
|
13
|
+
builder (~> 3.0.0)
|
14
|
+
activerecord (3.2.3)
|
15
|
+
activemodel (= 3.2.3)
|
16
|
+
activesupport (= 3.2.3)
|
17
|
+
arel (~> 3.0.2)
|
18
|
+
tzinfo (~> 0.3.29)
|
19
|
+
activesupport (3.2.3)
|
20
|
+
i18n (~> 0.6)
|
21
|
+
multi_json (~> 1.0)
|
22
|
+
appraisal (0.4.1)
|
23
|
+
bundler
|
24
|
+
rake
|
25
|
+
arel (3.0.2)
|
26
|
+
builder (3.0.0)
|
27
|
+
diff-lcs (1.1.3)
|
28
|
+
factory_girl (3.2.0)
|
29
|
+
activesupport (>= 3.0.0)
|
30
|
+
i18n (0.6.0)
|
31
|
+
multi_json (1.3.4)
|
32
|
+
rake (0.9.2.2)
|
33
|
+
rspec (2.10.0)
|
34
|
+
rspec-core (~> 2.10.0)
|
35
|
+
rspec-expectations (~> 2.10.0)
|
36
|
+
rspec-mocks (~> 2.10.0)
|
37
|
+
rspec-core (2.10.0)
|
38
|
+
rspec-expectations (2.10.0)
|
39
|
+
diff-lcs (~> 1.1.3)
|
40
|
+
rspec-mocks (2.10.1)
|
41
|
+
shoulda-matchers (1.1.0)
|
42
|
+
activesupport (>= 3.0.0)
|
43
|
+
sqlite3 (1.3.6)
|
44
|
+
tzinfo (0.3.33)
|
45
|
+
|
46
|
+
PLATFORMS
|
47
|
+
ruby
|
48
|
+
|
49
|
+
DEPENDENCIES
|
50
|
+
activerecord (= 3.2.3)
|
51
|
+
appraisal
|
52
|
+
factory_girl (~> 3.2)
|
53
|
+
guise!
|
54
|
+
rspec (~> 2.9)
|
55
|
+
shoulda-matchers (~> 1.1)
|
56
|
+
sqlite3 (~> 1.3.3)
|
data/guise.gemspec
CHANGED
@@ -4,8 +4,11 @@ require File.expand_path('../lib/guise/version', __FILE__)
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
5
|
gem.authors = ["Eduardo Gutierrez"]
|
6
6
|
gem.email = ["edd_d@mit.edu"]
|
7
|
-
gem.description = %q{
|
8
|
-
gem.summary = %q{
|
7
|
+
gem.description = %q{ Multiple inheritance STI }
|
8
|
+
gem.summary = %q{
|
9
|
+
Guise provides methods to setup single table
|
10
|
+
inheritance with multiple inheritances possible.
|
11
|
+
}
|
9
12
|
gem.homepage = "https://github.com/ecbypi/guise"
|
10
13
|
|
11
14
|
gem.files = `git ls-files`.split($\)
|
@@ -15,9 +18,11 @@ Gem::Specification.new do |gem|
|
|
15
18
|
gem.require_paths = ["lib"]
|
16
19
|
gem.version = Guise::VERSION
|
17
20
|
|
18
|
-
gem.add_dependency "activerecord", "~> 3.
|
21
|
+
gem.add_dependency "activerecord", "~> 3.1"
|
22
|
+
gem.add_dependency "activesupport", "~> 3.1"
|
19
23
|
gem.add_development_dependency "rspec", "~> 2.9"
|
20
24
|
gem.add_development_dependency "sqlite3", "~> 1.3.3"
|
21
25
|
gem.add_development_dependency "factory_girl", "~> 3.2"
|
22
26
|
gem.add_development_dependency "shoulda-matchers", "~> 1.1"
|
27
|
+
gem.add_development_dependency "appraisal"
|
23
28
|
end
|
data/lib/guise/introspection.rb
CHANGED
data/lib/guise/version.rb
CHANGED
data/lib/guise.rb
CHANGED
@@ -24,7 +24,7 @@ module Guise
|
|
24
24
|
|
25
25
|
def guise_for(name, options = {})
|
26
26
|
association = Object.const_get(name.to_s.classify)
|
27
|
-
foreign_key = options[:foreign_key] || "#{association.name}_id"
|
27
|
+
foreign_key = options[:foreign_key] || "#{association.name.underscore}_id"
|
28
28
|
|
29
29
|
belongs_to name, options
|
30
30
|
|
@@ -74,4 +74,6 @@ module Guise
|
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
|
-
ActiveRecord
|
77
|
+
if defined?(ActiveRecord)
|
78
|
+
ActiveRecord::Base.extend Guise
|
79
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guise
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,18 +13,29 @@ date: 2012-05-11 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
16
|
-
requirement: &
|
16
|
+
requirement: &70169931214160 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: '3.
|
21
|
+
version: '3.1'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70169931214160
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: activesupport
|
27
|
+
requirement: &70169931213600 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '3.1'
|
22
33
|
type: :runtime
|
23
34
|
prerelease: false
|
24
|
-
version_requirements: *
|
35
|
+
version_requirements: *70169931213600
|
25
36
|
- !ruby/object:Gem::Dependency
|
26
37
|
name: rspec
|
27
|
-
requirement: &
|
38
|
+
requirement: &70169931213120 !ruby/object:Gem::Requirement
|
28
39
|
none: false
|
29
40
|
requirements:
|
30
41
|
- - ~>
|
@@ -32,10 +43,10 @@ dependencies:
|
|
32
43
|
version: '2.9'
|
33
44
|
type: :development
|
34
45
|
prerelease: false
|
35
|
-
version_requirements: *
|
46
|
+
version_requirements: *70169931213120
|
36
47
|
- !ruby/object:Gem::Dependency
|
37
48
|
name: sqlite3
|
38
|
-
requirement: &
|
49
|
+
requirement: &70169931212520 !ruby/object:Gem::Requirement
|
39
50
|
none: false
|
40
51
|
requirements:
|
41
52
|
- - ~>
|
@@ -43,10 +54,10 @@ dependencies:
|
|
43
54
|
version: 1.3.3
|
44
55
|
type: :development
|
45
56
|
prerelease: false
|
46
|
-
version_requirements: *
|
57
|
+
version_requirements: *70169931212520
|
47
58
|
- !ruby/object:Gem::Dependency
|
48
59
|
name: factory_girl
|
49
|
-
requirement: &
|
60
|
+
requirement: &70169931211960 !ruby/object:Gem::Requirement
|
50
61
|
none: false
|
51
62
|
requirements:
|
52
63
|
- - ~>
|
@@ -54,10 +65,10 @@ dependencies:
|
|
54
65
|
version: '3.2'
|
55
66
|
type: :development
|
56
67
|
prerelease: false
|
57
|
-
version_requirements: *
|
68
|
+
version_requirements: *70169931211960
|
58
69
|
- !ruby/object:Gem::Dependency
|
59
70
|
name: shoulda-matchers
|
60
|
-
requirement: &
|
71
|
+
requirement: &70169931234980 !ruby/object:Gem::Requirement
|
61
72
|
none: false
|
62
73
|
requirements:
|
63
74
|
- - ~>
|
@@ -65,8 +76,19 @@ dependencies:
|
|
65
76
|
version: '1.1'
|
66
77
|
type: :development
|
67
78
|
prerelease: false
|
68
|
-
version_requirements: *
|
69
|
-
|
79
|
+
version_requirements: *70169931234980
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: appraisal
|
82
|
+
requirement: &70169931234440 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *70169931234440
|
91
|
+
description: ! ' Multiple inheritance STI '
|
70
92
|
email:
|
71
93
|
- edd_d@mit.edu
|
72
94
|
executables: []
|
@@ -75,10 +97,15 @@ extra_rdoc_files: []
|
|
75
97
|
files:
|
76
98
|
- .gitignore
|
77
99
|
- .rspec
|
100
|
+
- Appraisals
|
78
101
|
- Gemfile
|
79
102
|
- LICENSE
|
80
103
|
- README.md
|
81
104
|
- Rakefile
|
105
|
+
- gemfiles/3.1.gemfile
|
106
|
+
- gemfiles/3.1.gemfile.lock
|
107
|
+
- gemfiles/3.2.gemfile
|
108
|
+
- gemfiles/3.2.gemfile.lock
|
82
109
|
- guise.gemspec
|
83
110
|
- lib/guise.rb
|
84
111
|
- lib/guise/introspection.rb
|
@@ -111,8 +138,8 @@ rubyforge_project:
|
|
111
138
|
rubygems_version: 1.8.11
|
112
139
|
signing_key:
|
113
140
|
specification_version: 3
|
114
|
-
summary: Guise provides
|
115
|
-
|
141
|
+
summary: Guise provides methods to setup single table inheritance with multiple inheritances
|
142
|
+
possible.
|
116
143
|
test_files:
|
117
144
|
- spec/factories.rb
|
118
145
|
- spec/guise_spec.rb
|