sanity-ruby 0.6.0 → 0.8.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: 8cb8ebee529e3f7aa924f79ef9db8971f2e02ff727f307a0af4c2e01cd778afc
4
- data.tar.gz: ac53d38a057a8e830ccfed73032d751bdf3f49f98e70b835b7d4b108a31ef2a3
3
+ metadata.gz: 76349642b02272270f94ada31fe1f03f438490859eff6f1f987819ccf5ddb9dc
4
+ data.tar.gz: 246e2f225d6a6955f06aba7ffe29e718904887154423c61ee1de5ba5d03af65c
5
5
  SHA512:
6
- metadata.gz: c613cd3d0dc68006d80f0a52b40a2884d654e77357e516b30e01ff78519360ca592fa8ea0c06962792daad9aac7d9841d83a7ee11c8c73d07c588e75730a87ae
7
- data.tar.gz: 799a99a83a17e76526efa652207f1aad6756c01574a2dd63b786c9a3af75192ca5c6b10ca2ffaba602d275fdbf9ef7ee38996af258364406ca5b7a6818ef3855
6
+ metadata.gz: f2287a0e8eba82e69213bef9e0e0c928da0a5fdc29ca21e50d99f43fbea0604093506331375c8277783ab564d07bc0589edd906eb19cc85b6c63e64672f80ccc
7
+ data.tar.gz: 60e53655e0e9156959a2a9c40978850501bd92f4bf94feb604e37418778bb91ba05b89ba1ea78bf5f3064bd5477a22456cdabef8a33ac1b8ce6661ca996febb8
@@ -0,0 +1,11 @@
1
+ ## Description
2
+
3
+
4
+
5
+ ## Checklist
6
+
7
+ - [ ] I have checked existing issues for duplicates
8
+ - [ ] I have run `bin/dev-test` locally and all tests pass
9
+ - [ ] I have run `bin/dev-lint` locally and there are no linting errors
10
+ - [ ] I have updated the README if this change affects documentation
11
+
data/Gemfile CHANGED
@@ -14,3 +14,9 @@ gem "guard-minitest"
14
14
  gem "yard"
15
15
 
16
16
  gem "standard"
17
+
18
+ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3.0")
19
+ gem "ffi", "~> 1.16.3"
20
+ else
21
+ gem "ffi"
22
+ end
data/README.md CHANGED
@@ -12,6 +12,12 @@ The library also provides other features, like:
12
12
  - Extensibility in overriding the serializer for the API response results
13
13
  - A small DSL around GROQ queries
14
14
 
15
+ > [!NOTE]
16
+ > This gem was originally developed in early 2021 to facilitate Morning Brew's content migration from Rails to Sanity. It was subsequently used to enable interaction between Morning Brew's Rails-based Advertising CMS and their Sanity-based Editorial CMS for another ~year. The gem is no longer actively used in production as the Rails applications have since been deprecated, but it remains available as an open-source solution for Ruby - Sanity integrations.
17
+
18
+ > [!WARNING]
19
+ > If you're looking for a way to embed Sanity Studio within a Rails application, this gem is not the solution.
20
+
15
21
  ## Contents
16
22
 
17
23
  - [Sanity](#sanity)
@@ -121,6 +127,12 @@ class User < Sanity::Resource
121
127
  queryable
122
128
  publishable
123
129
  end
130
+
131
+ # If your class name doesn't match the Sanity document type, use `document_type`:
132
+ class Cms::BlogPost < Sanity::Resource
133
+ self.document_type = :post
134
+ # ...
135
+ end
124
136
  ```
125
137
 
126
138
 
@@ -351,6 +363,7 @@ groq_query = <<-GROQ
351
363
  GROQ
352
364
 
353
365
  Sanity::Document.where(groq: groq_query, variables: {name: "Monsters, Inc."})
366
+ # Note: symbols are treated like strings when passed as variables
354
367
  ```
355
368
 
356
369
 
@@ -27,7 +27,7 @@ module Sanity
27
27
  return unless select
28
28
 
29
29
  Array.wrap(select).each_with_index do |x, idx|
30
- val << "#{idx.positive? ? "," : ""} #{x}"
30
+ val << "#{"," if idx.positive?} #{x}"
31
31
  end
32
32
 
33
33
  "{ #{val.strip} }"
@@ -5,7 +5,8 @@ module Sanity
5
5
  def self.default_type(klass)
6
6
  return nil if klass == Sanity::Document
7
7
 
8
- type = klass.to_s
8
+ type = (klass.try(:document_type) || klass).to_s
9
+
9
10
  type[0].downcase + type[1..]
10
11
  end
11
12
  end
@@ -4,6 +4,7 @@ module Sanity
4
4
  module Http
5
5
  class Find
6
6
  include Sanity::Http::Query
7
+
7
8
  delegate find_api_endpoint: :resource_klass
8
9
  alias_method :api_endpoint, :find_api_endpoint
9
10
 
@@ -7,6 +7,7 @@ module Sanity
7
7
  module Http
8
8
  class Where
9
9
  include Sanity::Http::Query
10
+
10
11
  delegate where_api_endpoint: :resource_klass
11
12
  alias_method :api_endpoint, :where_api_endpoint
12
13
 
@@ -41,7 +42,7 @@ module Sanity
41
42
  else
42
43
  {}.tap do |hash|
43
44
  variables.each do |key, value|
44
- hash["$#{key}"] = "\"#{value}\""
45
+ hash["$#{key}"] = serialize_variable_value(value)
45
46
  end
46
47
  end
47
48
  end.merge(query: groq_query)
@@ -56,6 +57,17 @@ module Sanity
56
57
 
57
58
  query_and_variables.to_json
58
59
  end
60
+
61
+ def serialize_variable_value(value)
62
+ case value
63
+ when String, Symbol
64
+ "\"#{value}\""
65
+ when Array, Hash
66
+ value.to_json
67
+ else
68
+ value.to_s
69
+ end
70
+ end
59
71
  end
60
72
  end
61
73
  end
@@ -28,6 +28,8 @@ module Sanity
28
28
  module ClassMethods
29
29
  DEFAULT_KLASS_QUERIES = %i[find where].freeze
30
30
 
31
+ attr_accessor :document_type
32
+
31
33
  # See https://www.sanity.io/docs/http-query & https://www.sanity.io/docs/http-doc
32
34
  QUERY_ENDPOINTS = {
33
35
  find: "data/doc",
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sanity
4
- VERSION = "0.6.0"
4
+ VERSION = "0.8.0"
5
5
  end
data/lib/sanity.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "logger"
3
4
  require "active_model"
4
5
  require "forwardable"
5
6
  require "sanity/refinements"
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sanity-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Drew Monroe
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2024-08-06 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: activemodel
@@ -31,6 +30,7 @@ extensions: []
31
30
  extra_rdoc_files: []
32
31
  files:
33
32
  - ".dockerignore"
33
+ - ".github/PULL_REQUEST_TEMPLATE.md"
34
34
  - ".github/workflows/ci.yml"
35
35
  - ".gitignore"
36
36
  - ".standard.yml"
@@ -94,7 +94,6 @@ metadata:
94
94
  homepage_uri: https://github.com/dvmonroe/sanity-ruby
95
95
  source_code_uri: https://github.com/dvmonroe/sanity-ruby
96
96
  changelog_uri: https://github.com/dvmonroe/sanity-ruby
97
- post_install_message:
98
97
  rdoc_options: []
99
98
  require_paths:
100
99
  - lib
@@ -109,8 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
108
  - !ruby/object:Gem::Version
110
109
  version: '0'
111
110
  requirements: []
112
- rubygems_version: 3.0.3.1
113
- signing_key:
111
+ rubygems_version: 3.6.9
114
112
  specification_version: 4
115
113
  summary: Ruby bindings for the Sanity API
116
114
  test_files: []