camille 0.6.4 → 1.1.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: 8d5bb9ed1aaea6f00edbd04bf5d20a37d1a6f3cac39afc9a589e8e458f4c5363
4
- data.tar.gz: c3e50816796af03af2b1be68cfaf635bb0ee6cc692451caadf927cc0f0f53b56
3
+ metadata.gz: 9cce4fa44ca836262ebc8da14ad045ee0b5ea2ce832fd6852e863280c04b6658
4
+ data.tar.gz: cfc0c1797ce19035efd81de11b1176154f50575b3d4a90834ef6de517ef1ea4b
5
5
  SHA512:
6
- metadata.gz: d109a1064725e968ad7c89a5b0814ecb3e2f3ba58004c680d26548baaea3a0306e992511e51bc73a7856202a60749c50de342d56902cee722872f6803625f83e
7
- data.tar.gz: 60bfc88c5b15e31ce42dbcff1f86cfe673c14c5510a5813b1900cdf76aa8cc58d590fdb85a618dd3ddcc65f75ff8ddd070f8150f3af0aa2e4988b2890c2dc498
6
+ metadata.gz: f502c8340be0ecb804982d811a35072188e7cb1fdc6602cc2c986cea94228caaae2d650d4379c3ba413299186bd8753befc51f6e6943d720384a841b876425f5
7
+ data.tar.gz: cf6fc100a3e11ade528d88d5fbe89451c37866a218b7ddb2c0b0fc18645b7ceb40dd393b813af80ac22908d545017fa6bfe74927010a67ce1fb4c35b7ff8928d
data/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.1.0
4
+
5
+ ### Added
6
+
7
+ * Added support for HTTP verbs `put`, `patch` and `delete`.
8
+
9
+ ## 1.0.0
10
+
11
+ ### Changed
12
+
13
+ * **[BREAKING]** Removed `Camille::Type#test` in favour of `Camille::Type#check`.
14
+ * Decimal and DateTime types are no longer generated for installation.
15
+
3
16
  ## 0.6.4
4
17
 
5
18
  ### Changed
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- camille (0.6.3)
4
+ camille (1.0.0)
5
5
  rails (>= 6.1, < 8.1)
6
6
 
7
7
  GEM
@@ -108,6 +108,7 @@ GEM
108
108
  net-smtp
109
109
  marcel (1.0.4)
110
110
  mini_mime (1.1.5)
111
+ mini_portile2 (2.8.9)
111
112
  minitest (5.25.4)
112
113
  net-imap (0.5.6)
113
114
  date
@@ -119,6 +120,9 @@ GEM
119
120
  net-smtp (0.5.1)
120
121
  net-protocol
121
122
  nio4r (2.7.4)
123
+ nokogiri (1.17.2)
124
+ mini_portile2 (~> 2.8.2)
125
+ racc (~> 1.4)
122
126
  nokogiri (1.17.2-x86_64-linux)
123
127
  racc (~> 1.4)
124
128
  psych (5.2.1)
@@ -210,4 +214,4 @@ DEPENDENCIES
210
214
  rspec-rails
211
215
 
212
216
  BUNDLED WITH
213
- 2.2.33
217
+ 2.7.2
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Camille
2
2
 
3
+ ![Gem Version](https://img.shields.io/gem/v/camille)
4
+
3
5
  ## Why?
4
6
 
5
7
  Traditionally, the JSON response from a Rails API server isn't typed. So even if we have TypeScript at the front-end, we still have little guarantee that our back-end would return the correct type and structure of data.
@@ -29,10 +31,6 @@ Therefore, if the front-end requests the API by calling `data`, we have guarante
29
31
 
30
32
  By using these request functions, we also don't need to know about HTTP verbs and paths. It's impossible to have unrecognized routes, since Camille will make sure that each function handled by the correct Rails action.
31
33
 
32
- ## Tutorial
33
-
34
- There's a step by step tutorial for setting up and showcasing Camille: https://github.com/onyxblade/camille-tutorial.
35
-
36
34
  ## Installation
37
35
 
38
36
  Add this line to your application's Gemfile:
@@ -94,7 +92,7 @@ The `params` type for an endpoint is required to be an object type, or a hash in
94
92
 
95
93
  Camille will automatically add a Rails route for each endpoint. You don't need to do anything other than having the schema file in place.
96
94
 
97
- When defining an endpoint, you can also use `post` instead of `get` for non-idempotent requests. However, no other HTTP verbs are supported, because verbs in RESTful like `patch` and `delete` indicate what we do on resources, but in RPC-style design each request is merely a function call that does not concern RESTful resources.
95
+ When defining an endpoint, you can use any of `get`, `post`, `put`, `patch`, or `delete`.
98
96
 
99
97
  ### Custom types
100
98
 
@@ -128,14 +126,15 @@ Each custom type is considered a type alias in TypeScript. And `alias_of` define
128
126
  type Product = {id: number, name: string}
129
127
  ```
130
128
 
131
- You can perform a type check on a value using `test`, which might be handy in testing:
129
+ You can perform a type check on a value using `check`, which can be handy in testing:
132
130
 
133
131
  ```ruby
134
- error = Camille::Types::Product.test(hash)
135
- if error.nil?
132
+ # `check` will return either a Camille::Checked or a Camille::TypeError
133
+ result = Camille::Types::Product.check(hash)
134
+ if result.checked?
136
135
  # the hash is accepted by Camille::Types::Product type
137
136
  else
138
- p error
137
+ p result
139
138
  end
140
139
  ```
141
140
 
@@ -161,7 +160,7 @@ params(
161
160
  # an array of objects also works
162
161
  object_array: {
163
162
  field: Number
164
- }[]
163
+ }[],
165
164
  # a union type is two types connected by '|'
166
165
  union: Number | String,
167
166
  # an intersection type is two types connected by '&'
@@ -264,6 +263,10 @@ object:
264
263
 
265
264
  Everything in `config/camille/types` and `config/camille/schemas` will automatically reload after changes in development environment, just like other files in Rails.
266
265
 
266
+ ## Versioning
267
+
268
+ This project uses [Semantic Versioning](https://semver.org/).
269
+
267
270
  ## Development
268
271
 
269
272
  Run tests with `bundle exec rake`.
@@ -10,15 +10,14 @@ module Camille
10
10
  copy_file "configuration.rb", "config/camille/configuration.rb"
11
11
  end
12
12
 
13
- def create_date_time_and_decimal
14
- copy_file "date_time.rb", "config/camille/types/date_time.rb"
15
- copy_file "decimal.rb", "config/camille/types/decimal.rb"
16
- end
17
-
18
13
  def create_schemas_folder
19
14
  copy_file ".keep", "config/camille/schemas/.keep"
20
15
  end
21
16
 
17
+ def create_types_folder
18
+ copy_file ".keep", "config/camille/types/.keep"
19
+ end
20
+
22
21
  end
23
22
  end
24
23
  end
@@ -46,5 +46,17 @@ module Camille
46
46
  def self.post name, &block
47
47
  define_endpoint :post, name, &block
48
48
  end
49
+
50
+ def self.put name, &block
51
+ define_endpoint :put, name, &block
52
+ end
53
+
54
+ def self.patch name, &block
55
+ define_endpoint :patch, name, &block
56
+ end
57
+
58
+ def self.delete name, &block
59
+ define_endpoint :delete, name, &block
60
+ end
49
61
  end
50
- end
62
+ end
data/lib/camille/type.rb CHANGED
@@ -23,13 +23,8 @@ module Camille
23
23
  @underlying.check value
24
24
  end
25
25
 
26
- def test value
27
- result = check value
28
- result.type_error? ? result : nil
29
- end
30
-
31
- def self.test value
32
- new.test value
26
+ def self.check value
27
+ new.check value
33
28
  end
34
29
 
35
30
  def self.klass_name
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Camille
4
- VERSION = "0.6.4"
4
+ VERSION = "1.1.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: camille
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.4
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - merely
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2025-04-18 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: rails
@@ -107,7 +106,6 @@ licenses:
107
106
  metadata:
108
107
  homepage_uri: https://github.com/onyxblade/camille
109
108
  source_code_uri: https://github.com/onyxblade/camille
110
- post_install_message:
111
109
  rdoc_options: []
112
110
  require_paths:
113
111
  - lib
@@ -122,8 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
120
  - !ruby/object:Gem::Version
123
121
  version: '0'
124
122
  requirements: []
125
- rubygems_version: 3.5.16
126
- signing_key:
123
+ rubygems_version: 3.6.9
127
124
  specification_version: 4
128
125
  summary: Typed API schema for Rails with TypeScript codegen
129
126
  test_files: []