fmrest-spyke 0.17.0.rc1 → 0.18.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d90ab7cfdd1a358ceb0c8abcea9d456f3b97a1b9629346a208c72cdf9b627860
4
- data.tar.gz: 65888738c1d5ceff390c10a86f012162b3659ca75319b9f0c70a326ba5d7178e
3
+ metadata.gz: 1e542d636795f376392e6da0d5a7177e0c2133a4d1b534d9c52d5dcdc5b808b9
4
+ data.tar.gz: 870414e64e6a1170ca77d809b89cdb1da9e3279e3dd14f2145f141fd8ff18298
5
5
  SHA512:
6
- metadata.gz: 5b5deb4e31f490766dbd17ef17c822fe38f1387c5b5e16ed7dea9d343983e470352c0be482758901ae9fe1c28e145ad8f49102e0b4aa8ff4d9f381e20e42130d
7
- data.tar.gz: f5f500c34a809a34bc375cc62d9c7d7a39318a4172db72c2466a0fe906738406eca3c46493db7df0e1e8a1d0427cc64ee586e3134e6d53dbc8b69977adf07a69
6
+ metadata.gz: 7bdb182e4d580b33b1dfccd125d69573c9020de3118e21ae83fce8f7f2ede2e186a2eb5b8bf2b09f9be0569bb9cc3ac812b0d978d993653943c01366aa3ab64b
7
+ data.tar.gz: 681f99b637ba62caa6a0e57e976302143e2189ae49a4b6843eba7a492f0cabd1363bf2382d3ca15a7df7ed5d6a5eb115cc0aae07491edd71f87b94f6a35b684b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  ## Changelog
2
2
 
3
+ ### 0.18.0
4
+
5
+ * Better support for portals with mismatching field qualifiers
6
+ * Defining an attribute on a model that would collide with an existing method
7
+ now raises an error
8
+
9
+ ### 0.17.1
10
+
11
+ * Fixed crash when `fmid_token` is set but `username` isn't
12
+
3
13
  ### 0.17.0
4
14
 
5
15
  * Added support for Claris ID token login
data/README.md CHANGED
@@ -543,6 +543,10 @@ class LoggyBee < FmRest::Layout
543
543
  end
544
544
  ```
545
545
 
546
+ ## Gotchas
547
+
548
+ Read about unexpected scenarios in the [gotchas doc](docs/Gotchas.md).
549
+
546
550
  ## API implementation completeness table
547
551
 
548
552
  FM Data API reference: https://fmhelp.filemaker.com/docs/18/en/dataapi/
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "fmrest/spyke/portal_builder"
3
4
  require "fmrest/spyke/portal"
4
5
 
5
6
  module FmRest
@@ -13,6 +14,8 @@ module FmRest
13
14
  included do
14
15
  # Keep track of portal options by their FM keys as we could need it
15
16
  # to parse the portalData JSON in SpykeFormatter
17
+ #
18
+ # TODO: Replace this with options in PortalBuilder
16
19
  class_attribute :portal_options, instance_accessor: false, instance_predicate: false
17
20
 
18
21
  # class_attribute supports a :default option since ActiveSupport 5.2,
@@ -40,11 +43,13 @@ module FmRest
40
43
  # end
41
44
  #
42
45
  def has_portal(name, options = {})
43
- create_association(name, Portal, options)
46
+ # This is analogous to Spyke's create_association method, but using
47
+ # our custom builder instead
48
+ self.associations = associations.merge(name => PortalBuilder.new(self, name, Portal, options))
44
49
 
45
50
  # Store options for SpykeFormatter to use if needed
46
51
  portal_key = options[:portal_key] || name
47
- self.portal_options = portal_options.merge(portal_key.to_s => options.dup.merge(name: name.to_s)).freeze
52
+ self.portal_options = portal_options.merge(portal_key.to_s => options.dup.merge(name: name.to_s).freeze).freeze
48
53
 
49
54
  define_method "#{name.to_s.singularize}_ids" do
50
55
  association(name).map(&:id)
@@ -94,11 +94,17 @@ module FmRest
94
94
  end
95
95
 
96
96
  def _fmrest_define_attribute(from, to)
97
+ if existing_method = ((method_defined?(from) || private_method_defined?(from)) && from) ||
98
+ ((method_defined?("#{from}=") || private_method_defined?("#{from}=")) && "#{from}=")
99
+
100
+ raise ArgumentError, "You tried to define an attribute named `#{from}' on `#{name}', but this will generate a instance method `#{existing_method}', which is already defined by FmRest::Layout."
101
+ end
102
+
97
103
  # We use a setter here instead of injecting the hash key/value pair
98
104
  # directly with #[]= so that we don't change the mapped_attributes
99
105
  # hash on the parent class. The resulting hash is frozen for the
100
106
  # same reason.
101
- self.mapped_attributes = mapped_attributes.merge(from => to).freeze
107
+ self.mapped_attributes = mapped_attributes.merge(from => to.to_s).freeze
102
108
 
103
109
  _fmrest_attribute_methods_container.module_eval do
104
110
  define_method(from) do
@@ -6,8 +6,6 @@ module FmRest
6
6
  module GlobalFields
7
7
  extend ::ActiveSupport::Concern
8
8
 
9
- FULLY_QUALIFIED_FIELD_NAME_MATCHER = /\A[^:]+::[^:]+\Z/.freeze
10
-
11
9
  class_methods do
12
10
  def set_globals(values_hash)
13
11
  connection.patch(FmRest::V1.globals_path, {
@@ -26,7 +24,7 @@ module FmRest
26
24
  next
27
25
  end
28
26
 
29
- unless FULLY_QUALIFIED_FIELD_NAME_MATCHER === k.to_s
27
+ unless V1.is_fully_qualified?(k.to_s)
30
28
  raise ArgumentError, "global fields must be given in fully qualified format (table name::field name)"
31
29
  end
32
30
 
@@ -26,7 +26,7 @@ module FmRest
26
26
  def serialize_for_portal(portal)
27
27
  params =
28
28
  changed_params.except(:__record_id).transform_keys do |key|
29
- "#{portal.attribute_prefix}::#{key}"
29
+ V1.is_fully_qualified?(key) ? key : "#{portal.attribute_prefix}::#{key}"
30
30
  end
31
31
 
32
32
  params[:recordId] = __record_id.to_s if __record_id
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FmRest
4
+ module Spyke
5
+ class PortalBuilder < ::Spyke::Associations::Builder
6
+ attr_reader :options
7
+
8
+ def klass
9
+ begin
10
+ super
11
+ rescue NameError => e
12
+ ::FmRest::Layout
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -195,8 +195,8 @@ module FmRest
195
195
  out
196
196
  end
197
197
 
198
- # Extracts `recordId` and strips the `"PortalName::"` field prefix for each
199
- # portal
198
+ # Extracts `recordId` and strips the `"tableName::"` field qualifier for
199
+ # each portal
200
200
  #
201
201
  # Sample `json_portal_data`:
202
202
  #
@@ -210,19 +210,33 @@ module FmRest
210
210
  # @return [Hash] the portal data in Spyke format
211
211
  def prepare_portal_data(json_portal_data)
212
212
  json_portal_data.each_with_object({}) do |(portal_name, portal_records), out|
213
+
213
214
  portal_options = @model.portal_options[portal_name.to_s] || {}
215
+ portal_builder = portal_options[:name] && @model.associations[portal_options[:name].to_sym]
216
+ portal_class = portal_builder && portal_builder.klass
217
+ portal_attributes = (portal_class && portal_class.mapped_attributes.values) || []
214
218
 
215
219
  out[portal_name] =
216
220
  portal_records.map do |portal_fields|
217
221
  attributes = { __record_id: portal_fields[:recordId] }
218
222
  attributes[:__mod_id] = portal_fields[:modId] if portal_fields[:modId]
219
223
 
220
- prefix = portal_options[:attribute_prefix] || portal_name
221
- prefix_matcher = /\A#{prefix}::/
224
+ qualifier = portal_options[:attribute_prefix] || portal_name
225
+ qualifier_matcher = /\A#{qualifier}::/
222
226
 
223
227
  portal_fields.each do |k, v|
224
228
  next if :recordId == k || :modId == k
225
- attributes[k.to_s.gsub(prefix_matcher, "").to_sym] = v
229
+
230
+ stripped_field_name = k.to_s.gsub(qualifier_matcher, "")
231
+
232
+ # Only use the non-qualified attribute name if it was defined
233
+ # that way on the portal model, otherwise default to the fully
234
+ # qualified name
235
+ if portal_attributes.include?(stripped_field_name)
236
+ attributes[stripped_field_name.to_sym] = v
237
+ else
238
+ attributes[k.to_sym] = v
239
+ end
226
240
  end
227
241
 
228
242
  attributes
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fmrest-spyke
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.0.rc1
4
+ version: 0.18.0.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pedro Carbajal
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-26 00:00:00.000000000 Z
11
+ date: 2021-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fmrest-core
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.17.0.rc1
19
+ version: 0.18.0.rc2
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 0.17.0.rc1
26
+ version: 0.18.0.rc2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: spyke
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -68,6 +68,7 @@ files:
68
68
  - lib/fmrest/spyke/model/serialization.rb
69
69
  - lib/fmrest/spyke/model/uri.rb
70
70
  - lib/fmrest/spyke/portal.rb
71
+ - lib/fmrest/spyke/portal_builder.rb
71
72
  - lib/fmrest/spyke/relation.rb
72
73
  - lib/fmrest/spyke/spyke_formatter.rb
73
74
  - lib/fmrest/spyke/validation_error.rb