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 +4 -4
- data/README.md +2 -0
- data/lib/ixby.rb +5 -0
- data/lib/rixby/version.rb +1 -1
- data/lib/rixby.rb +40 -2
- metadata +1 -2
- data/NOTES.md +0 -16
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ef6d5cf45dabe8f0517070a8d17ec40d31ed2c16f995730cd525bcaf241ebc9d
|
|
4
|
+
data.tar.gz: 7e16d744d8e27d45dd14862a6b6ece2b0ff235666599ef0477852181da3e2c17
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 86d9731737f512720ff0d59e266acf398a21181a2564cfd241eaa23749d8ec50c3cadd24f7fa5135b1107ab466516b35f59b7e239c1e082861dd5954919a2ed3
|
|
7
|
+
data.tar.gz: 8cfb9f99b2373cb875ced2f399bc53f2aabf834759681e7be1e7adfdff3a79cefe1ab386b1dc2f4cafaeea35a3a203c73b136fdce277b53e3f52db5747186155
|
data/README.md
CHANGED
data/lib/ixby.rb
CHANGED
data/lib/rixby/version.rb
CHANGED
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.
|
|
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