mongoid-included 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.rspec +1 -0
- data/.rvmrc +1 -1
- data/lib/mongoid-included/document_inclusion.rb +6 -4
- data/lib/mongoid-included/embedded_name.rb +25 -0
- data/lib/mongoid-included/version.rb +1 -1
- data/lib/mongoid-included.rb +2 -1
- data/spec/unit/included_spec.rb +23 -17
- metadata +52 -78
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color --format nested --fail-fast
|
data/.rvmrc
CHANGED
@@ -1 +1 @@
|
|
1
|
-
rvm
|
1
|
+
rvm ruby-head
|
@@ -32,10 +32,12 @@ module Mongoid
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def model_name
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
35
|
+
@_model_name ||=begin
|
36
|
+
if self.parent != Object
|
37
|
+
Mongoid::EmbeddedName.new(self, self.parent)
|
38
|
+
else
|
39
|
+
super
|
40
|
+
end
|
39
41
|
end
|
40
42
|
end
|
41
43
|
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Mongoid
|
2
|
+
class EmbeddedName < ActiveModel::Name
|
3
|
+
attr_reader :singular, :plural, :element, :collection, :partial_path, :route_key, :param_key, :i18n_key
|
4
|
+
alias_method :cache_key, :collection
|
5
|
+
|
6
|
+
def initialize(klass, namespace, pluralize_namespace = true)
|
7
|
+
name ||= klass.name
|
8
|
+
# super(name)
|
9
|
+
@unnamespaced = name.sub(/^#{namespace.name}::/, '') if namespace
|
10
|
+
|
11
|
+
@klass = klass
|
12
|
+
@singular = _singularize(name).freeze
|
13
|
+
@singular_namespace = _singularize(namespace.name).freeze
|
14
|
+
@plural = ActiveSupport::Inflector.pluralize(@singular).freeze
|
15
|
+
@plural_namespace = ActiveSupport::Inflector.pluralize(@singular_namespace).freeze
|
16
|
+
@element = ActiveSupport::Inflector.underscore(ActiveSupport::Inflector.demodulize(name)).freeze
|
17
|
+
@human = ActiveSupport::Inflector.humanize(@element).freeze
|
18
|
+
@collection = ActiveSupport::Inflector.tableize(name).freeze
|
19
|
+
@partial_path = "#{@collection.sub(@singular_namespace, @plural_namespace)}/#{@element}".freeze
|
20
|
+
@param_key = _singularize(@unnamespaced).freeze
|
21
|
+
@route_key = ActiveSupport::Inflector.pluralize(@param_key).freeze
|
22
|
+
@i18n_key = name.underscore.to_sym
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/mongoid-included.rb
CHANGED
data/spec/unit/included_spec.rb
CHANGED
@@ -59,23 +59,6 @@ describe "Mongoid::Included" do
|
|
59
59
|
Invoice::Item.relations["invoice"].macro.should == :embedded_in
|
60
60
|
end
|
61
61
|
|
62
|
-
it "strips namespace from param_key" do
|
63
|
-
Invoice::Item.model_name.param_key.should == "item"
|
64
|
-
end
|
65
|
-
|
66
|
-
it "strips namespace from #route_key" do
|
67
|
-
Invoice::Item.model_name.route_key.should == "items"
|
68
|
-
end
|
69
|
-
|
70
|
-
it "forbids inclusion in another parent" do
|
71
|
-
begin
|
72
|
-
Invoice::Item.included_in :invoice
|
73
|
-
rescue => e
|
74
|
-
e.class.should == Mongoid::DocumentInclusion::DocumentAlreadyIncluded
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
|
79
62
|
it "issues an error if parent is not mongoid document" do
|
80
63
|
Object.const_set "NonMongoidDocument", Class.new
|
81
64
|
NonMongoidDocument.const_set "NonMongoidParent", Class.new
|
@@ -101,6 +84,29 @@ describe "Mongoid::Included" do
|
|
101
84
|
end
|
102
85
|
end
|
103
86
|
|
87
|
+
context "when overwriting #model_name" do
|
88
|
+
it "strips namespace from #param_key" do
|
89
|
+
Invoice::Item.model_name.param_key.should == "item"
|
90
|
+
end
|
91
|
+
|
92
|
+
it "strips namespace from #route_key" do
|
93
|
+
Invoice::Item.model_name.route_key.should == "items"
|
94
|
+
end
|
95
|
+
|
96
|
+
it "pluralize namespace in #partial_path" do
|
97
|
+
Invoice::Item.model_name.partial_path.should == "invoices/items/item"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
it "forbids inclusion in another parent" do
|
102
|
+
begin
|
103
|
+
Invoice::Item.included_in :invoice
|
104
|
+
rescue => e
|
105
|
+
e.class.should == Mongoid::DocumentInclusion::DocumentAlreadyIncluded
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
|
104
110
|
end
|
105
111
|
|
106
112
|
end
|
metadata
CHANGED
@@ -1,91 +1,71 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-included
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 0
|
8
|
-
- 3
|
9
|
-
version: 0.0.3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.4
|
5
|
+
prerelease:
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
7
|
+
authors:
|
12
8
|
- Alexandre Angelim
|
13
9
|
autorequire:
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
|
-
|
17
|
-
date: 2011-07-05 00:00:00 -03:00
|
12
|
+
date: 2011-07-06 00:00:00.000000000 -03:00
|
18
13
|
default_executable:
|
19
|
-
dependencies:
|
20
|
-
- !ruby/object:Gem::Dependency
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
21
16
|
name: activemodel
|
22
|
-
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
17
|
+
requirement: &2160464360 !ruby/object:Gem::Requirement
|
24
18
|
none: false
|
25
|
-
requirements:
|
19
|
+
requirements:
|
26
20
|
- - ~>
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
segments:
|
29
|
-
- 3
|
30
|
-
- 1
|
31
|
-
- 0
|
32
|
-
- beta1
|
21
|
+
- !ruby/object:Gem::Version
|
33
22
|
version: 3.1.0.beta1
|
34
23
|
type: :runtime
|
35
|
-
version_requirements: *id001
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
name: mongoid
|
38
24
|
prerelease: false
|
39
|
-
|
25
|
+
version_requirements: *2160464360
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: mongoid
|
28
|
+
requirement: &2160463820 !ruby/object:Gem::Requirement
|
40
29
|
none: false
|
41
|
-
requirements:
|
30
|
+
requirements:
|
42
31
|
- - ~>
|
43
|
-
- !ruby/object:Gem::Version
|
44
|
-
|
45
|
-
- 2
|
46
|
-
- 0
|
47
|
-
version: "2.0"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
48
34
|
type: :runtime
|
49
|
-
version_requirements: *id002
|
50
|
-
- !ruby/object:Gem::Dependency
|
51
|
-
name: rspec
|
52
35
|
prerelease: false
|
53
|
-
|
36
|
+
version_requirements: *2160463820
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rspec
|
39
|
+
requirement: &2160463300 !ruby/object:Gem::Requirement
|
54
40
|
none: false
|
55
|
-
requirements:
|
41
|
+
requirements:
|
56
42
|
- - ~>
|
57
|
-
- !ruby/object:Gem::Version
|
58
|
-
|
59
|
-
- 2
|
60
|
-
- 6
|
61
|
-
version: "2.6"
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '2.6'
|
62
45
|
type: :development
|
63
|
-
version_requirements: *id003
|
64
|
-
- !ruby/object:Gem::Dependency
|
65
|
-
name: bson_ext
|
66
46
|
prerelease: false
|
67
|
-
|
47
|
+
version_requirements: *2160463300
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: bson_ext
|
50
|
+
requirement: &2160462780 !ruby/object:Gem::Requirement
|
68
51
|
none: false
|
69
|
-
requirements:
|
52
|
+
requirements:
|
70
53
|
- - ~>
|
71
|
-
- !ruby/object:Gem::Version
|
72
|
-
|
73
|
-
- 1
|
74
|
-
- 3
|
75
|
-
version: "1.3"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '1.3'
|
76
56
|
type: :development
|
77
|
-
|
78
|
-
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *2160462780
|
59
|
+
description: Helper to facilitate inclusion of namespaced documents in another Mongoid
|
60
|
+
Document
|
79
61
|
email: angelim@angelim.com.br
|
80
62
|
executables: []
|
81
|
-
|
82
63
|
extensions: []
|
83
|
-
|
84
64
|
extra_rdoc_files: []
|
85
|
-
|
86
|
-
files:
|
65
|
+
files:
|
87
66
|
- .document
|
88
67
|
- .gitignore
|
68
|
+
- .rspec
|
89
69
|
- .rvmrc
|
90
70
|
- Gemfile
|
91
71
|
- LICENSE
|
@@ -93,6 +73,7 @@ files:
|
|
93
73
|
- Rakefile
|
94
74
|
- lib/mongoid-included.rb
|
95
75
|
- lib/mongoid-included/document_inclusion.rb
|
76
|
+
- lib/mongoid-included/embedded_name.rb
|
96
77
|
- lib/mongoid-included/version.rb
|
97
78
|
- log/development.log
|
98
79
|
- mongoid-included.gemspec
|
@@ -107,36 +88,29 @@ files:
|
|
107
88
|
has_rdoc: true
|
108
89
|
homepage: http://github.com/angelim/mongoid-included
|
109
90
|
licenses: []
|
110
|
-
|
111
91
|
post_install_message:
|
112
92
|
rdoc_options: []
|
113
|
-
|
114
|
-
require_paths:
|
93
|
+
require_paths:
|
115
94
|
- lib
|
116
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
96
|
none: false
|
118
|
-
requirements:
|
119
|
-
- -
|
120
|
-
- !ruby/object:Gem::Version
|
121
|
-
|
122
|
-
|
123
|
-
version: "0"
|
124
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ! '>='
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
102
|
none: false
|
126
|
-
requirements:
|
127
|
-
- -
|
128
|
-
- !ruby/object:Gem::Version
|
129
|
-
|
130
|
-
- 0
|
131
|
-
version: "0"
|
103
|
+
requirements:
|
104
|
+
- - ! '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
132
107
|
requirements: []
|
133
|
-
|
134
108
|
rubyforge_project: mongoid-included
|
135
|
-
rubygems_version: 1.
|
109
|
+
rubygems_version: 1.6.2
|
136
110
|
signing_key:
|
137
111
|
specification_version: 3
|
138
112
|
summary: Included namespaces documents for Mongoid
|
139
|
-
test_files:
|
113
|
+
test_files:
|
140
114
|
- spec/functional/invoice.rb
|
141
115
|
- spec/functional/item.rb
|
142
116
|
- spec/models/inclusion.rb
|