filemaker 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/filemaker/metadata/field.rb +2 -3
- data/lib/filemaker/model.rb +1 -1
- data/lib/filemaker/model/builder.rb +2 -0
- data/lib/filemaker/model/persistable.rb +3 -1
- data/lib/filemaker/model/relations.rb +10 -1
- data/lib/filemaker/model/relations/has_portal.rb +24 -0
- data/lib/filemaker/record.rb +3 -3
- data/lib/filemaker/resultset.rb +4 -3
- data/lib/filemaker/version.rb +1 -1
- data/spec/filemaker/record_spec.rb +5 -0
- data/spec/filemaker/resultset_spec.rb +6 -0
- data/spec/support/responses/portal.xml +27 -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: f3eeb9794e61e3c3cf1f4c2787e3e8705b2f9c6c
|
4
|
+
data.tar.gz: 1f536f8d4222365920815d72276e8074c1f7acdf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8594e7753236a5dbf6f1f2acd65a49862dbdc1d2350e117cb49e18aac9dbd4baac593a5d22ed92a60735d31a09f2bf2bf7d434f84c1f0a8aedc0e1642921ba57
|
7
|
+
data.tar.gz: eaf53d15fc516d4dfdc240a38c2857fedc6e966f1167b81fa95108ad4598fa9c3f01344ff0767a3ac9880aa647b01b6acb0af4b91bc1cd1de057c4ed3e5c86e6
|
data/lib/filemaker/model.rb
CHANGED
@@ -6,7 +6,7 @@ module Filemaker
|
|
6
6
|
include Components
|
7
7
|
|
8
8
|
# @return [Boolean] indicates if this is a new fresh record
|
9
|
-
attr_reader :attributes, :new_record, :record_id, :mod_id
|
9
|
+
attr_reader :attributes, :new_record, :record_id, :mod_id, :portals
|
10
10
|
|
11
11
|
included do
|
12
12
|
class_attribute :db, :lay, :registry_name, :server, :api, :per_page
|
@@ -14,6 +14,7 @@ module Filemaker
|
|
14
14
|
object.instance_variable_set('@new_record', false)
|
15
15
|
object.instance_variable_set('@record_id', record.record_id)
|
16
16
|
object.instance_variable_set('@mod_id', record.mod_id)
|
17
|
+
object.instance_variable_set('@portals', record.portals)
|
17
18
|
|
18
19
|
record.keys.each do |fm_field_name|
|
19
20
|
# record.keys are all lowercase
|
@@ -36,6 +37,7 @@ module Filemaker
|
|
36
37
|
object.instance_variable_set('@new_record', false)
|
37
38
|
object.instance_variable_set('@record_id', record.record_id)
|
38
39
|
object.instance_variable_set('@mod_id', record.mod_id)
|
40
|
+
object.instance_variable_set('@portals', record.portals)
|
39
41
|
|
40
42
|
record.keys.each do |fm_field_name|
|
41
43
|
# record.keys are all lowercase
|
@@ -66,10 +66,12 @@ module Filemaker
|
|
66
66
|
end
|
67
67
|
alias_method :delete, :destroy
|
68
68
|
|
69
|
+
# If value is nil, we convert to empty string so it will get pick up by
|
70
|
+
# `fm_attributes`
|
69
71
|
def assign_attributes(new_attributes)
|
70
72
|
return if new_attributes.blank?
|
71
73
|
new_attributes.each_pair do |key, value|
|
72
|
-
public_send("#{key}=", value) if respond_to?("#{key}=")
|
74
|
+
public_send("#{key}=", (value || '')) if respond_to?("#{key}=")
|
73
75
|
end
|
74
76
|
end
|
75
77
|
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'filemaker/model/relations/belongs_to'
|
2
2
|
require 'filemaker/model/relations/has_many'
|
3
|
+
require 'filemaker/model/relations/has_portal'
|
3
4
|
|
4
5
|
module Filemaker
|
5
6
|
module Model
|
@@ -21,11 +22,19 @@ module Filemaker
|
|
21
22
|
end
|
22
23
|
|
23
24
|
def has_portal(name, options = {})
|
24
|
-
Relations::HasPortal
|
25
|
+
relate_portal(Relations::HasPortal, name, options)
|
25
26
|
end
|
26
27
|
|
27
28
|
protected
|
28
29
|
|
30
|
+
def relate_portal(type, name, options)
|
31
|
+
name = name.to_s
|
32
|
+
|
33
|
+
define_method(name) do
|
34
|
+
type.new(self, name, options)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
29
38
|
# Get the single model and cache it to `relations`
|
30
39
|
def relate_single(type, name, options)
|
31
40
|
name = name.to_s
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'filemaker/model/relations/proxy'
|
2
|
+
|
3
|
+
module Filemaker
|
4
|
+
module Model
|
5
|
+
module Relations
|
6
|
+
class HasPortal < Proxy
|
7
|
+
def initialize(owner, name, options)
|
8
|
+
super(owner, name, options)
|
9
|
+
build_target
|
10
|
+
end
|
11
|
+
|
12
|
+
def table_name
|
13
|
+
options.fetch(:table_name)
|
14
|
+
end
|
15
|
+
|
16
|
+
protected
|
17
|
+
|
18
|
+
def build_target
|
19
|
+
@target = owner.portals[table_name]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/filemaker/record.rb
CHANGED
@@ -67,11 +67,11 @@ module Filemaker
|
|
67
67
|
table_name = relatedset['table']
|
68
68
|
records = []
|
69
69
|
|
70
|
+
@portals[table_name] ||= records
|
71
|
+
|
70
72
|
relatedset.xpath('record').each do |record|
|
71
|
-
|
73
|
+
@portals[table_name] << self.class.new(record, resultset, table_name)
|
72
74
|
end
|
73
|
-
|
74
|
-
@portals[table_name] = records
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
data/lib/filemaker/resultset.rb
CHANGED
@@ -101,14 +101,15 @@ module Filemaker
|
|
101
101
|
table_name = relatedset.attribute('table').value
|
102
102
|
p_fields = {}
|
103
103
|
|
104
|
+
@portal_fields[table_name] ||= p_fields
|
105
|
+
|
104
106
|
relatedset.xpath('field-definition').each do |definition|
|
105
107
|
# Right now, I do not want to mess with the field name
|
106
108
|
# name = definition['name'].gsub("#{table_name}::", '')
|
107
109
|
name = definition['name']
|
108
|
-
|
110
|
+
@portal_fields[table_name][name] = \
|
111
|
+
Metadata::Field.new(definition, self)
|
109
112
|
end
|
110
|
-
|
111
|
-
@portal_fields[table_name] = p_fields
|
112
113
|
end
|
113
114
|
end
|
114
115
|
|
data/lib/filemaker/version.rb
CHANGED
@@ -44,6 +44,11 @@ describe Filemaker::Record do
|
|
44
44
|
expect(@record.portals[:PORTAL_1]).to eq @record.portals['portal_1']
|
45
45
|
end
|
46
46
|
|
47
|
+
it 'has 4 records for PORTAL_2' do
|
48
|
+
expect(@record.portals[:PORTAL_2].size).to eq 4
|
49
|
+
expect(@record.portals[:PORTAL_2][1]['portal_2::expired']).to be_nil
|
50
|
+
end
|
51
|
+
|
47
52
|
it 'key access as plain method' do
|
48
53
|
expect(@record.portalid).to eq '1234'
|
49
54
|
end
|
@@ -54,6 +54,12 @@ describe Filemaker::Resultset do
|
|
54
54
|
it 'has 2 portals' do
|
55
55
|
expect(resultset.portal_fields.size).to eq 2
|
56
56
|
end
|
57
|
+
|
58
|
+
it 'PORTAL_2 has 2 fields: Expired and Renewed' do
|
59
|
+
expect(resultset.portal_fields['PORTAL_2'].size).to eq 2
|
60
|
+
expect(resultset.portal_fields['PORTAL_2'].keys).to eq \
|
61
|
+
%w(PORTAL_2::Expired PORTAL_2::Renewed)
|
62
|
+
end
|
57
63
|
end
|
58
64
|
|
59
65
|
describe 'build records' do
|
@@ -18,6 +18,9 @@
|
|
18
18
|
<relatedset-definition table="PORTAL_2">
|
19
19
|
<field-definition auto-enter="no" four-digit-year="no" global="no" max-repeat="1" name="PORTAL_2::Expired" not-empty="no" numeric-only="no" result="date" time-of-day="no" type="normal"/>
|
20
20
|
</relatedset-definition>
|
21
|
+
<relatedset-definition table="PORTAL_2">
|
22
|
+
<field-definition auto-enter="no" four-digit-year="no" global="no" max-repeat="1" name="PORTAL_2::Renewed" not-empty="no" numeric-only="no" result="date" time-of-day="no" type="normal"/>
|
23
|
+
</relatedset-definition>
|
21
24
|
</metadata>
|
22
25
|
<resultset count="2" fetch-size="2">
|
23
26
|
<record mod-id="mod-id-1" record-id="record-id-1">
|
@@ -61,6 +64,18 @@
|
|
61
64
|
</field>
|
62
65
|
</record>
|
63
66
|
</relatedset>
|
67
|
+
<relatedset count="2" table="PORTAL_2">
|
68
|
+
<record mod-id="24" record-id="12492">
|
69
|
+
<field name="PORTAL_2::Renewed">
|
70
|
+
<data>10/4/2014</data>
|
71
|
+
</field>
|
72
|
+
</record>
|
73
|
+
<record mod-id="21" record-id="12591">
|
74
|
+
<field name="PORTAL_2::Renewed">
|
75
|
+
<data>12/12/2014</data>
|
76
|
+
</field>
|
77
|
+
</record>
|
78
|
+
</relatedset>
|
64
79
|
</record>
|
65
80
|
<record mod-id="mod-id-2" record-id="record-id-2">
|
66
81
|
<field name="PortalID">
|
@@ -103,6 +118,18 @@
|
|
103
118
|
</field>
|
104
119
|
</record>
|
105
120
|
</relatedset>
|
121
|
+
<relatedset count="2" table="PORTAL_2">
|
122
|
+
<record mod-id="24" record-id="12152">
|
123
|
+
<field name="PORTAL_2::Renewed">
|
124
|
+
<data>12/31/2014</data>
|
125
|
+
</field>
|
126
|
+
</record>
|
127
|
+
<record mod-id="21" record-id="12141">
|
128
|
+
<field name="PORTAL_2::Renewed">
|
129
|
+
<data/>
|
130
|
+
</field>
|
131
|
+
</record>
|
132
|
+
</relatedset>
|
106
133
|
</record>
|
107
134
|
</resultset>
|
108
135
|
</fmresultset>
|
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.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mech
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -183,6 +183,7 @@ files:
|
|
183
183
|
- lib/filemaker/model/relations.rb
|
184
184
|
- lib/filemaker/model/relations/belongs_to.rb
|
185
185
|
- lib/filemaker/model/relations/has_many.rb
|
186
|
+
- lib/filemaker/model/relations/has_portal.rb
|
186
187
|
- lib/filemaker/model/relations/proxy.rb
|
187
188
|
- lib/filemaker/model/selectable.rb
|
188
189
|
- lib/filemaker/railtie.rb
|