camille 0.5.2 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a5d2a7ffaa4c7361b74237e051c928076a5d67b1e05629804c7fa1ab28af76e3
4
- data.tar.gz: 8b341b964c8a3527f5ab0b11565bb1cbf12b525413f4eec0bba2e4292551528e
3
+ metadata.gz: 9ebcd5a9f0f1efd10108a596a8e4e442eb5afd3975728cd2ec51319563ae504e
4
+ data.tar.gz: '0889d8c954ef2983e27f7b9d97d396db0edb46251b6b55febc1f1427e9c3391f'
5
5
  SHA512:
6
- metadata.gz: c2dbd934c66958f439dd803a0ca7bdc43c19089d4b5a303a644644be2e6ef021937be9b2b7c95a7e929d044b33f28fd12be9056578c5151bb9c6694f875b53c6
7
- data.tar.gz: 5c63fe09fd9080e6995db273891dabb3ca90c417c488f58488ae32d1a5d84ad72e7804ad45fbcbfa77685195ca6e4d54f6d3bb693b10762bccfbc4686e487179
6
+ metadata.gz: 5247e53a9b76e8117247ef8d5e7c83d27cb57b3c8bf4971a5ee978e168e1e1e1c58a1348522ec7d2a4ab530d958d044c7c670a464e5cd5c02fadf046284e97c4
7
+ data.tar.gz: b64ab07566a56d4e407ec887af105493b4af9dd99c0fa4c1e32de32fce6e54d9e78ca375ba59377f8cecd0002f27bfc6822de2635612345ff67ea67efa305466
data/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.5.4
4
+
5
+ ### Added
6
+
7
+ * Symbols are now accepted in string literal types
8
+
9
+ ### Changed
10
+
11
+ * Reverted previous change to use `{}` for omitted response type
12
+
13
+ ## 0.5.3
14
+
15
+ ### Added
16
+
17
+ * Added boolean literal types
18
+
19
+ ### Changed
20
+
21
+ * Renamed `Camille::ControllerExtension` to `Camille::Controller`
22
+
3
23
  ## 0.5.2
4
24
 
5
25
  ### Added
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- camille (0.5.1)
4
+ camille (0.5.3)
5
5
  rails (>= 6.1, < 8)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -160,6 +160,7 @@ params(
160
160
  # literal types
161
161
  number_literal: 1,
162
162
  string_literal: 'hello',
163
+ boolean_literal: false,
163
164
  # a custom type we defined above
164
165
  product: Product,
165
166
  # Pick and Omit accepts a type and an array of symbols
@@ -42,6 +42,8 @@ module Camille
42
42
  Camille::Types::NumberLiteral.new(value)
43
43
  when value.is_a?(::String)
44
44
  Camille::Types::StringLiteral.new(value)
45
+ when value == true || value == false
46
+ Camille::Types::BooleanLiteral.new(value)
45
47
  when value.is_a?(Camille::BasicType)
46
48
  value
47
49
  when value.is_a?(Class) && value < Camille::BasicType && value.directly_instantiable?
@@ -1,5 +1,5 @@
1
1
  module Camille
2
- module ControllerExtension
2
+ module Controller
3
3
  class TypeError < ::StandardError; end
4
4
  class ArgumentError < ::ArgumentError; end
5
5
 
@@ -12,7 +12,9 @@ module Camille
12
12
  end
13
13
 
14
14
  def signature
15
- @response_type ||= Camille::Types::Object.new({})
15
+ unless @response_type
16
+ raise UnknownResponseError.new("Endpoint lacking a `response` definition.")
17
+ end
16
18
  if @params_type
17
19
  "#{ActiveSupport::Inflector.camelize @name, false}(params: #{@params_type.literal}): Promise<#{@response_type.literal}>"
18
20
  else
@@ -4,8 +4,8 @@ module Camille
4
4
  class Railtie < ::Rails::Railtie
5
5
 
6
6
  initializer "camille.configure_rails" do |app|
7
- ActionController::API.include(Camille::ControllerExtension)
8
- ActionController::Base.include(Camille::ControllerExtension)
7
+ ActionController::API.include(Camille::Controller)
8
+ ActionController::Base.include(Camille::Controller)
9
9
 
10
10
  Camille::Loader.setup_zeitwerk_loader(app)
11
11
 
@@ -0,0 +1,27 @@
1
+ module Camille
2
+ module Types
3
+ class BooleanLiteral < Camille::BasicType
4
+ class ArgumentError < ::ArgumentError; end
5
+
6
+ attr_reader :value
7
+
8
+ def initialize value
9
+ if value == true || value == false
10
+ @value = value
11
+ else
12
+ raise ArgumentError.new("Expecting true or false, got #{value.inspect}")
13
+ end
14
+ end
15
+
16
+ def check value
17
+ unless value == @value
18
+ Camille::TypeError.new("Expected boolean literal #{@value.inspect}, got #{value.inspect}.")
19
+ end
20
+ end
21
+
22
+ def literal
23
+ @value.to_s
24
+ end
25
+ end
26
+ end
27
+ end
@@ -14,7 +14,8 @@ module Camille
14
14
  end
15
15
 
16
16
  def check value
17
- unless value == @value
17
+ transformed = value.is_a?(Symbol) ? value.to_s : value
18
+ unless transformed == @value
18
19
  Camille::TypeError.new("Expected string literal #{@value.inspect}, got #{value.inspect}.")
19
20
  end
20
21
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Camille
4
- VERSION = "0.5.2"
4
+ VERSION = "0.5.4"
5
5
  end
data/lib/camille.rb CHANGED
@@ -17,6 +17,7 @@ require_relative "camille/types/tuple"
17
17
  require_relative "camille/types/any"
18
18
  require_relative "camille/types/number_literal"
19
19
  require_relative "camille/types/string_literal"
20
+ require_relative "camille/types/boolean_literal"
20
21
  require_relative "camille/pick_and_omit"
21
22
  require_relative "camille/types/pick"
22
23
  require_relative "camille/types/omit"
@@ -29,7 +30,7 @@ require_relative "camille/schema"
29
30
  require_relative "camille/schemas"
30
31
  require_relative "camille/line"
31
32
  require_relative "camille/railtie"
32
- require_relative "camille/controller_extension"
33
+ require_relative "camille/controller"
33
34
  require_relative "camille/loader"
34
35
  require_relative "camille/configuration"
35
36
  require_relative "camille/code_generator"
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.5.2
4
+ version: 0.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - 辻彩
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-05-06 00:00:00.000000000 Z
11
+ date: 2023-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -51,7 +51,7 @@ files:
51
51
  - lib/camille/basic_type.rb
52
52
  - lib/camille/code_generator.rb
53
53
  - lib/camille/configuration.rb
54
- - lib/camille/controller_extension.rb
54
+ - lib/camille/controller.rb
55
55
  - lib/camille/endpoint.rb
56
56
  - lib/camille/generators/install_generator.rb
57
57
  - lib/camille/generators/schema_generator.rb
@@ -77,6 +77,7 @@ files:
77
77
  - lib/camille/types/any.rb
78
78
  - lib/camille/types/array.rb
79
79
  - lib/camille/types/boolean.rb
80
+ - lib/camille/types/boolean_literal.rb
80
81
  - lib/camille/types/null.rb
81
82
  - lib/camille/types/number.rb
82
83
  - lib/camille/types/number_literal.rb