trebor 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +4 -0
- data/Rakefile +10 -0
- data/bin/trebor +6 -0
- data/lib/trebor.rb +25 -0
- data/lib/trebor/command.rb +45 -0
- data/lib/trebor/context.rb +57 -0
- data/lib/trebor/domain.rb +31 -0
- data/lib/trebor/task.rb +18 -0
- data/lib/trebor/version.rb +3 -0
- data/lib/trebor/with.rb +21 -0
- data/lib/trebor/within.rb +22 -0
- data/test/command_test.rb +33 -0
- data/test/test_helper.rb +3 -0
- data/trebor.gemspec +22 -0
- metadata +91 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 77026d34d3fdfd41538cdb4b4c3c9234b57a8764
|
4
|
+
data.tar.gz: a32e91b55ccd3c877d2a840e28bf642079567fc9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3a9446e16f9d319d7012664c6a48269d7ccb2d45170ba8c2077c35c5995cd427dd4f25d5524551f1809079997fc54aed850ea761ba23b807bab93781977eb424
|
7
|
+
data.tar.gz: 5fc93aaa5fe0054b7964d8385653ce31ba992ccaadf4d61c00feb976c5afecdeb7587e93b3a66aff44f2873005a941fc70d51db711de71de5473def3d78108f5
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 daisuko
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
data/bin/trebor
ADDED
data/lib/trebor.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require "trebor/version"
|
2
|
+
require "logger"
|
3
|
+
|
4
|
+
module Trebor
|
5
|
+
class << self
|
6
|
+
def logger=(val)
|
7
|
+
@@logger = val
|
8
|
+
end
|
9
|
+
|
10
|
+
def logger
|
11
|
+
@@loger ||= Logger.new(STDOUT)
|
12
|
+
end
|
13
|
+
|
14
|
+
def run(file_name, command)
|
15
|
+
Context.new.tap {|context| context.load file_name}.parse(command)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
require_relative "trebor/domain"
|
21
|
+
require_relative "trebor/command"
|
22
|
+
require_relative "trebor/context"
|
23
|
+
require_relative "trebor/task"
|
24
|
+
require_relative "trebor/within"
|
25
|
+
require_relative "trebor/with"
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require "open3"
|
2
|
+
|
3
|
+
module Trebor
|
4
|
+
module Command
|
5
|
+
def within(directory, &block)
|
6
|
+
joined_directory = File.join(*[current_directory, directory].compact)
|
7
|
+
message = "Directory does not exist '#{joined_directory}'"
|
8
|
+
|
9
|
+
raise message unless test?(joined_directory, '-d')
|
10
|
+
Within.new(self, directory).action block
|
11
|
+
end
|
12
|
+
|
13
|
+
def with(environment, &block)
|
14
|
+
With.new(self, environment).action block
|
15
|
+
end
|
16
|
+
|
17
|
+
def as(name, &block)
|
18
|
+
# pending
|
19
|
+
end
|
20
|
+
|
21
|
+
def run(command)
|
22
|
+
Open3.popen3(fetch(command)) do |inn, out, err, wait|
|
23
|
+
inn.close
|
24
|
+
|
25
|
+
message = out.read.chomp
|
26
|
+
error = err.read.chomp
|
27
|
+
|
28
|
+
Trebor.logger.info message if !message.empty?
|
29
|
+
Trebor.logger.error error if !error.empty?
|
30
|
+
|
31
|
+
(wait ? wait.value : $?).exitstatus
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def test?(name, option)
|
36
|
+
command = %([ #{option} #{File.join *[current_directory, name].compact} ])
|
37
|
+
|
38
|
+
run(command) == 0
|
39
|
+
end
|
40
|
+
|
41
|
+
def call(*names)
|
42
|
+
toplevel.call(*names)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Trebor
|
2
|
+
class Context
|
3
|
+
include Domain
|
4
|
+
|
5
|
+
def initialize(parent = nil)
|
6
|
+
@vars = {}
|
7
|
+
@parent = parent
|
8
|
+
end
|
9
|
+
|
10
|
+
def context(name, &block)
|
11
|
+
Context.new(self).tap do |context|
|
12
|
+
self[name] = context
|
13
|
+
context.action block
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def task(name, &block)
|
18
|
+
self[name] = Task.new(self, block)
|
19
|
+
end
|
20
|
+
|
21
|
+
def action(block)
|
22
|
+
instance_eval &block
|
23
|
+
end
|
24
|
+
|
25
|
+
def lookup(names)
|
26
|
+
name = names.first
|
27
|
+
cdr = names[1..-1]
|
28
|
+
var = self[name]
|
29
|
+
|
30
|
+
var && cdr && cdr.any? ? var.lookup(cdr) : var
|
31
|
+
end
|
32
|
+
|
33
|
+
def call(*names)
|
34
|
+
var = toplevel.lookup(names)
|
35
|
+
|
36
|
+
raise "Don't know task #{names.join(":")}" unless var && var.is_a?(Task)
|
37
|
+
var.action
|
38
|
+
end
|
39
|
+
|
40
|
+
def parse(command)
|
41
|
+
command && call(*command.split(":"))
|
42
|
+
end
|
43
|
+
|
44
|
+
def load(file_name)
|
45
|
+
self.instance_eval open(file_name) {|f| f.read}, file_name
|
46
|
+
end
|
47
|
+
private
|
48
|
+
def [](name)
|
49
|
+
@vars[name.to_sym]
|
50
|
+
end
|
51
|
+
|
52
|
+
def []=(name, val)
|
53
|
+
raise "Already initialized #{name}" if @vars[name.to_sym]
|
54
|
+
@vars[name.to_sym] = val
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Trebor
|
2
|
+
module Domain
|
3
|
+
attr_reader :parent
|
4
|
+
|
5
|
+
def fetch(command)
|
6
|
+
parent ? parent.fetch(command) : command
|
7
|
+
end
|
8
|
+
|
9
|
+
def current_directory
|
10
|
+
parent && parent.current_directory
|
11
|
+
end
|
12
|
+
|
13
|
+
def toplevel
|
14
|
+
parent ? parent.toplevel : self
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
module InnerDomain
|
19
|
+
include Domain
|
20
|
+
|
21
|
+
attr_reader :command
|
22
|
+
|
23
|
+
def command
|
24
|
+
parent && parent.command
|
25
|
+
end
|
26
|
+
|
27
|
+
def action(block)
|
28
|
+
instance_eval &block
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/trebor/task.rb
ADDED
data/lib/trebor/with.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module Trebor
|
2
|
+
class With
|
3
|
+
include InnerDomain
|
4
|
+
|
5
|
+
attr_reader :environment, :command
|
6
|
+
|
7
|
+
def initialize(parent, environment)
|
8
|
+
@environment = environment.map do |key, val|
|
9
|
+
"#{key.upcase}=#{val}"
|
10
|
+
end.join(" ")
|
11
|
+
@command = parent.command
|
12
|
+
@parent = parent
|
13
|
+
|
14
|
+
self.extend @command
|
15
|
+
end
|
16
|
+
|
17
|
+
def fetch(command)
|
18
|
+
parent.fetch("%s %s" % [environment, command])
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Trebor
|
2
|
+
class Within
|
3
|
+
include InnerDomain
|
4
|
+
|
5
|
+
attr_reader :directory
|
6
|
+
|
7
|
+
def initialize(parent, directory)
|
8
|
+
@directory = directory
|
9
|
+
@parent = parent
|
10
|
+
|
11
|
+
self.extend parent.command
|
12
|
+
end
|
13
|
+
|
14
|
+
def fetch(command)
|
15
|
+
parent.fetch("cd %s; %s" % [directory, command])
|
16
|
+
end
|
17
|
+
|
18
|
+
def current_directory
|
19
|
+
File.join(*[parent.current_directory, directory].compact)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "minitest/autorun"
|
3
|
+
|
4
|
+
module Trebor
|
5
|
+
class TestCommand < Minitest::Test
|
6
|
+
def setup
|
7
|
+
@context = Context.new
|
8
|
+
|
9
|
+
@context.task :test_within do
|
10
|
+
self.stub(:test?, true) do
|
11
|
+
within '/some/directory' do
|
12
|
+
current_directory
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
@context.task :test_with do
|
18
|
+
with env: 'example' do
|
19
|
+
fetch 'CMD'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_within
|
25
|
+
assert_equal @context.call(:test_within), '/some/directory'
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_with
|
29
|
+
assert_equal @context.call(:test_with), 'ENV=example CMD'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
data/test/test_helper.rb
ADDED
data/trebor.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'trebor/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "trebor"
|
8
|
+
gem.version = Trebor::VERSION
|
9
|
+
gem.authors = ["daisuko"]
|
10
|
+
gem.email = ["striker.daisuko@gmail.com"]
|
11
|
+
gem.description = %q{Trebor is a small DSL}
|
12
|
+
gem.summary = %q{Trebor is a small DSL}
|
13
|
+
gem.homepage = "https://github.com/daisuko/trebor"
|
14
|
+
|
15
|
+
gem.add_development_dependency 'rake'
|
16
|
+
gem.add_development_dependency 'minitest'
|
17
|
+
|
18
|
+
gem.files = `git ls-files`.split($/)
|
19
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
20
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
21
|
+
gem.require_paths = ["lib"]
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: trebor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- daisuko
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Trebor is a small DSL
|
42
|
+
email:
|
43
|
+
- striker.daisuko@gmail.com
|
44
|
+
executables:
|
45
|
+
- trebor
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- bin/trebor
|
55
|
+
- lib/trebor.rb
|
56
|
+
- lib/trebor/command.rb
|
57
|
+
- lib/trebor/context.rb
|
58
|
+
- lib/trebor/domain.rb
|
59
|
+
- lib/trebor/task.rb
|
60
|
+
- lib/trebor/version.rb
|
61
|
+
- lib/trebor/with.rb
|
62
|
+
- lib/trebor/within.rb
|
63
|
+
- test/command_test.rb
|
64
|
+
- test/test_helper.rb
|
65
|
+
- trebor.gemspec
|
66
|
+
homepage: https://github.com/daisuko/trebor
|
67
|
+
licenses: []
|
68
|
+
metadata: {}
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options: []
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 2.2.2
|
86
|
+
signing_key:
|
87
|
+
specification_version: 4
|
88
|
+
summary: Trebor is a small DSL
|
89
|
+
test_files:
|
90
|
+
- test/command_test.rb
|
91
|
+
- test/test_helper.rb
|