camille 0.6.3 → 1.0.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: 99c0d1cc96b49d7fe7e6262f5a81f07feeb476bb0c1d3902259cdaf3d346497e
4
- data.tar.gz: 1f9973ab623eb9d1322f116ba21eb1708bd5b32d8f3957798bfc87493bbaea1d
3
+ metadata.gz: a1ea493a56729858449f5d04a2242a0920a1aff7e345fde52d7fed3061b9cb3e
4
+ data.tar.gz: 624ef2a41e1c413e8e288de97f6b464f02ce51d9f2cda9eeed9b7ba4a818aaad
5
5
  SHA512:
6
- metadata.gz: 50fb0dd0da2ca88ab75652af3bd8481ef37185dbfaddd5913cbfa4a9a24d0887cfe4fe1d7b42f98287bbcbce0fbbf108434343a1d149102f1471df16451a3556
7
- data.tar.gz: f7d61181b15fa95ceff6e43f68148c3ca4bc03dbfbae89820250ce23028a78213fc255252b790e61890ff30a632c73442c1696c64372f1f56f9ecbf28d74928d
6
+ metadata.gz: 3bf2d9199a22c3a1a6f0c81538d93e87f4aacf073c52866fed0d07156f44af98d059c6559071554e275dc754bfd5413284acebf841e59f11659acfa9527827bc
7
+ data.tar.gz: 8b249d54deee18c77faebe8da95eda1ff6bae624daf67f9db1e54225951fca9259c5ef58f0c22393806ec5225c007f6962cdb377eff572a2bc20c97bb5c48859
data/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.0.0
4
+
5
+ ### Changed
6
+
7
+ * **[BREAKING]** Removed `Camille::Type#test` in favour of `Camille::Type#check`.
8
+ * Decimal and DateTime types are no longer generated for installation.
9
+
10
+ ## 0.6.4
11
+
12
+ ### Changed
13
+
14
+ * **[BREAKING]** Calling `transform` before `check` is now each custom type's responsibility. To migrate, copy the `check` method [here](https://github.com/onyxblade/camille/commit/00fb254667480c3a2ce222209b09f7afd714fd5d#diff-94b933f5da6d8a5cfd11e24fd89c85cd8e788e4f25ca86a94bbf8aaabaade207R13) to existing custom types that make use of `transform`.
15
+ * Warning comment is moved to config.ts_header.
16
+
3
17
  ## 0.6.3
4
18
 
5
19
  ### Added
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- camille (0.6.2)
4
+ camille (0.6.4)
5
5
  rails (>= 6.1, < 8.1)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -29,10 +29,6 @@ Therefore, if the front-end requests the API by calling `data`, we have guarante
29
29
 
30
30
  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
31
 
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
32
  ## Installation
37
33
 
38
34
  Add this line to your application's Gemfile:
@@ -128,14 +124,15 @@ Each custom type is considered a type alias in TypeScript. And `alias_of` define
128
124
  type Product = {id: number, name: string}
129
125
  ```
130
126
 
131
- You can perform a type check on a value using `test`, which might be handy in testing:
127
+ You can perform a type check on a value using `check`, which can be handy in testing:
132
128
 
133
129
  ```ruby
134
- error = Camille::Types::Product.test(hash)
135
- if error.nil?
130
+ # `check` will return either a Camille::Checked or a Camille::TypeError
131
+ result = Camille::Types::Product.check(hash)
132
+ if result.checked?
136
133
  # the hash is accepted by Camille::Types::Product type
137
134
  else
138
- p error
135
+ p result
139
136
  end
140
137
  ```
141
138
 
@@ -161,7 +158,7 @@ params(
161
158
  # an array of objects also works
162
159
  object_array: {
163
160
  field: Number
164
- }[]
161
+ }[],
165
162
  # a union type is two types connected by '|'
166
163
  union: Number | String,
167
164
  # an intersection type is two types connected by '&'
@@ -264,6 +261,10 @@ object:
264
261
 
265
262
  Everything in `config/camille/types` and `config/camille/schemas` will automatically reload after changes in development environment, just like other files in Rails.
266
263
 
264
+ ## Versioning
265
+
266
+ This project uses [Semantic Versioning](https://semver.org/).
267
+
267
268
  ## Development
268
269
 
269
270
  Run tests with `bundle exec rake`.
@@ -41,10 +41,6 @@ module Camille
41
41
  raise NotImplementedError
42
42
  end
43
43
 
44
- def transform value
45
- value
46
- end
47
-
48
44
  def self.| other
49
45
  Camille::Type.instance(self) | other
50
46
  end
@@ -4,7 +4,6 @@ module Camille
4
4
  module CodeGenerator
5
5
  def self.generate_ts
6
6
  io = StringIO.new
7
- io.puts "// This file is automatically generated."
8
7
  io.puts Camille::Configuration.ts_header
9
8
  io.puts
10
9
  Camille::Types.literal_lines.each do |line|
@@ -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
@@ -1,6 +1,7 @@
1
1
  Camille.configure do |config|
2
2
  # Contents to be placed at the beginning of the output TypeScript file.
3
3
  config.ts_header = <<~EOF
4
+ // DO NOT EDIT! This file is automatically generated.
4
5
  import request from './request'
5
6
  EOF
6
7
  end
@@ -9,4 +9,9 @@ class Camille::Types::DateTime < Camille::Type
9
9
  def transform value
10
10
  value.as_json
11
11
  end
12
+
13
+ def check value
14
+ normalized = transform value
15
+ super normalized
16
+ end
12
17
  end
@@ -13,4 +13,9 @@ class Camille::Types::Decimal < Camille::Type
13
13
  value
14
14
  end
15
15
  end
16
+
17
+ def check value
18
+ normalized = transform value
19
+ super normalized
20
+ end
16
21
  end
data/lib/camille/type.rb CHANGED
@@ -20,17 +20,11 @@ module Camille
20
20
  end
21
21
 
22
22
  def check value
23
- normalized = transform value
24
- @underlying.check normalized
23
+ @underlying.check value
25
24
  end
26
25
 
27
- def test value
28
- result = check value
29
- result.type_error? ? result : nil
30
- end
31
-
32
- def self.test value
33
- new.test value
26
+ def self.check value
27
+ new.check value
34
28
  end
35
29
 
36
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.3"
4
+ VERSION = "1.0.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: camille
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - merely
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-04-18 00:00:00.000000000 Z
11
+ date: 2025-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails