betty_resource 0.0.15 → 0.0.16
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.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bdf799400eb031e8a42991aa8e2ee9b6d4687591
|
4
|
+
data.tar.gz: d6f47073026b86f3ce86263818095a601afa20b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 08fbca04440922885d21556a25620d845c4d002dde90addf451180073cade1669ffef3d1153b5e3ee6f296787807cc2e9d9f94ac5ee054ca22aa8418f7f5a21a
|
7
|
+
data.tar.gz: 99168e3923909cb6c18215d29adb4eec8a891857b6e90067e8e9faabc385cb78f4efbcb73369cc7ecc4aa2aef3430fdb452489e820971a233ea1026702f99fe9
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module BettyResource
|
2
|
+
class Model
|
3
|
+
class Property
|
4
|
+
module Types
|
5
|
+
module HasAndBelongsToMany
|
6
|
+
include Association
|
7
|
+
|
8
|
+
def collection?
|
9
|
+
true
|
10
|
+
end
|
11
|
+
|
12
|
+
def typecast(record, value)
|
13
|
+
filter = {
|
14
|
+
'operator' => 'and',
|
15
|
+
'conditions' => [
|
16
|
+
'path' => [inverse_property.id, model.property(:id).id],
|
17
|
+
'predicate' => 'eq',
|
18
|
+
'criteria' => record.id
|
19
|
+
]
|
20
|
+
}
|
21
|
+
|
22
|
+
target_model.all :filters => [filter]
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'betty_resource/model/property/types/association'
|
2
2
|
require 'betty_resource/model/property/types/belongs_to'
|
3
|
+
require 'betty_resource/model/property/types/has_and_belongs_to_many'
|
3
4
|
require 'betty_resource/model/property/types/has_many'
|
4
5
|
|
5
6
|
module BettyResource
|
@@ -19,7 +20,7 @@ module BettyResource
|
|
19
20
|
|
20
21
|
def initialize(id, model_id, name, kind, options)
|
21
22
|
@id, @model_id, @name, @kind, @options = id, model_id, name, kind, options
|
22
|
-
extend_kind_methods if %(belongs_to has_many).include?(kind)
|
23
|
+
extend_kind_methods if %(belongs_to has_and_belongs_to_many has_many).include?(kind)
|
23
24
|
end
|
24
25
|
|
25
26
|
def collection?
|
@@ -148,6 +148,14 @@ module Unit
|
|
148
148
|
group = BettyResource::Group.get(3)
|
149
149
|
assert_equal %w(), group.relations.map(&:first_name).sort
|
150
150
|
end
|
151
|
+
|
152
|
+
it "should be able to fetch a has-and-belongs-to-many value" do
|
153
|
+
user = BettyResource::User.get(5)
|
154
|
+
assert_equal %w(admin), user.roles.map(&:name)
|
155
|
+
|
156
|
+
user = BettyResource::User.get(1)
|
157
|
+
assert_equal ['admin', 'blocks admin'], user.roles.map(&:name).sort
|
158
|
+
end
|
151
159
|
end
|
152
160
|
|
153
161
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: betty_resource
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chiel Wester
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2013-11-
|
14
|
+
date: 2013-11-25 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: httparty
|
@@ -123,6 +123,7 @@ files:
|
|
123
123
|
- lib/betty_resource/model/property.rb
|
124
124
|
- lib/betty_resource/model/property/types/association.rb
|
125
125
|
- lib/betty_resource/model/property/types/belongs_to.rb
|
126
|
+
- lib/betty_resource/model/property/types/has_and_belongs_to_many.rb
|
126
127
|
- lib/betty_resource/model/property/types/has_many.rb
|
127
128
|
- lib/betty_resource/model/record.rb
|
128
129
|
- lib/betty_resource/version.rb
|