crystalruby 0.1.5 → 0.1.6

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: e8dc48667be65ee6e6d36ba7efcfc87dfefb133a06cb375a22297db9643221e3
4
- data.tar.gz: 40753b3741ae9fb5dec86019d35968027517280a08ae6bffbcf8f2e207fe96b3
3
+ metadata.gz: 7c552102391f468b4974cb4ac36c4876001743fdec5fa8f2a69577255de4c52d
4
+ data.tar.gz: f7c104b10cf70eb03ab064117be946d4268c97063ba9302a99613e9c473ded97
5
5
  SHA512:
6
- metadata.gz: 1682a4405fd2baf66a93fc913af2146fa11e9806b90c8d6ac6d0eebc496b30415204474bd841377e3ea409401608f2907f58d7b717b21520cd4b1fe04d825d86
7
- data.tar.gz: 8682ebdcdd83bda6ab29261cdfc627afe1bd211343bc4caa95c9f08cbb30fba663f1aebcf4df1535e27d7a84377449d5028afcce145cc0a91c153721e2d261f1
6
+ metadata.gz: 0c01cefa9a6f820cd59aed62e02846bd90cd53a742c203b8de0023908c53e77ef2a558adf26023008dcd921e9c9cbc0466a63598361c18ec7cc6bee29a57ce2c
7
+ data.tar.gz: a9fe76d0b8a93dab4afd94d696d9955a81e75384fd1d4af8a0af5249c30fd51920d46de4728caab630862c889e799f1207f9915176fe861c6624e7a13d994e5a
data/README.md CHANGED
@@ -133,6 +133,31 @@ def add(a, b)
133
133
  end
134
134
  ```
135
135
 
136
+ ## Getting Started
137
+
138
+ The below is a stand-alone one-file script that allows you to quickly see crystalruby in action.
139
+
140
+ ```ruby
141
+ # crystalrubytest.rb
142
+ require 'bundler/inline'
143
+
144
+ gemfile do
145
+ source 'https://rubygems.org'
146
+ gem 'crystalruby', path: '../crystalruby'
147
+ end
148
+
149
+ require 'crystalruby'
150
+
151
+ module Adder
152
+ crystalize [a: :int, b: :int] => :int
153
+ def add(a, b)
154
+ a + b * 3
155
+ end
156
+ end
157
+
158
+ puts Adder.add(1, 2)
159
+ ```
160
+
136
161
  ## Types
137
162
 
138
163
  Currently primitive types are supported.
@@ -249,7 +274,7 @@ Remember to require these installed shards after installing them. E.g. inside `.
249
274
 
250
275
  You can edit the default paths for crystal source and library files from within the `./crystalruby.yaml` config file.
251
276
 
252
- ### Wrapping Crystal code in Ruby
277
+ ## Wrapping Crystal code in Ruby
253
278
 
254
279
  Sometimes you may want to wrap a Crystal method in Ruby, so that you can use Ruby before the Crystal code to prepare arguments, or after the Crystal code, to apply transformations to the result. A real-life example of this might be an ActionController method, where you might want to use Ruby to parse the request, perform auth etc., and then use Crystal to perform some heavy computation, before returning the result from Ruby.
255
280
  To do this, you simply pass a block to the `crystalize` method, which will serve as the Ruby entry point to the function. From within this block, you can invoke `super` to call the Crystal method, and then apply any Ruby transformations to the result.
@@ -270,7 +295,7 @@ end
270
295
  MyModule.add("1", "2")
271
296
  ```
272
297
 
273
- ### Release Builds
298
+ ## Release Builds
274
299
 
275
300
  You can control whether CrystalRuby builds in debug or release mode by setting following config option
276
301
 
@@ -303,7 +328,7 @@ CrystalRuby.compile!
303
328
 
304
329
  Then you can run this file as part of your build step, to ensure all Crystal code is compiled ahead of time.
305
330
 
306
- ### Troubleshooting
331
+ ## Troubleshooting
307
332
 
308
333
  The logic to detect when to JIT recompile is not robust and can end up in an inconsistent state. To remedy this it is useful to clear out all generated assets and build from scratch.
309
334
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Crystalruby
4
- VERSION = "0.1.5"
4
+ VERSION = "0.1.6"
5
5
  end
data/lib/crystalruby.rb CHANGED
@@ -292,10 +292,11 @@ module CrystalRuby
292
292
  "crystal build --release --no-debug -o #{lib_target} #{config.crystal_main_file}"
293
293
  end
294
294
 
295
- raise "Error compiling crystal code" unless result = system(cmd)
296
-
295
+ unless result = system(cmd)
296
+ File.delete("#{config.crystal_codegen_dir}/index.cr") if File.exist?("#{config.crystal_codegen_dir}/index.cr")
297
+ raise "Error compiling crystal code"
298
+ end
297
299
  @compiled = true
298
- File.delete("#{config.crystal_codegen_dir}/index.cr") if File.exist?("#{config.crystal_codegen_dir}/index.cr")
299
300
  end
300
301
  extend FFI::Library
301
302
  ffi_lib "#{config.crystal_lib_dir}/#{config.crystal_lib_name}"
@@ -303,7 +304,7 @@ module CrystalRuby
303
304
  const_set(:ErrorCallback, FFI::Function.new(:void, %i[string string]) do |error_type, message|
304
305
  error_type = error_type.to_sym
305
306
  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
+ error_type = is_exception_type ? Object.const_get(error_type) : RuntimeError
307
308
  raise error_type.new(message)
308
309
  end)
309
310
  attach_rb_error_handler(ErrorCallback)
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.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wouter Coppieters