malachite 0.0.8 → 0.0.9
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 +12 -72
- data/lib/malachite/version.rb +1 -1
- data/lib/malachite.rb +4 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74395f3bd70b33d34c59da34c3e8cfcf58a6a53f
|
4
|
+
data.tar.gz: 425ee905e2b18d16bc61e770ab468b0c151f06fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee2075a956557036e812b06a6a8d573204bbace086615343a98f41c614b645b519fe9143558ad75e4626d6c56bfc871f6089b341136c7ee7c81c8d09ac11d76f
|
7
|
+
data.tar.gz: e396d11d21e26ecafa4df81f0ad19395c7b4eb457661a643e942fa2d0b8ac10b311e7e2a7485d24d28cf3163b59c3c30bce7a092704a623f12a00a4bcb245b19
|
data/README.md
CHANGED
@@ -9,20 +9,20 @@ Install [Go 1.5 or later](https://golang.org/doc/install) on relevant machines.
|
|
9
9
|
Add this to your Gemfile:
|
10
10
|
|
11
11
|
```ruby
|
12
|
-
gem 'malachite'
|
12
|
+
gem 'malachite'
|
13
13
|
```
|
14
14
|
|
15
15
|
Make a subdirectory of "app" called "go".
|
16
16
|
|
17
17
|
### Write Some Go Functions
|
18
18
|
|
19
|
-
Everything in
|
19
|
+
Everything in ```app/go```will get compiled into one namespace, so to get it to work with
|
20
20
|
Malachite, you need to:
|
21
21
|
|
22
|
-
* name the methods you want exported like:
|
23
|
-
* the Handle methods can only take one argument (use structs for more complexity)
|
22
|
+
* name the methods you want exported like: ```HandleFoo```
|
23
|
+
* the Handle methods can only take one argument (use [structs](https://github.com/zhubert/malachite/wiki/Structs) for more complexity)
|
24
24
|
|
25
|
-
For instance, if you wanted to upcase strings more quickly in your Rails app, you'd put the following in the file
|
25
|
+
For instance, if you wanted to upcase strings more quickly in your Rails app, you'd put the following in the file ```app/go/upcase.go```:
|
26
26
|
|
27
27
|
```go
|
28
28
|
package main
|
@@ -42,77 +42,23 @@ func HandleUpcase(things []string) (upperCased []string) {
|
|
42
42
|
Then use your function from Rails:
|
43
43
|
|
44
44
|
```ruby
|
45
|
-
Malachite
|
45
|
+
Malachite.upcase(["foo","bar"])
|
46
46
|
=> ["FOO", "BAR"]
|
47
47
|
```
|
48
48
|
|
49
|
-
|
49
|
+
More examples can be found in [examples](https://github.com/zhubert/malachite/wiki/Examples).
|
50
50
|
|
51
|
-
|
52
|
-
package main
|
53
|
-
|
54
|
-
import "strings"
|
55
|
-
|
56
|
-
type Person struct {
|
57
|
-
Name string `json:"name"`
|
58
|
-
Age string `json:"age"`
|
59
|
-
}
|
60
|
-
|
61
|
-
func HandleStructured(people []Person) (upperCasedPeople []Person) {
|
62
|
-
for _, person := range people {
|
63
|
-
upCase := Person{strings.ToUpper(person.Name), person.Age}
|
64
|
-
upperCasedPeople = append(upperCasedPeople, upCase)
|
65
|
-
}
|
66
|
-
return
|
67
|
-
}
|
68
|
-
```
|
69
|
-
|
70
|
-
```ruby
|
71
|
-
peeps = [{name: 'Peter', age: '27'},{name: 'Tim', age: '30'}]
|
72
|
-
Malachite::Client.structured(peeps)
|
73
|
-
=> [{"name"=>"PETER", "age"=>"27"}, {"name"=>"TIM", "age"=>"30"}]
|
74
|
-
```
|
75
|
-
|
76
|
-
Or even something totally arbitrary:
|
77
|
-
|
78
|
-
```go
|
79
|
-
package main
|
51
|
+
### Testing
|
80
52
|
|
81
|
-
|
82
|
-
|
83
|
-
type Person struct {
|
84
|
-
Name string `json:"name"`
|
85
|
-
}
|
53
|
+
I'd encourage writing tests for your Go code in the usual fashion. ```app/go/upcase_test.go``` would be the right place for it in the example above.
|
86
54
|
|
87
|
-
|
88
|
-
Friends []Person `json:"friends"`
|
89
|
-
Enemies []Person `json:"enemies"`
|
90
|
-
}
|
91
|
-
|
92
|
-
func HandleFrenemies(foo Foo) (frenemies []Person) {
|
93
|
-
for _, friend := range foo.Friends {
|
94
|
-
for _, enemy := range foo.Enemies {
|
95
|
-
if friend.Name == enemy.Name {
|
96
|
-
frenemies = append(frenemies, friend)
|
97
|
-
}
|
98
|
-
}
|
99
|
-
}
|
100
|
-
return
|
101
|
-
}
|
102
|
-
```
|
103
|
-
|
104
|
-
```ruby
|
105
|
-
friends = [{name: 'Peter'},{name: 'Tim'}]
|
106
|
-
enemies = [{name: 'Peter'},{name: 'Zeb'}]
|
107
|
-
Malachite::Client.frenemies({friends: friends, enemies: enemies})
|
108
|
-
=> [{"name"=>"Peter"}]
|
109
|
-
```
|
55
|
+
Slightly more detail found in [Testing](https://github.com/zhubert/malachite/wiki/Testing)
|
110
56
|
|
111
57
|
### How Does it Work?
|
112
58
|
|
113
|
-
|
59
|
+
One part code generation, another part pure evil.
|
114
60
|
|
115
|
-
* The first time the function is called, Malachite will build a shared library from all the Go code in your
|
61
|
+
* The first time the function is called, Malachite will build a shared library from all the Go code in your ```app/go``` folder
|
116
62
|
* It then uses Ruby's Fiddle to call the shared library
|
117
63
|
* Arguments are passed back and forth via JSON
|
118
64
|
|
@@ -121,9 +67,3 @@ Because of the JSON step, you'll only see real performance gains on computationa
|
|
121
67
|
### Ruby 2.2.4+
|
122
68
|
|
123
69
|
It's strongly recommended to use the [newest release of Ruby](https://www.ruby-lang.org/en/news/2015/12/16/unsafe-tainted-string-usage-in-fiddle-and-dl-cve-2015-7551/) as there was a security issue with older versions of Fiddle.
|
124
|
-
|
125
|
-
### TODO
|
126
|
-
|
127
|
-
* Confirm Go's existence, raise exception on build
|
128
|
-
* Error handling
|
129
|
-
* Benchmark performance...roughly
|
data/lib/malachite/version.rb
CHANGED
data/lib/malachite.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: malachite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zack Hubert
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|