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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 07a0d476e0764cb08d2117b7d538dd8e5a64ed11
4
- data.tar.gz: 2ccccc678e2395196cbff0c83a7b47f017196f3b
3
+ metadata.gz: 74395f3bd70b33d34c59da34c3e8cfcf58a6a53f
4
+ data.tar.gz: 425ee905e2b18d16bc61e770ab468b0c151f06fc
5
5
  SHA512:
6
- metadata.gz: f0a826099b4868083018805211858d24d463c5632fda704220bdc9b4c8f860e41cae6e94b6a8d669c6318d08f306b90fd5f50e3ce6a8a144ba222bc8a8422548
7
- data.tar.gz: df07b50d3d0654e87a88db32635e3c43dfd2dceff93e2056e050bd9ebac8d8b68c92fe16885c8f1cce94aef2230850d6810a1ff95f1bd5403b886461add6b76e
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', github: 'zhubert/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 "app/go" will get compiled into one namespace, so to get it to work with
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: "HandleFoo"
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 "app/go/upcase.go":
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::Client.upcase(["foo","bar"])
45
+ Malachite.upcase(["foo","bar"])
46
46
  => ["FOO", "BAR"]
47
47
  ```
48
48
 
49
- Or if you have more interesting data organize it with a struct:
49
+ More examples can be found in [examples](https://github.com/zhubert/malachite/wiki/Examples).
50
50
 
51
- ```go
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
- import "strings"
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
- type Foo struct {
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
- Some code trickery, quite honestly.
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 "app/go" folder
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
@@ -1,3 +1,3 @@
1
1
  module Malachite
2
- VERSION = '0.0.8'
2
+ VERSION = '0.0.9'
3
3
  end
data/lib/malachite.rb CHANGED
@@ -11,6 +11,10 @@ require 'malachite/file_compiler'
11
11
  require 'malachite/compiler'
12
12
 
13
13
  module Malachite
14
+ def self.method_missing(name, args)
15
+ Malachite::Client.new(name, args).call
16
+ end
17
+
14
18
  def self.load_json(string)
15
19
  JSON.parse(string)
16
20
  end
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.8
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-18 00:00:00.000000000 Z
11
+ date: 2015-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json