sanity-ruby 0.5.0 → 0.6.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 +4 -4
- data/.github/workflows/ci.yml +1 -1
- data/Dockerfile-3.3 +30 -0
- data/README.md +36 -2
- data/bin/dev-lint +4 -1
- data/bin/dev-test +4 -1
- data/docker-compose.yml +13 -2
- data/lib/sanity/configuration.rb +24 -9
- data/lib/sanity/version.rb +1 -1
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8cb8ebee529e3f7aa924f79ef9db8971f2e02ff727f307a0af4c2e01cd778afc
|
4
|
+
data.tar.gz: ac53d38a057a8e830ccfed73032d751bdf3f49f98e70b835b7d4b108a31ef2a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c613cd3d0dc68006d80f0a52b40a2884d654e77357e516b30e01ff78519360ca592fa8ea0c06962792daad9aac7d9841d83a7ee11c8c73d07c588e75730a87ae
|
7
|
+
data.tar.gz: 799a99a83a17e76526efa652207f1aad6756c01574a2dd63b786c9a3af75192ca5c6b10ca2ffaba602d275fdbf9ef7ee38996af258364406ca5b7a6818ef3855
|
data/.github/workflows/ci.yml
CHANGED
data/Dockerfile-3.3
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
FROM ruby:3.3-alpine as base
|
2
|
+
|
3
|
+
RUN apk add --update --no-cache \
|
4
|
+
build-base \
|
5
|
+
cmake \
|
6
|
+
tzdata \
|
7
|
+
bash \
|
8
|
+
git
|
9
|
+
|
10
|
+
ENV APP_PATH /var/www/sanity-ruby
|
11
|
+
RUN mkdir -p $APP_PATH
|
12
|
+
|
13
|
+
# Build intermediate
|
14
|
+
FROM base as intermediate
|
15
|
+
|
16
|
+
WORKDIR $APP_PATH
|
17
|
+
|
18
|
+
RUN rm -rf /var/cache/apk/*
|
19
|
+
|
20
|
+
FROM base as development
|
21
|
+
|
22
|
+
COPY --from=intermediate $APP_PATH $APP_PATH
|
23
|
+
|
24
|
+
WORKDIR $APP_PATH
|
25
|
+
|
26
|
+
ENV GEM_HOME $APP_PATH/vendor/bundle
|
27
|
+
ENV BUNDLE_PATH vendor/bundle
|
28
|
+
|
29
|
+
COPY . ./
|
30
|
+
RUN bundle check || bundle install
|
data/README.md
CHANGED
@@ -35,6 +35,7 @@ gem 'sanity-ruby'
|
|
35
35
|
Setup your configuration. If using in Rails, consider setting this in an initializer:
|
36
36
|
|
37
37
|
```ruby
|
38
|
+
# config/initializers/sanity.rb
|
38
39
|
Sanity.configure do |s|
|
39
40
|
s.token = "yoursupersecrettoken"
|
40
41
|
s.api_version = "v2021-03-25"
|
@@ -42,9 +43,19 @@ Sanity.configure do |s|
|
|
42
43
|
s.dataset = "development"
|
43
44
|
s.use_cdn = false
|
44
45
|
end
|
46
|
+
|
47
|
+
# OR
|
48
|
+
|
49
|
+
# Sanity.configure do |s|
|
50
|
+
# s.token = ENV.fetch("SANITY_TOKEN", "")
|
51
|
+
# s.api_version = ENV.fetch("SANITY_API_VERSION", "")
|
52
|
+
# s.project_id = ENV.fetch("SANITY_PROJECT_ID", "")
|
53
|
+
# s.dataset = ENV.fetch("SANITY_DATASET", "")
|
54
|
+
# s.use_cdn = ENV.fetch("SANITY_USE_CDN", false)
|
55
|
+
# end
|
45
56
|
```
|
46
57
|
|
47
|
-
or you can set the following ENV variables at runtime:
|
58
|
+
or you can set the following ENV variables at runtime without any initializer:
|
48
59
|
|
49
60
|
```bash
|
50
61
|
SANITY_TOKEN="yoursupersecrettoken"
|
@@ -54,7 +65,30 @@ SANITY_DATASET="development"
|
|
54
65
|
SANITY_USE_CDN="false"
|
55
66
|
```
|
56
67
|
|
57
|
-
The configuration object is thread safe meaning you can connect to multiple different projects across
|
68
|
+
The configuration object is thread safe by default meaning you can connect to multiple different projects and/or API variations across any number of threads. A real world scenario when working with Sanity may require that you sometimes interact with the [CDN based API](https://www.sanity.io/docs/api-cdn) and sometimes the non-CDN based API. Using ENV variables combined with the thread safe configuration object gives you the ultimate flexibility.
|
69
|
+
|
70
|
+
If you're using this gem in a Rails application AND you're interacting with only ONE set of configuration you can make the gem use the global configuration by setting the `use_global_config` option to `true`.
|
71
|
+
|
72
|
+
Your initializer `config/initializers/sanity.rb` should look like:
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
# `use_global_config` is NOT thread safe. DO NOT use if you intend on changing the
|
76
|
+
# config object at anytime within your application's lifecycle.
|
77
|
+
#
|
78
|
+
# Do not use `use_global_config` in your application if you're:
|
79
|
+
# - Interacting with various Sanity project ids/token
|
80
|
+
# - Interacting with multiple API versions
|
81
|
+
# - Interacting with calls that sometimes require the use of the CDN and sometimes don't
|
82
|
+
|
83
|
+
Sanity.use_global_config = true
|
84
|
+
Sanity.configure do |s|
|
85
|
+
s.token = "yoursupersecrettoken"
|
86
|
+
s.api_version = "v2021-03-25"
|
87
|
+
s.project_id = "1234"
|
88
|
+
s.dataset = "development"
|
89
|
+
s.use_cdn = false
|
90
|
+
end
|
91
|
+
```
|
58
92
|
|
59
93
|
To create a new document:
|
60
94
|
|
data/bin/dev-lint
CHANGED
@@ -1,3 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
system "docker-compose run --rm 2.6 bin/standardrb &&
|
3
|
+
system "docker-compose run --rm 2.6 bin/standardrb && \
|
4
|
+
docker-compose run --rm 2.7 bin/standardrb && \
|
5
|
+
docker-compose run --rm 3.0 bin/standardrb && \
|
6
|
+
docker-compose run --rm 3.3 bin/standardrb"
|
data/bin/dev-test
CHANGED
@@ -1,3 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
system "docker-compose run --rm 2.6 bundle exec rake test &&
|
3
|
+
system "docker-compose run --rm 2.6 bundle exec rake test && \
|
4
|
+
docker-compose run --rm 2.7 bundle exec rake test && \
|
5
|
+
docker-compose run --rm 3.0 bundle exec rake test && \
|
6
|
+
docker-compose run --rm 3.3 bundle exec rake test"
|
data/docker-compose.yml
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
version: '3.9'
|
2
|
-
|
3
1
|
services:
|
4
2
|
'2.6':
|
5
3
|
build:
|
@@ -40,6 +38,19 @@ services:
|
|
40
38
|
container_name: sanity-ruby-3.0
|
41
39
|
command: bash
|
42
40
|
|
41
|
+
'3.3':
|
42
|
+
build:
|
43
|
+
context: .
|
44
|
+
dockerfile: Dockerfile-3.3
|
45
|
+
tty: true
|
46
|
+
stdin_open: true
|
47
|
+
volumes:
|
48
|
+
- ./bin:/var/www/sanity-ruby/bin/
|
49
|
+
- ./lib:/var/www/sanity-ruby/lib/
|
50
|
+
- ./test:/var/www/sanity-ruby/test/
|
51
|
+
container_name: sanity-ruby-3.3
|
52
|
+
command: bash
|
53
|
+
|
43
54
|
volumes:
|
44
55
|
bin:
|
45
56
|
lib:
|
data/lib/sanity/configuration.rb
CHANGED
@@ -29,21 +29,36 @@ module Sanity
|
|
29
29
|
def api_subdomain
|
30
30
|
use_cdn ? "apicdn" : "api"
|
31
31
|
end
|
32
|
-
end
|
33
32
|
|
34
|
-
|
35
|
-
|
33
|
+
def to_h
|
34
|
+
instance_variables.each_with_object({}) do |var, obj|
|
35
|
+
obj[var.to_s.delete("@").to_sym] = instance_variable_get(var)
|
36
|
+
end
|
37
|
+
end
|
36
38
|
end
|
37
39
|
|
38
40
|
class << self
|
41
|
+
attr_accessor :use_global_config
|
42
|
+
|
43
|
+
def configuration
|
44
|
+
if use_global_config
|
45
|
+
@configuration ||= Configuration.new
|
46
|
+
else
|
47
|
+
Thread.current[:sanity_configuration] ||= Configuration.new
|
48
|
+
end
|
49
|
+
end
|
39
50
|
alias_method :config, :configuration
|
40
|
-
end
|
41
51
|
|
42
|
-
|
43
|
-
|
44
|
-
|
52
|
+
def configuration=(config)
|
53
|
+
if use_global_config
|
54
|
+
@configuration = config
|
55
|
+
else
|
56
|
+
Thread.current[:sanity_configuration] = config
|
57
|
+
end
|
58
|
+
end
|
45
59
|
|
46
|
-
|
47
|
-
|
60
|
+
def configure
|
61
|
+
yield configuration
|
62
|
+
end
|
48
63
|
end
|
49
64
|
end
|
data/lib/sanity/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sanity-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Drew Monroe
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-08-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -37,6 +37,7 @@ files:
|
|
37
37
|
- Dockerfile-2.6
|
38
38
|
- Dockerfile-2.7
|
39
39
|
- Dockerfile-3.0
|
40
|
+
- Dockerfile-3.3
|
40
41
|
- Gemfile
|
41
42
|
- LICENSE.txt
|
42
43
|
- README.md
|
@@ -93,7 +94,7 @@ metadata:
|
|
93
94
|
homepage_uri: https://github.com/dvmonroe/sanity-ruby
|
94
95
|
source_code_uri: https://github.com/dvmonroe/sanity-ruby
|
95
96
|
changelog_uri: https://github.com/dvmonroe/sanity-ruby
|
96
|
-
post_install_message:
|
97
|
+
post_install_message:
|
97
98
|
rdoc_options: []
|
98
99
|
require_paths:
|
99
100
|
- lib
|
@@ -108,8 +109,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
109
|
- !ruby/object:Gem::Version
|
109
110
|
version: '0'
|
110
111
|
requirements: []
|
111
|
-
rubygems_version: 3.
|
112
|
-
signing_key:
|
112
|
+
rubygems_version: 3.0.3.1
|
113
|
+
signing_key:
|
113
114
|
specification_version: 4
|
114
115
|
summary: Ruby bindings for the Sanity API
|
115
116
|
test_files: []
|