datacraft 0.1.1 → 0.2.0
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 +7 -5
- data/exe/dcraft +1 -0
- data/lib/datacraft/context.rb +4 -0
- data/lib/datacraft/instruction.rb +4 -0
- data/lib/datacraft/registry.rb +14 -13
- data/lib/datacraft/runner.rb +62 -8
- data/lib/datacraft/version.rb +1 -1
- 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: 0d5b93cedf58b0affe9e22abc1f1597a3de90c4e
|
4
|
+
data.tar.gz: d7592ee90f256ad37cd2c6b8b90a5b71cc397581
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0eb59fa1bb9d2cb546425393bd07f97c754c343a4d685eeb2e11b3c55061617ff1ec22626a16814bd5a0c0ce29e188205834af64f8a570dd85abf566d2a7116
|
7
|
+
data.tar.gz: 2cb72b1a6852382c61985f620c8542744af97dab13df5091d443e810cac397af54a46525e86a44169381b00748533a2eaa3c2b168a00f1fe90dd09a60d6596b0
|
data/README.md
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
# Datacraft
|
2
2
|
|
3
|
-
|
3
|
+
Play with data like a Pro, and have fun like Minecraft.
|
4
4
|
|
5
|
-
|
5
|
+
[](http://badge.fury.io/rb/datacraft)
|
6
|
+
[](https://travis-ci.org/xiaoxinghu/datacraft)
|
7
|
+
[](https://gemnasium.com/xiaoxinghu/datacraft)
|
8
|
+
[](https://codeclimate.com/github/xiaoxinghu/datacraft)
|
6
9
|
|
7
10
|
## Installation
|
8
11
|
|
@@ -22,7 +25,7 @@ Or install it yourself as:
|
|
22
25
|
|
23
26
|
## Usage
|
24
27
|
|
25
|
-
|
28
|
+
$ dcraft build inst.rb
|
26
29
|
|
27
30
|
## Development
|
28
31
|
|
@@ -32,10 +35,9 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
32
35
|
|
33
36
|
## Contributing
|
34
37
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
38
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/xiaoxinghu/datacraft. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
36
39
|
|
37
40
|
|
38
41
|
## License
|
39
42
|
|
40
43
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
-
|
data/exe/dcraft
CHANGED
data/lib/datacraft/context.rb
CHANGED
data/lib/datacraft/registry.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
1
3
|
module Datacraft
|
2
4
|
# for normalizing blocks
|
3
5
|
class CompatiableProc < Proc
|
@@ -8,12 +10,24 @@ module Datacraft
|
|
8
10
|
|
9
11
|
# common registry
|
10
12
|
class Registry
|
13
|
+
extend Forwardable
|
14
|
+
def_delegators :instances, :each, :map
|
11
15
|
def initialize
|
12
16
|
@items = []
|
13
17
|
end
|
14
18
|
|
15
19
|
attr_accessor :mandatory_methods
|
16
20
|
|
21
|
+
def instances
|
22
|
+
@instances ||= @items.map do |i|
|
23
|
+
if i[:klass]
|
24
|
+
i[:klass].new(*i[:args])
|
25
|
+
elsif i[:block]
|
26
|
+
CompatiableProc.new(&i[:block])
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
17
31
|
def <<(val)
|
18
32
|
klass = val[:klass]
|
19
33
|
block = val[:block]
|
@@ -32,19 +46,6 @@ module Datacraft
|
|
32
46
|
klass.method_defined? m
|
33
47
|
end
|
34
48
|
end
|
35
|
-
|
36
|
-
def each
|
37
|
-
@instances ||= @items.map do |i|
|
38
|
-
if i[:klass]
|
39
|
-
i[:klass].new(*i[:args])
|
40
|
-
elsif i[:block]
|
41
|
-
CompatiableProc.new(&i[:block])
|
42
|
-
end
|
43
|
-
end
|
44
|
-
@instances.each do |instance|
|
45
|
-
yield instance
|
46
|
-
end
|
47
|
-
end
|
48
49
|
end
|
49
50
|
|
50
51
|
class ProviderRegistry < Registry
|
data/lib/datacraft/runner.rb
CHANGED
@@ -1,17 +1,49 @@
|
|
1
|
+
require 'benchmark'
|
2
|
+
|
1
3
|
module Datacraft
|
2
4
|
# The runner for the whole process
|
3
5
|
module Runner
|
6
|
+
# run the instruction
|
4
7
|
def run(instruction)
|
5
8
|
context = instruction.context
|
6
|
-
|
7
|
-
|
8
|
-
context.
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
measurements = []
|
10
|
+
measurements << Benchmark.measure('pre build:') do
|
11
|
+
context.pre_hooks.each(&:call)
|
12
|
+
end
|
13
|
+
measurements << Benchmark.measure('process rows:') do
|
14
|
+
if context.options[:parallel]
|
15
|
+
pprocess_rows(
|
16
|
+
context.providers,
|
17
|
+
context.tweakers,
|
18
|
+
context.consumers)
|
19
|
+
else
|
20
|
+
process_rows(
|
21
|
+
context.providers,
|
22
|
+
context.tweakers,
|
23
|
+
context.consumers)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
measurements << Benchmark.measure('build:') do
|
28
|
+
build context.consumers
|
29
|
+
end
|
30
|
+
|
31
|
+
measurements << Benchmark.measure('post build:') do
|
32
|
+
context.post_hooks.each(&:call)
|
33
|
+
end
|
34
|
+
report measurements if context.options[:benchmark]
|
13
35
|
end
|
14
36
|
|
37
|
+
# output benchmark results
|
38
|
+
def report(measurements)
|
39
|
+
width = measurements.max_by { |m| m.label.size }.label.size + 1
|
40
|
+
puts "#{' ' * width}#{Benchmark::CAPTION}"
|
41
|
+
measurements.each do |m|
|
42
|
+
puts "#{m.label.to_s.ljust width} #{m}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# process rows sequentially
|
15
47
|
def process_rows(providers, tweakers, consumers)
|
16
48
|
providers.each do |provider|
|
17
49
|
provider.each do |row|
|
@@ -26,11 +58,33 @@ module Datacraft
|
|
26
58
|
end
|
27
59
|
end
|
28
60
|
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# process rows in parallel
|
64
|
+
def pprocess_rows(providers, tweakers, consumers)
|
65
|
+
threads = providers.map do |provider|
|
66
|
+
Thread.new(provider) do |p|
|
67
|
+
p.each do |row|
|
68
|
+
tweakers.each do |tweaker|
|
69
|
+
row = tweaker.tweak row
|
70
|
+
break unless row
|
71
|
+
end
|
72
|
+
next unless row
|
73
|
+
consumers.each do |consumer|
|
74
|
+
consumer << row
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
threads.each(&:join)
|
80
|
+
end
|
81
|
+
|
82
|
+
# build and close consumers
|
83
|
+
def build(consumers)
|
29
84
|
consumers.each do |consumer|
|
30
85
|
consumer.build if consumer.respond_to? :build
|
31
86
|
consumer.close if consumer.respond_to? :close
|
32
87
|
end
|
33
88
|
end
|
34
|
-
|
35
89
|
end
|
36
90
|
end
|
data/lib/datacraft/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: datacraft
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Xiaoxing Hu
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|