doem 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8903d4ac84d50377dffbbad5f4fba9cd92a8c42d
4
+ data.tar.gz: 58c90a74db2bad5b681543eae51c3ff11bb78493
5
+ SHA512:
6
+ metadata.gz: ac2e5c50d9ebc7a27a26dd58fb98ab746e22744b719c6dfe29a0cffb067c2e48ff88304dc6b480eb3738bdaebf61d001578b631e7e83e75bf926e7b8951c8934
7
+ data.tar.gz: d9bfedf54101ac778de73f7158b8fcd4696493e96be691b8467d132d564affac4705253a40c1cfacda64ab7e4cf4c6b64a3daf5c8d32aca4b1d6907ba50c8bb8
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .DS_Store
11
+ *.gem
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.5
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in doem.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 xiaoxing
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,41 @@
1
+ # Doem
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/doem`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'doem'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install doem
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/doem. 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
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << 'test'
6
+ t.libs << 'lib'
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task default: :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'doem'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ require 'pry'
11
+ Pry.start
12
+
13
+ # require 'irb'
14
+ # IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'doem/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'doem'
8
+ spec.version = Doem::VERSION
9
+ spec.authors = ['Xiaoxing Hu']
10
+ spec.email = ['dawnstar.hu@gmail.com']
11
+
12
+ spec.summary = 'Data OEM (Original Equipment Manufacturer)'
13
+ spec.description = 'doem works like an OEM but for data, '\
14
+ 'get data from source, process them, build the products '\
15
+ 'or parts that is used in another end product.'\
16
+ 'You get to desgin the instructions with a comprehensive DSL.'
17
+ spec.homepage = 'https://github.com/xiaoxinghu/doem'
18
+ spec.license = 'MIT'
19
+
20
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ spec.bindir = 'exe'
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ['lib']
24
+
25
+ spec.add_development_dependency 'bundler', '~> 1.10'
26
+ spec.add_development_dependency 'rake', '~> 10.0'
27
+ spec.add_development_dependency 'minitest', '~> 0'
28
+ spec.add_development_dependency 'pry', '~> 0'
29
+ end
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/doem/cli'
4
+
5
+ Doem::Cli.run(ARGV)
@@ -0,0 +1,9 @@
1
+ require 'doem/version'
2
+ require 'doem/registry'
3
+ require 'doem/context'
4
+ require 'doem/instruction'
5
+ require 'doem/runner'
6
+
7
+ module Doem
8
+ extend Doem::Runner
9
+ end
@@ -0,0 +1,16 @@
1
+ require 'doem'
2
+
3
+ module Doem
4
+ # command line interface
5
+ class Cli
6
+ def self.run(args)
7
+ unless args.size == 1
8
+ puts 'Syntax: brick your-script.rb'
9
+ exit(-1)
10
+ end
11
+ filename = args[0]
12
+ instruction = Instruction.from_file filename
13
+ Doem.run instruction
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,23 @@
1
+ module Doem
2
+ class Context
3
+ def providers
4
+ @providers ||= ProviderRegistry.new
5
+ end
6
+
7
+ def consumers
8
+ @consumers ||= ConsumerRegistry.new
9
+ end
10
+
11
+ def tweakers
12
+ @tweakers ||= TweakerRegistry.new
13
+ end
14
+
15
+ def pre_hooks
16
+ @pre_hooks ||= HookRegistry.new
17
+ end
18
+
19
+ def post_hooks
20
+ @post_hooks ||= HookRegistry.new
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,37 @@
1
+ module Doem
2
+ # Building Instruction
3
+ class Instruction
4
+ attr_reader :context
5
+
6
+ def initialize(context = Context.new)
7
+ @context = context
8
+ end
9
+
10
+ def pre_build(&block)
11
+ @context.pre_hooks << { block: block }
12
+ end
13
+
14
+ def from(klass, *initialization_params)
15
+ @context.providers << { klass: klass, args: initialization_params }
16
+ end
17
+
18
+ def tweak(klass = nil, *initialization_params, &block)
19
+ @context.tweakers << { klass: klass, args: initialization_params, block: block }
20
+ end
21
+
22
+ def to(klass, *initialization_params)
23
+ @context.consumers << { klass: klass, args: initialization_params }
24
+ end
25
+
26
+ def post_build(&block)
27
+ @context.post_hooks << { block: block }
28
+ end
29
+
30
+ def self.from_file(filename)
31
+ script_content = IO.read(filename)
32
+ instruction = Instruction.new
33
+ instruction.instance_eval(script_content)
34
+ instruction
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,69 @@
1
+ module Doem
2
+ # for normalizing blocks
3
+ class CompatiableProc < Proc
4
+ alias_method :run, :call
5
+ alias_method :process, :call
6
+ alias_method :tweak, :call
7
+ end
8
+
9
+ # common registry
10
+ class Registry
11
+ def initialize
12
+ @items = []
13
+ end
14
+
15
+ def mandatory_methods
16
+ []
17
+ end
18
+
19
+ def <<(val)
20
+ klass = val[:klass]
21
+ block = val[:block]
22
+ if klass
23
+ fail "#{klass.name} needs to implement methods: "\
24
+ "#{mandatory_methods}" unless valid? klass
25
+ @items << val[:klass].new(*val[:args])
26
+ elsif block
27
+ @items << CompatiableProc.new(&block)
28
+ else
29
+ fail 'registry error'
30
+ end
31
+ end
32
+
33
+ def valid?(klass)
34
+ mandatory_methods.all? do |m|
35
+ klass.method_defined? m
36
+ end
37
+ end
38
+
39
+ def each
40
+ @items.each do |item|
41
+ yield item
42
+ end
43
+ end
44
+ end
45
+
46
+ class ProviderRegistry < Registry
47
+ def mandatory_methods
48
+ [:each]
49
+ end
50
+ end
51
+
52
+ class ConsumerRegistry < Registry
53
+ def mandatory_methods
54
+ [:<<, :close]
55
+ end
56
+ end
57
+
58
+ class TweakerRegistry < Registry
59
+ def mandatory_methods
60
+ [:tweak]
61
+ end
62
+ end
63
+
64
+ class HookRegistry < Registry
65
+ def mandatory_methods
66
+ [:run]
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,36 @@
1
+ module Doem
2
+ # The runner for the whole process
3
+ module Runner
4
+ def run(instruction)
5
+ context = instruction.context
6
+ context.pre_hooks.each(&:call)
7
+ process_rows(
8
+ context.providers,
9
+ context.tweakers,
10
+ context.consumers
11
+ )
12
+ context.post_hooks.each(&:call)
13
+ end
14
+
15
+ def process_rows(providers, tweakers, consumers)
16
+ providers.each do |provider|
17
+ provider.each do |row|
18
+ tweakers.each do |tweaker|
19
+ row = tweaker.tweak row
20
+ break unless row
21
+ end
22
+ # nil means to dismiss the row
23
+ next unless row
24
+ consumers.each do |consumer|
25
+ consumer << row
26
+ end
27
+ end
28
+ end
29
+ consumers.each do |consumer|
30
+ consumer.build if consumer.respond_to? :build
31
+ consumer.close if consumer.respond_to? :close
32
+ end
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,3 @@
1
+ module Doem
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: doem
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Xiaoxing Hu
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-07-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: doem works like an OEM but for data, get data from source, process them,
70
+ build the products or parts that is used in another end product.You get to desgin
71
+ the instructions with a comprehensive DSL.
72
+ email:
73
+ - dawnstar.hu@gmail.com
74
+ executables:
75
+ - doem
76
+ extensions: []
77
+ extra_rdoc_files: []
78
+ files:
79
+ - ".gitignore"
80
+ - ".travis.yml"
81
+ - CODE_OF_CONDUCT.md
82
+ - Gemfile
83
+ - LICENSE.txt
84
+ - README.md
85
+ - Rakefile
86
+ - bin/console
87
+ - bin/setup
88
+ - doem.gemspec
89
+ - exe/doem
90
+ - lib/doem.rb
91
+ - lib/doem/cli.rb
92
+ - lib/doem/context.rb
93
+ - lib/doem/instruction.rb
94
+ - lib/doem/registry.rb
95
+ - lib/doem/runner.rb
96
+ - lib/doem/version.rb
97
+ homepage: https://github.com/xiaoxinghu/doem
98
+ licenses:
99
+ - MIT
100
+ metadata: {}
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 2.4.8
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: Data OEM (Original Equipment Manufacturer)
121
+ test_files: []