crystalruby 0.1.3 → 0.1.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: 157d03e574c1ef5e06073e71c29e259741c26373113f2ae51c692b4aaef429f9
4
- data.tar.gz: 94c1f670b52a39b78c961a3050c2587c540a1cb1593c30e87d6bd05d90a4d736
3
+ metadata.gz: 26b2e0d15fd3b320f700a1f0571b8bb5d8991a4ed1c60cfcd9f003b48bb9f891
4
+ data.tar.gz: 27243d104172eef50adfc46524a0b9052410636dc0b39e142fc3e53c04ded1f0
5
5
  SHA512:
6
- metadata.gz: 1b7972639977a290fd9a42b737edd1f3eec28a240a6e0e773619190bf646ec0707520d317ddf6e6152f507753b16fa66db0d2903c18fd23e58ebce4422e02555
7
- data.tar.gz: bc3d03de05c21a14a6d6d9b6de76ff04efcd660999c0dd2c166cc306707d0f93be01053e34ba8a531c9e0a9154e887bb1c6796b141564e290e25d537eeab88b4
6
+ metadata.gz: a54c1cf883a7dea97d66e9c18903139713aaec0b965026a21fc2e14ced85c13fc676f7d8e76ecc9a2e6ca2fc69034185a9fa4eb6fc66a6986cc9bb2d037738fb
7
+ data.tar.gz: 0f29fe7bad266af6593d0e4533af27a9be925372befe40ed0e4ee5ea8c9293c7ea62aab4b1664eaf3d2202eb3000b3dda1dfbdc44ae9e924e2de017f5516a6bc
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.1.4] - 2024-04-10
4
+
5
+ - Fix bug in type checking on deserialization of union types
6
+
3
7
  ## [0.1.3] - 2024-04-10
4
8
 
5
9
  - Support exceptions thrown in Crystal being caught in Ruby
data/README.md CHANGED
@@ -196,6 +196,22 @@ ArgumentError: Expected Bool but was Int at line 1, column 15
196
196
  from crystalruby.rb:303:in `block in compile!'
197
197
  ```
198
198
 
199
+ ## Named Types
200
+
201
+ You can name your types, for more succinct method signatures.
202
+ The type names will be mirrored in the generated Crystal code.
203
+ E.g.
204
+
205
+ ```ruby
206
+
207
+ IntArrOrBoolArr = crtype{ Array(Bool) | Array(Int32) }
208
+
209
+ crystalize [a: IntArrOrBoolArr] => json{ IntArrOrBoolArr }
210
+ def method_with_named_types(a)
211
+ return a
212
+ end
213
+ ```
214
+
199
215
  ## Exceptions
200
216
 
201
217
  Exceptions thrown in Crystal code can be caught in Ruby.
@@ -27,7 +27,11 @@ module CrystalRuby
27
27
  def interpret!(raw)
28
28
  union_types.each do |type|
29
29
  if type.interprets?(raw)
30
- return type.interpret!(raw)
30
+ begin
31
+ return type.interpret!(raw)
32
+ rescue
33
+ # Pass
34
+ end
31
35
  end
32
36
  end
33
37
  raise "Invalid deserialized value #{raw} for type #{inspect}"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Crystalruby
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.4"
5
5
  end
data/lib/crystalruby.rb CHANGED
@@ -112,7 +112,9 @@ module CrystalRuby
112
112
  fn_ret_type: return_type[:crystal_type],
113
113
  lib_fn_args: arg_types.map { |k, arg_type| "_#{k}: #{arg_type[:lib_type]}" }.join(","),
114
114
  lib_fn_ret_type: return_type[:lib_type],
115
- convert_lib_args: arg_types.map{|k, arg_type| "#{k} = #{arg_type[:convert_lib_to_crystal_type]["_#{k}"]}" }.join("\n "),
115
+ convert_lib_args: arg_types.map do |k, arg_type|
116
+ "#{k} = #{arg_type[:convert_lib_to_crystal_type]["_#{k}"]}"
117
+ end.join("\n "),
116
118
  arg_names: args.keys.join(","),
117
119
  convert_return_type: return_type[:convert_crystal_to_lib_type]["return_value"],
118
120
  error_value: return_type[:error_value]
@@ -212,7 +214,10 @@ module CrystalRuby
212
214
  FileUtils.mkdir_p "#{config.crystal_src_dir}/#{config.crystal_codegen_dir}"
213
215
  FileUtils.mkdir_p "#{config.crystal_lib_dir}"
214
216
  unless File.exist?("#{config.crystal_src_dir}/#{config.crystal_main_file}")
215
- IO.write("#{config.crystal_src_dir}/#{config.crystal_main_file}", "require \"./#{config.crystal_codegen_dir}/index\"\n")
217
+ IO.write(
218
+ "#{config.crystal_src_dir}/#{config.crystal_main_file}",
219
+ "require \"./#{config.crystal_codegen_dir}/index\"\n"
220
+ )
216
221
  end
217
222
  return if File.exist?("#{config.crystal_src_dir}/shard.yml")
218
223
 
@@ -295,12 +300,11 @@ module CrystalRuby
295
300
  extend FFI::Library
296
301
  ffi_lib "#{config.crystal_lib_dir}/#{config.crystal_lib_name}"
297
302
  attach_function :attach_rb_error_handler, [:pointer], :int
298
- const_set(:ErrorCallback, FFI::Function.new(:void, [:string, :string]) do |error_type, message|
303
+ const_set(:ErrorCallback, FFI::Function.new(:void, %i[string string]) do |error_type, message|
299
304
  error_type = error_type.to_sym
300
- error_type = Object.const_defined?(error_type) && Object.const_get(error_type).ancestors.include?(Exception) ?
301
- Object.const_get(error_type) :
302
- RuntimeError
303
- raise error_type.new(message)
305
+ is_exception_type = Object.const_defined?(error_type) && Object.const_get(error_type).ancestors.include?(Exception)
306
+ error_type = is_exception_type ? Object.const_get(error_type) : RuntimeError
307
+ raise error_type.new(message)
304
308
  end)
305
309
  attach_rb_error_handler(ErrorCallback)
306
310
  end
@@ -313,7 +317,9 @@ module CrystalRuby
313
317
  end
314
318
 
315
319
  def self.write_function(owner, name:, body:, &compile_callback)
316
- @compiled = File.exist?("#{config.crystal_src_dir}/#{config.crystal_codegen_dir}/index.cr") unless defined?(@compiled)
320
+ unless defined?(@compiled)
321
+ @compiled = File.exist?("#{config.crystal_src_dir}/#{config.crystal_codegen_dir}/index.cr")
322
+ end
317
323
  @block_store ||= []
318
324
  @block_store << { owner: owner, name: name, body: body, compile_callback: compile_callback }
319
325
  FileUtils.mkdir_p("#{config.crystal_src_dir}/#{config.crystal_codegen_dir}")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crystalruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wouter Coppieters