rixby 1.0.0 → 1.0.1

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: fc379f400b5e2b6213b52f64b4cc87c30138fab3f3ced3a0935b1e13a6a133ae
4
- data.tar.gz: b6d14233a8f412d5a8de2bd9daa284e0a96ef22dd2c59e741909abe513bb186a
3
+ metadata.gz: ef6d5cf45dabe8f0517070a8d17ec40d31ed2c16f995730cd525bcaf241ebc9d
4
+ data.tar.gz: 7e16d744d8e27d45dd14862a6b6ece2b0ff235666599ef0477852181da3e2c17
5
5
  SHA512:
6
- metadata.gz: 761bea6040e72373f4a2d58591b8b4240c8678bfd1ba60cd2b7c545e268c89caefd16a25a92df2cccce002d52545d1c1f864bc0faa758ec9e9c4d6e166784f40
7
- data.tar.gz: 6bddb361c92dd554440bed262f621d0fdeb1c0ccf423915dab7787cde2e484d69dd9b25e0ed2eb2b40c5b2fc54e38f99e4d866ac762b3f64d446db1f2c1aafd7
6
+ metadata.gz: 86d9731737f512720ff0d59e266acf398a21181a2564cfd241eaa23749d8ec50c3cadd24f7fa5135b1107ab466516b35f59b7e239c1e082861dd5954919a2ed3
7
+ data.tar.gz: 8cfb9f99b2373cb875ced2f399bc53f2aabf834759681e7be1e7adfdff3a79cefe1ab386b1dc2f4cafaeea35a3a203c73b136fdce277b53e3f52db5747186155
data/README.md CHANGED
@@ -42,6 +42,8 @@ p unit_square
42
42
 
43
43
  </tr>
44
44
 
45
+ </table>
46
+
45
47
  > [!TIP]
46
48
  > For a more complete example, see the `example` directory.
47
49
  > Start from `canvas.rb`.
data/lib/ixby.rb CHANGED
@@ -1 +1,6 @@
1
1
  require 'rixby'
2
+
3
+ # Back in the day, you had to activate RubyGems by passing `-rubygems`.
4
+ # This was really `-r` (for `require`) on a gem called `ubygems`, which was an alias for `rubygems`.
5
+ #
6
+ # This is a similar hack!
data/lib/rixby/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rixby
2
- VERSION = '1.0.0'
2
+ VERSION = '1.0.1'
3
3
  end
data/lib/rixby.rb CHANGED
@@ -6,10 +6,29 @@ if Ruby::Box.current == Ruby::Box.main
6
6
  Ruby::Box.main.instance_variable_set(:@__rixby_boxes, {})
7
7
  end
8
8
 
9
+ # Import items from a file.
10
+ #
11
+ # Requires a block in one of the following two forms:
12
+ #
13
+ # 1. Import particular items from the file (which must be `export`-ed):
14
+ # ```
15
+ # import { from 'file', :a, :b, :c }
16
+ # ```
17
+ #
18
+ # 2. Import everything which was `export`-ed from the file:
19
+ # ```
20
+ # import { all: 'file' }
21
+ # ```
22
+ #
23
+ # Imports are only visible to the current file.
24
+ # Files which import this file will not see the same imports.
25
+ #
9
26
  def import(&blk)
10
27
  unless block_given?
11
28
  raise 'you must pass a block to `import` describing the items to import'
12
29
  end
30
+
31
+ # The syntax uses a block specifically so that we can pinch the binding, and define new things in it
13
32
  block_binding = blk.binding
14
33
 
15
34
  import_desc = Rixby::ImportDsl.evaluate(&blk)
@@ -23,13 +42,16 @@ def import(&blk)
23
42
  absolute_filename += '.rb'
24
43
  end
25
44
 
45
+ # Only import each file into a box once.
46
+ # Otherwise we'll end up with a new definition of each class every time we import something, and
47
+ # they won't compare equally.
26
48
  imported_boxes = Ruby::Box.main.instance_variable_get(:@__rixby_boxes)
27
49
  if imported_boxes.has_key?(absolute_filename)
28
50
  box = imported_boxes[absolute_filename]
29
51
  else
30
52
  box = Ruby::Box.new
31
53
  box.instance_variable_set(:@__rixby_imported, true)
32
- box.require(__FILE__)
54
+ box.require(__FILE__) # Enable `import`/`export` in that file too
33
55
  box.require(absolute_filename)
34
56
  imported_boxes[absolute_filename] = box
35
57
  end
@@ -44,6 +66,7 @@ def import(&blk)
44
66
  raise 'internal error: malformed import array'
45
67
  end
46
68
 
69
+ # Copy imports into the current scope.
47
70
  imports.each do |import|
48
71
  export = exports[import] or raise(KeyError, "no export named `#{import}`")
49
72
 
@@ -58,6 +81,20 @@ def import(&blk)
58
81
  end
59
82
  end
60
83
 
84
+ # Export an item from this file, so it's visible to `import`.
85
+ #
86
+ # Call either on a method definition, or from within a class/module:
87
+ #
88
+ # ```
89
+ # export def something
90
+ # # ...
91
+ # end
92
+ #
93
+ # class Foobar export
94
+ # # ...
95
+ # end
96
+ # ```
97
+ #
61
98
  def export(item)
62
99
  # If this file isn't being imported, we can ignore `export`.
63
100
  # This is relevant if you `export` from the main file, where `singleton_method` doesn't seem to be
@@ -86,8 +123,9 @@ def export(item)
86
123
  exports = box.instance_variable_get(:@__rixby_exports)
87
124
  exports[key] = value
88
125
  end
89
- EXPORT_METHOD = method(:export)
90
126
 
127
+ # Enables `export` to be called from within a class or module to export that item
128
+ EXPORT_METHOD = method(:export)
91
129
  Module.define_method(:export) do
92
130
  EXPORT_METHOD.(self)
93
131
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rixby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Christiansen
@@ -17,7 +17,6 @@ extra_rdoc_files: []
17
17
  files:
18
18
  - ".tool-versions"
19
19
  - LICENSE
20
- - NOTES.md
21
20
  - README.md
22
21
  - example/assertion.rb
23
22
  - example/canvas.rb
data/NOTES.md DELETED
@@ -1,16 +0,0 @@
1
- explicit export is vital so you don't throw out all of your imports as exports
2
-
3
- the idea doesn't really work without this
4
-
5
- ```ruby
6
- export def x
7
-
8
- end
9
-
10
- export class X
11
-
12
- end
13
-
14
- export 3, as: Something
15
- ```
16
-