fmrest 0.8.0 → 0.9.0

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
  SHA256:
3
- metadata.gz: 5873c0192a2b166cfef71b33c521665dd6953660bd9d23d3ef728b89c55e886f
4
- data.tar.gz: 7615faa115cc7506d3a472d2fac70ea293bd3dbec1e03bb3c19f0faca51b7c9d
3
+ metadata.gz: 5f96cf4500b2417bde1c853954dee03a362088adac933fc7d803d8e37e91cc8a
4
+ data.tar.gz: e6cd271dbfef1c87c04a515b8a22e7ead87ec88ab915b37245d4dcecc7c9a237
5
5
  SHA512:
6
- metadata.gz: b627994fa66842be8200692895077649837a7b343c337aaf5762926c633de02baf14ba6428cc33b8b3cc0d0314d7d62a4f6cf16173edb09d32ba8218c533d7d6
7
- data.tar.gz: 2cd9e7f7003f9ec05120587f50ee892076d8e02045a6b18e9311276792bf831dee6c4434969990b17f4f5898f95040da0614aabbdb5940fa8906f3c507f7f0e8
6
+ metadata.gz: 68c4083e32e942fd609b050c2001d32b97c18d88ab70301f10ff0ce31527af2c5faff6e210afceaf152280dc2e0924a8edf2e2994e28ad331d2f015860f172f3
7
+ data.tar.gz: 9af1f38e2a59bda96639d6b6f1d3756b007a8c327392159f6288f2365161a94a211ff483744499771716e8e1d61cd8a57876fbfffcf7646e61db52d1794ab1a3
@@ -1,11 +1,16 @@
1
1
  ## Changelog
2
2
 
3
+ ### 0.9.0
4
+
5
+ * Added `FmRest::Spyke::Base.set_globals`
6
+
3
7
  ### 0.8.0
4
8
 
5
9
  * Improved metadata when using `FmRest::Spyke::Model`. Metadata now uses
6
10
  Struct/OpenStruct, so properties are accessible through `.property`, as well
7
11
  as `[:property]`
8
- * Implemented `.find_in_batches` and `.find_each` for `FmRest::Spyke::Model`
12
+ * Added batch-finders `.find_in_batches` and `.find_each` for
13
+ * `FmRest::Spyke::Base`
9
14
 
10
15
  ### 0.7.1
11
16
 
data/README.md CHANGED
@@ -943,6 +943,32 @@ to retrieving single records, in that case you'll have to use
943
943
  `.last_request_metadata`.
944
944
 
945
945
 
946
+ ### Setting global field values
947
+
948
+ You can call `.set_globals` on any `FmRest::Spyke::Base` model to set glabal
949
+ field values on the database that model is configured for.
950
+
951
+ You can pass it either a hash of fully qualified field names
952
+ (table_name::field_name), or 1-level-deep nested hashes, with the outer being a
953
+ table name and the inner keys being the field names:
954
+
955
+ ```ruby
956
+ Honeybee.set_globals(
957
+ "beeTable::myVar" => "value",
958
+ "beeTable::myOtherVar" => "also a value"
959
+ )
960
+
961
+ # Equivalent to the above example
962
+ Honeybee.set_globals(beeTable: { myVar: "value", myOtherVar: "also a value" })
963
+
964
+ # Combined
965
+ Honeybee.set_globals(
966
+ "beeTable::myVar" => "value",
967
+ beeTable: { myOtherVar: "also a value" }
968
+ )
969
+ ```
970
+
971
+
946
972
  ## Logging
947
973
 
948
974
  If using fmrest-ruby + Spyke in a Rails app pretty log output will be set up
@@ -1011,7 +1037,7 @@ FM Data API reference: https://fmhelp.filemaker.com/docs/18/en/dataapi/
1011
1037
  | Get container data | Manual* | Yes |
1012
1038
  | Upload container data | Manual* | Yes |
1013
1039
  | Perform a find request | Manual* | Yes |
1014
- | Set global field values | Manual* | No |
1040
+ | Set global field values | Manual* | Yes
1015
1041
  | Run a script | Manual* | Yes |
1016
1042
  | Run a script with another request | Manual* | Yes |
1017
1043
 
@@ -7,6 +7,7 @@ require "fmrest/spyke/model/serialization"
7
7
  require "fmrest/spyke/model/associations"
8
8
  require "fmrest/spyke/model/orm"
9
9
  require "fmrest/spyke/model/container_fields"
10
+ require "fmrest/spyke/model/global_fields"
10
11
  require "fmrest/spyke/model/http"
11
12
  require "fmrest/spyke/model/auth"
12
13
 
@@ -22,6 +23,7 @@ module FmRest
22
23
  include Associations
23
24
  include Orm
24
25
  include ContainerFields
26
+ include GlobalFields
25
27
  include Http
26
28
  include Auth
27
29
 
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FmRest
4
+ module Spyke
5
+ module Model
6
+ module GlobalFields
7
+ extend ::ActiveSupport::Concern
8
+
9
+ FULLY_QUALIFIED_FIELD_NAME_MATCHER = /\A[^:]+::[^:]+\Z/.freeze
10
+
11
+ class_methods do
12
+ def set_globals(values_hash)
13
+ connection.patch(FmRest::V1.globals_path, {
14
+ globalFields: normalize_globals_hash(values_hash)
15
+ })
16
+ end
17
+
18
+ private
19
+
20
+ def normalize_globals_hash(hash)
21
+ hash.each_with_object({}) do |(k, v), normalized|
22
+ if v.kind_of?(Hash)
23
+ v.each do |k2, v2|
24
+ normalized["#{k}::#{k2}"] = v2
25
+ end
26
+ next
27
+ end
28
+
29
+ unless FULLY_QUALIFIED_FIELD_NAME_MATCHER === k.to_s
30
+ raise ArgumentError, "global fields must be given in fully qualified format (table name::field name)"
31
+ end
32
+
33
+ normalized[k] = v
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FmRest
4
- VERSION = "0.8.0"
4
+ VERSION = "0.9.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fmrest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pedro Carbajal
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-16 00:00:00.000000000 Z
11
+ date: 2020-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -247,6 +247,7 @@ files:
247
247
  - lib/fmrest/spyke/model/auth.rb
248
248
  - lib/fmrest/spyke/model/connection.rb
249
249
  - lib/fmrest/spyke/model/container_fields.rb
250
+ - lib/fmrest/spyke/model/global_fields.rb
250
251
  - lib/fmrest/spyke/model/http.rb
251
252
  - lib/fmrest/spyke/model/orm.rb
252
253
  - lib/fmrest/spyke/model/serialization.rb