sanity-ruby 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -3
- data/lib/sanity/attributable.rb +1 -1
- data/lib/sanity/helpers/type_helper.rb +12 -0
- data/lib/sanity/helpers.rb +3 -0
- data/lib/sanity/http/mutation.rb +1 -1
- data/lib/sanity/queryable.rb +10 -5
- data/lib/sanity/resource.rb +3 -2
- data/lib/sanity/serializable.rb +3 -2
- data/lib/sanity/version.rb +1 -1
- data/lib/sanity.rb +2 -1
- data/sanity.gemspec +5 -3
- metadata +25 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e02c772808fc5112f526e0e8bd329a829dd4ba0e2395d82a83d34f8419a05e66
|
4
|
+
data.tar.gz: c2b80c8bee2242e68ec2b814fc18e11ad699687a2174889cdf4a7b34823405f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e265993399cfa3c24f821cac9625daaf763a0468353d18f0fac375231bc9e62e727f2a3314bbf55fc7aaa3b5d51f733822cc16409489bf6f3aebbff75ba5c72d
|
7
|
+
data.tar.gz: 5bf5fbfdb1fcf02d691fec0ad2226d2c24a9b993559f6e92eba16d6961eb0f54d97c70616e6642f6f42982666f3e3443b98bc8a9c53dc356b6fa956e99ae077b
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Sanity
|
2
2
|
|
3
|
-
![](https://github.com/
|
4
|
-
|
3
|
+
![](https://github.com/dvmonroe/sanity-ruby/actions/workflows/ci.yml/badge.svg)
|
4
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/24b96780b59c8a871e6e/maintainability)](https://codeclimate.com/github/dvmonroe/sanity-ruby/maintainability)
|
5
5
|
|
6
6
|
The Sanity Ruby library provides convenient access to the Sanity API from applications written in Ruby. It includes a pre-defined set of classes for API resources.
|
7
7
|
|
@@ -76,6 +76,20 @@ class User < Sanity::Resource
|
|
76
76
|
end
|
77
77
|
```
|
78
78
|
|
79
|
+
Since `Sanity::Resource` includes `ActiveModel::Model` and
|
80
|
+
`ActiveModel::Attributes`, you're able to define types on attributes and use
|
81
|
+
methods like `alias_attribute`.
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
class User < Sanity::Resource
|
85
|
+
...
|
86
|
+
attribute :name, :string, default: 'John Doe'
|
87
|
+
attribute :_createdAt, :datetime
|
88
|
+
alias_attribute :created_at, :_createdAt
|
89
|
+
...
|
90
|
+
end
|
91
|
+
```
|
92
|
+
|
79
93
|
To create a new document in Sanity:
|
80
94
|
|
81
95
|
```ruby
|
@@ -296,7 +310,7 @@ bin/dev-lint
|
|
296
310
|
|
297
311
|
## Contributing
|
298
312
|
|
299
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
313
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/dvmonroe/sanity-ruby.
|
300
314
|
|
301
315
|
## License
|
302
316
|
|
data/lib/sanity/attributable.rb
CHANGED
@@ -39,7 +39,7 @@ module Sanity
|
|
39
39
|
def initialize(**args)
|
40
40
|
self.class.default_attributes.merge(args).then do |attrs|
|
41
41
|
attrs.each do |key, val|
|
42
|
-
define_singleton_method("#{key}=") do |val|
|
42
|
+
define_singleton_method(:"#{key}=") do |val|
|
43
43
|
args[key] = val
|
44
44
|
attributes[key] = val
|
45
45
|
end
|
data/lib/sanity/http/mutation.rb
CHANGED
data/lib/sanity/queryable.rb
CHANGED
@@ -36,15 +36,20 @@ module Sanity
|
|
36
36
|
|
37
37
|
private
|
38
38
|
|
39
|
-
# @private
|
40
39
|
def queryable(**options)
|
41
40
|
options.fetch(:only, DEFAULT_KLASS_QUERIES).each do |query|
|
42
|
-
|
43
|
-
Module.const_get("Sanity::Http::#{query.to_s.classify}").call(**args.merge(resource_klass: self))
|
44
|
-
end
|
45
|
-
define_singleton_method("#{query}_api_endpoint") { QUERY_ENDPOINTS[query] }
|
41
|
+
define_query_method(query)
|
46
42
|
end
|
47
43
|
end
|
44
|
+
|
45
|
+
def define_query_method(query)
|
46
|
+
define_singleton_method(query) do |**args|
|
47
|
+
default_type = args.key?(:_type) ? args[:_type] : Sanity::TypeHelper.default_type(self)
|
48
|
+
default_args = {resource_klass: self, _type: default_type}.compact
|
49
|
+
Module.const_get("Sanity::Http::#{query.to_s.classify}").call(**default_args.merge(args))
|
50
|
+
end
|
51
|
+
define_singleton_method(:"#{query}_api_endpoint") { QUERY_ENDPOINTS[query] }
|
52
|
+
end
|
48
53
|
end
|
49
54
|
end
|
50
55
|
end
|
data/lib/sanity/resource.rb
CHANGED
@@ -5,7 +5,6 @@ module Sanity
|
|
5
5
|
# the sanity resources defined within this gem.
|
6
6
|
#
|
7
7
|
# Out of the box it includes the following mixins:
|
8
|
-
# Sanity::Attributable
|
9
8
|
# Sanity::Mutatable
|
10
9
|
# Sanity::Queryable
|
11
10
|
# Sanity::Serializable
|
@@ -24,7 +23,9 @@ module Sanity
|
|
24
23
|
# end
|
25
24
|
#
|
26
25
|
class Resource
|
27
|
-
include
|
26
|
+
include ActiveModel::Model
|
27
|
+
include ActiveModel::Attributes
|
28
|
+
|
28
29
|
include Sanity::Mutatable
|
29
30
|
include Sanity::Queryable
|
30
31
|
include Sanity::Serializable
|
data/lib/sanity/serializable.rb
CHANGED
@@ -50,8 +50,9 @@ module Sanity
|
|
50
50
|
|
51
51
|
def class_serializer
|
52
52
|
@class_serializer ||= proc do |results|
|
53
|
-
results
|
54
|
-
|
53
|
+
key = results.key?("result") ? "result" : "documents"
|
54
|
+
results[key].map do |result|
|
55
|
+
attributes = result.slice(*attribute_names)
|
55
56
|
new(**attributes.transform_keys(&:to_sym))
|
56
57
|
end
|
57
58
|
end
|
data/lib/sanity/version.rb
CHANGED
data/lib/sanity.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "active_model"
|
3
4
|
require "forwardable"
|
4
5
|
require "sanity/refinements"
|
5
6
|
|
@@ -8,8 +9,8 @@ require "sanity/configuration"
|
|
8
9
|
|
9
10
|
require "sanity/groqify"
|
10
11
|
require "sanity/http"
|
12
|
+
require "sanity/helpers"
|
11
13
|
|
12
|
-
require "sanity/attributable"
|
13
14
|
require "sanity/mutatable"
|
14
15
|
require "sanity/queryable"
|
15
16
|
require "sanity/serializable"
|
data/sanity.gemspec
CHANGED
@@ -5,12 +5,12 @@ require_relative "lib/sanity/version"
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "sanity-ruby"
|
7
7
|
spec.version = Sanity::VERSION
|
8
|
-
spec.authors = "
|
9
|
-
spec.email = "
|
8
|
+
spec.authors = "Drew Monroe"
|
9
|
+
spec.email = "drew@pinecreeklabs.com"
|
10
10
|
|
11
11
|
spec.summary = "Ruby bindings for the Sanity API"
|
12
12
|
spec.description = ""
|
13
|
-
spec.homepage = "https://github.com/
|
13
|
+
spec.homepage = "https://github.com/dvmonroe/sanity-ruby"
|
14
14
|
spec.license = "MIT"
|
15
15
|
spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
|
16
16
|
|
@@ -26,4 +26,6 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.bindir = "exe"
|
27
27
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
28
|
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_dependency "activemodel"
|
29
31
|
end
|
metadata
CHANGED
@@ -1,17 +1,31 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sanity-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Drew Monroe
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
11
|
+
date: 2024-02-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activemodel
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
description: ''
|
14
|
-
email:
|
28
|
+
email: drew@pinecreeklabs.com
|
15
29
|
executables: []
|
16
30
|
extensions: []
|
17
31
|
extra_rdoc_files: []
|
@@ -42,6 +56,8 @@ files:
|
|
42
56
|
- lib/sanity/groq/select.rb
|
43
57
|
- lib/sanity/groq/slice.rb
|
44
58
|
- lib/sanity/groqify.rb
|
59
|
+
- lib/sanity/helpers.rb
|
60
|
+
- lib/sanity/helpers/type_helper.rb
|
45
61
|
- lib/sanity/http.rb
|
46
62
|
- lib/sanity/http/create.rb
|
47
63
|
- lib/sanity/http/create_if_not_exists.rb
|
@@ -66,13 +82,13 @@ files:
|
|
66
82
|
- lib/sanity/serializable.rb
|
67
83
|
- lib/sanity/version.rb
|
68
84
|
- sanity.gemspec
|
69
|
-
homepage: https://github.com/
|
85
|
+
homepage: https://github.com/dvmonroe/sanity-ruby
|
70
86
|
licenses:
|
71
87
|
- MIT
|
72
88
|
metadata:
|
73
|
-
homepage_uri: https://github.com/
|
74
|
-
source_code_uri: https://github.com/
|
75
|
-
changelog_uri: https://github.com/
|
89
|
+
homepage_uri: https://github.com/dvmonroe/sanity-ruby
|
90
|
+
source_code_uri: https://github.com/dvmonroe/sanity-ruby
|
91
|
+
changelog_uri: https://github.com/dvmonroe/sanity-ruby
|
76
92
|
post_install_message:
|
77
93
|
rdoc_options: []
|
78
94
|
require_paths:
|