camille 0.5.1 → 0.5.3

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: 54ba62877d8151101a93641018cc5516967bac05b2c437accc5861bd50f640da
4
- data.tar.gz: 7097f8975cce507a806ba77f022b79e797f6d607734d573fa3607de79ee03162
3
+ metadata.gz: f58d6bc69ec0ca18561254ccd7a8cb48caf134bca3b65b3694e09eda2d480c86
4
+ data.tar.gz: cf6a91b9ed549c095ec5b911e20fc92ea43c64b0634e3eaf9da8ebec29f7da24
5
5
  SHA512:
6
- metadata.gz: c17a00216823baa351ec0cb78f7e959c8c3ab17fd0533ba7f7265660024c08ac17f9086083519220589c9bd56480642b45b146b3b0aa1e4ac069c321d3b9f670
7
- data.tar.gz: f95bce0848370d9934673cd9fb367d43d0851718e3d37871f8e8f0005efb1263cb9c0cd03c9040fbfc928d15b4e996273b75ed9cf5481ad2f6abf5cd546bda3a
6
+ metadata.gz: 3ecfa0f3d4753d480e70967c1da84a9442121226d942c81bb24398ebeef2520148efd4d14b702532f69148dc50a5d70e35ff3de418df6df99077f96573754281
7
+ data.tar.gz: 0a39893452ae9461b50919c1cfa5a20cc29bf4b0e6c46b3bfd873128d71ff0b5329875755319104dbd071722941b935b2366476378b7d60238ddde990d01fa1c
data/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.5.3
4
+
5
+ ### Added
6
+
7
+ * Added boolean literal types
8
+
9
+ ### Changed
10
+
11
+ * Renamed `Camille::ControllerExtension` to `Camille::Controller`
12
+
13
+ ## 0.5.2
14
+
15
+ ### Added
16
+
17
+ * Symbols are now accepted in string types
18
+ * When omitted, the response type of an endpoint will now have the default `{}`
19
+
3
20
  ## 0.5.1
4
21
 
5
22
  ### Fixed
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,9 +12,7 @@ module Camille
12
12
  end
13
13
 
14
14
  def signature
15
- unless @response_type
16
- raise UnknownResponseError.new("Endpoint lacking a `response` definition.")
17
- end
15
+ @response_type ||= Camille::Types::Object.new({})
18
16
  if @params_type
19
17
  "#{ActiveSupport::Inflector.camelize @name, false}(params: #{@params_type.literal}): Promise<#{@response_type.literal}>"
20
18
  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
@@ -2,7 +2,7 @@ module Camille
2
2
  module Types
3
3
  class String < Camille::BasicType
4
4
  def check value
5
- unless value.is_a? ::String
5
+ unless value.is_a?(::String) || value.is_a?(Symbol)
6
6
  Camille::TypeError.new("Expected string, got #{value.inspect}.")
7
7
  end
8
8
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Camille
4
- VERSION = "0.5.1"
4
+ VERSION = "0.5.3"
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.1
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - 辻彩
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-04-25 00:00:00.000000000 Z
11
+ date: 2023-05-06 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