filemaker 0.0.15 → 0.0.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/filemaker/model/relations/belongs_to.rb +25 -11
- data/lib/filemaker/model/relations/has_many.rb +18 -10
- data/lib/filemaker/version.rb +1 -1
- data/spec/filemaker/model/relations_spec.rb +53 -1
- data/spec/filemaker/model_spec.rb +2 -0
- data/spec/support/models.rb +38 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74815c22be9b4664b3517a86e75cc15ee1dc6ac5
|
4
|
+
data.tar.gz: 1671c6d8d7ff017642b03f3acac0883ef34f6082
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b7308d7c3d585c5344d33686f85924e94562ff7331cd8b6a7fc16a0c2878f18980483b75e74818a2b2e99e65754d6ccc06197096c2fa38f9e0384b306edf545
|
7
|
+
data.tar.gz: cfcb4506718f4889b58f2fe5da37d5554ed178ed13a51456b4dbfe1b8eeb36340647733ec54e0810b0ff68325c8b8828531646e27e04b5683b7ccdd048b93ea0
|
@@ -13,20 +13,34 @@ module Filemaker
|
|
13
13
|
options.fetch(:reference_key) { "#{@name}_id" }
|
14
14
|
end
|
15
15
|
|
16
|
+
def source_key
|
17
|
+
options.fetch(:source_key) { nil }
|
18
|
+
end
|
19
|
+
|
20
|
+
def reference_value
|
21
|
+
owner.public_send(reference_key.to_sym)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Order: source_key first, reference_key next, then identity
|
25
|
+
# all must be findable using `to find_field_by_name`
|
26
|
+
def final_reference_key
|
27
|
+
target_class.find_field_by_name(source_key).try(:name) ||
|
28
|
+
target_class.find_field_by_name(reference_key).try(:name) ||
|
29
|
+
target_class.identity.try(:name)
|
30
|
+
end
|
31
|
+
|
16
32
|
protected
|
17
33
|
|
34
|
+
# Single `=` match whole word or (match empty)
|
35
|
+
# Double `==` match entire field
|
36
|
+
# If the field value contains underscore or space like 'FM_notified'
|
37
|
+
# or 'FM notified', a single `=` may not match correctly.
|
18
38
|
def build_target
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
# Single `=` match whole word or (match empty)
|
25
|
-
# Double `==` match entire field
|
26
|
-
# If the field value contains underscore or space like 'FM_notified'
|
27
|
-
# or 'FM notified', a single `=` may not match correctly.
|
28
|
-
@target = target_class.where(reference_key => "=#{key_value}").first
|
29
|
-
end
|
39
|
+
@target = nil if reference_value.blank? || final_reference_key.blank?
|
40
|
+
|
41
|
+
@target = target_class.where(
|
42
|
+
final_reference_key => "=#{reference_value}"
|
43
|
+
).first
|
30
44
|
end
|
31
45
|
end
|
32
46
|
end
|
@@ -15,6 +15,20 @@ module Filemaker
|
|
15
15
|
options.fetch(:reference_key) { owner.identity.name }
|
16
16
|
end
|
17
17
|
|
18
|
+
def reference_value
|
19
|
+
owner.public_send(reference_key.to_sym)
|
20
|
+
end
|
21
|
+
|
22
|
+
def source_key
|
23
|
+
options.fetch(:source_key) { nil }
|
24
|
+
end
|
25
|
+
|
26
|
+
def final_reference_key
|
27
|
+
target_class.find_field_by_name(source_key).try(:name) ||
|
28
|
+
target_class.find_field_by_name(reference_key).try(:name) ||
|
29
|
+
target_class.identity.try(:name)
|
30
|
+
end
|
31
|
+
|
18
32
|
# Append a model or array of models to the relation. Will set the owner
|
19
33
|
# ID to the children.
|
20
34
|
#
|
@@ -67,17 +81,11 @@ module Filemaker
|
|
67
81
|
protected
|
68
82
|
|
69
83
|
def build_target
|
70
|
-
|
84
|
+
@target = [] if reference_value.blank? || final_reference_key.blank?
|
71
85
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
# Single `=` match whole word or (match empty)
|
76
|
-
# Double `==` match entire field
|
77
|
-
# If the field value contains underscore or space like 'FM_notified'
|
78
|
-
# or 'FM notified', a single `=` may not match correctly.
|
79
|
-
@target = target_class.where(reference_key => "=#{key_value}")
|
80
|
-
end
|
86
|
+
@target = target_class.where(
|
87
|
+
final_reference_key => "=#{reference_value}"
|
88
|
+
)
|
81
89
|
end
|
82
90
|
end
|
83
91
|
end
|
data/lib/filemaker/version.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
describe Filemaker::Model::Relations do
|
2
|
-
it 'every model has a relations hash' do
|
2
|
+
it 'every model has a relations hash to store associations' do
|
3
3
|
expect(MyModel.new.relations).to eq({})
|
4
4
|
end
|
5
5
|
|
@@ -8,16 +8,22 @@ describe Filemaker::Model::Relations do
|
|
8
8
|
before do
|
9
9
|
@model = MyModel.new(candidate_id: '123')
|
10
10
|
allow(Candidate).to receive(:where).and_return([Candidate.new])
|
11
|
+
allow(Member).to receive(:where).and_return([Member.new])
|
11
12
|
end
|
12
13
|
|
13
14
|
it 'appends _id to missing reference_key' do
|
14
15
|
expect(@model.candidate.reference_key).to eq 'candidate_id'
|
16
|
+
expect(@model.candidate.final_reference_key).to eq 'candidate_id'
|
15
17
|
end
|
16
18
|
|
17
19
|
it 'target class should be Candidate' do
|
18
20
|
expect(@model.candidate.target_class).to eq Candidate
|
19
21
|
end
|
20
22
|
|
23
|
+
it 'reference_value is 123' do
|
24
|
+
expect(@model.candidate.reference_value).to eq '123'
|
25
|
+
end
|
26
|
+
|
21
27
|
it 'owner belongs to MyModel' do
|
22
28
|
expect(@model.candidate.owner).to eq @model
|
23
29
|
end
|
@@ -27,6 +33,11 @@ describe Filemaker::Model::Relations do
|
|
27
33
|
expect(@model.relations.fetch('candidate')).to eq \
|
28
34
|
@model.candidate.target
|
29
35
|
end
|
36
|
+
|
37
|
+
it 'uses identity for missing reference_key' do
|
38
|
+
expect(@model.member.reference_key).to eq 'member_id'
|
39
|
+
expect(@model.member.final_reference_key).to eq 'id'
|
40
|
+
end
|
30
41
|
end
|
31
42
|
|
32
43
|
context 'when using supplied reference_key' do
|
@@ -41,6 +52,30 @@ describe Filemaker::Model::Relations do
|
|
41
52
|
|
42
53
|
it 'will use the supplied reference_key' do
|
43
54
|
expect(@model.applicant.reference_key).to eq :name
|
55
|
+
expect(@model.applicant.final_reference_key).to eq 'name'
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'reference_value is ABC' do
|
59
|
+
expect(@model.applicant.reference_value).to eq 'ABC'
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'when using source key' do
|
64
|
+
before do
|
65
|
+
@model = MyModel.new(manager_id: 'MG1')
|
66
|
+
allow(Manager).to receive(:where).and_return([Manager.new])
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'will use manager_id as final_reference_key' do
|
70
|
+
expect(@model.manager.final_reference_key).to eq 'mg_id'
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'reference_key is still manager_id' do
|
74
|
+
expect(@model.manager.reference_key).to eq 'manager_id'
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'another_manager has different reference_key' do
|
78
|
+
expect(@model.another_manager.reference_key).to eq :candidate_id
|
44
79
|
end
|
45
80
|
end
|
46
81
|
end
|
@@ -53,6 +88,7 @@ describe Filemaker::Model::Relations do
|
|
53
88
|
context 'when using default reference_key' do
|
54
89
|
it 'will use owner identity name' do
|
55
90
|
expect(@model.posts.reference_key).to eq 'candidate_id'
|
91
|
+
expect(@model.posts.final_reference_key).to eq 'candidate_id'
|
56
92
|
end
|
57
93
|
|
58
94
|
it 'target class should be Post' do
|
@@ -75,6 +111,22 @@ describe Filemaker::Model::Relations do
|
|
75
111
|
|
76
112
|
it 'will use the supplied reference_key' do
|
77
113
|
expect(@model.posters.reference_key).to eq :email
|
114
|
+
expect(@model.posters.final_reference_key).to eq 'email'
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
context 'when using source key' do
|
119
|
+
before do
|
120
|
+
@model = Project.new
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'will use id as reference_key' do
|
124
|
+
expect(@model.project_members.reference_key).to eq :id
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'will use project_id as source_key' do
|
128
|
+
expect(@model.project_members.source_key).to eq :project_id
|
129
|
+
expect(@model.project_members.final_reference_key).to eq 'project_id'
|
78
130
|
end
|
79
131
|
end
|
80
132
|
end
|
data/spec/support/models.rb
CHANGED
@@ -6,10 +6,15 @@ end
|
|
6
6
|
|
7
7
|
class Candidate
|
8
8
|
include Filemaker::Model
|
9
|
+
|
10
|
+
string :candidate_id
|
9
11
|
end
|
10
12
|
|
11
13
|
class User
|
12
14
|
include Filemaker::Model
|
15
|
+
|
16
|
+
string :name
|
17
|
+
string :email
|
13
18
|
end
|
14
19
|
|
15
20
|
class Post
|
@@ -29,6 +34,19 @@ class Job
|
|
29
34
|
date :modify_date, fm_name: 'modify date'
|
30
35
|
end
|
31
36
|
|
37
|
+
class Member
|
38
|
+
include Filemaker::Model
|
39
|
+
|
40
|
+
string :id, identity: true
|
41
|
+
end
|
42
|
+
|
43
|
+
class Manager
|
44
|
+
include Filemaker::Model
|
45
|
+
|
46
|
+
string :id, identity: true
|
47
|
+
string :mg_id
|
48
|
+
end
|
49
|
+
|
32
50
|
class MyModel
|
33
51
|
include Filemaker::Model
|
34
52
|
|
@@ -37,13 +55,33 @@ class MyModel
|
|
37
55
|
|
38
56
|
belongs_to :candidate
|
39
57
|
belongs_to :applicant, class_name: User, reference_key: :name
|
58
|
+
belongs_to :member
|
59
|
+
belongs_to :manager, source_key: :mg_id
|
60
|
+
belongs_to :another_manager, class_name: Manager, source_key: :mg_id, reference_key: :candidate_id
|
40
61
|
has_many :posts
|
41
62
|
has_many :posters, class_name: User, reference_key: :email
|
42
63
|
|
43
64
|
string :name, :email, default: 'UNTITLED'
|
44
65
|
string :candidate_id, fm_name: 'CA ID', identity: true
|
66
|
+
string :member_id
|
67
|
+
string :manager_id
|
45
68
|
date :created_at
|
46
69
|
datetime :updated_at, fm_name: 'ModifiedDate'
|
47
70
|
money :salary
|
48
71
|
integer :age, fm_name: 'passage of time'
|
49
72
|
end
|
73
|
+
|
74
|
+
class Project
|
75
|
+
include Filemaker::Model
|
76
|
+
|
77
|
+
string :id, identity: true
|
78
|
+
|
79
|
+
has_many :project_members, source_key: :project_id, reference_key: :id
|
80
|
+
end
|
81
|
+
|
82
|
+
class ProjectMember
|
83
|
+
include Filemaker::Model
|
84
|
+
|
85
|
+
string :member_id
|
86
|
+
string :project_id
|
87
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: filemaker
|
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
|
- mech
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -273,3 +273,4 @@ test_files:
|
|
273
273
|
- spec/support/responses/portal.xml
|
274
274
|
- spec/support/responses/scriptnames.xml
|
275
275
|
- spec/support/xml_loader.rb
|
276
|
+
has_rdoc:
|