dsltasks 0.1.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 +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +37 -0
- data/Rakefile +3 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/dsltasks.gemspec +23 -0
- data/lib/dsltasks/dsltasks.rb +148 -0
- data/lib/dsltasks/version.rb +3 -0
- data/lib/dsltasks.rb +3 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1ff260a21086009f2c39962cd4adc9a29280a137
|
4
|
+
data.tar.gz: eade23ec2ec18079a763d079226011995e54ffda
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 57712882662a2aa7223c134c9f0fa132b4f34745acc9936bc4c7cef8161acecfcf4a83c7870b30afa2d2ac6a3b46d8c9a52e750ee36c42f543f74bc73f03f5e3
|
7
|
+
data.tar.gz: bb7ce45cb9edab55f49e9bbb61439fe1e1a5c2dd942d6fb1b37b77538516e14778554370ad6f29ce6f022c47837a9749f67c32e78410e72d88852d0cad00b171
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Jonathan Johnson
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# Dsltasks
|
2
|
+
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
|
6
|
+
Add this line to your application's Gemfile:
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
gem 'dsltasks'
|
10
|
+
```
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install dsltasks
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
|
23
|
+
## Development
|
24
|
+
|
25
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
26
|
+
|
27
|
+
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).
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/thejonjohn/dsltasks.
|
32
|
+
|
33
|
+
|
34
|
+
## License
|
35
|
+
|
36
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
37
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "dsltasks"
|
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
|
data/bin/setup
ADDED
data/dsltasks.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'dsltasks/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "dsltasks"
|
8
|
+
spec.version = DSLTasks::VERSION
|
9
|
+
spec.authors = ["Jonathan Johnson"]
|
10
|
+
spec.email = ["jonjohn@byu.net"]
|
11
|
+
|
12
|
+
spec.summary = %q{Library and framework based on the concept of tasks for creating DSLs}
|
13
|
+
spec.homepage = "https://github.com/thejonjohn/dsltasks"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
end
|
@@ -0,0 +1,148 @@
|
|
1
|
+
module DSLTasks
|
2
|
+
|
3
|
+
module TaskMixin
|
4
|
+
attr_reader :__block__
|
5
|
+
attr_reader :__name__
|
6
|
+
attr_reader :__parent_task__
|
7
|
+
attr_reader :__lib_stack__
|
8
|
+
attr_reader :__lib_dirs__
|
9
|
+
def __initialize_task_mixin__(opts={})
|
10
|
+
@__parent_task__ = opts[:parent]
|
11
|
+
@__name__ = opts[:name]
|
12
|
+
@__block__ = opts[:block]
|
13
|
+
@__lib_stack__ = opts[:lib_stack]
|
14
|
+
@__lib_dirs__ = opts[:lib_dirs] || (opts[:parent] ? opts[:parent].__lib_dirs__ : [])
|
15
|
+
@__root__ = opts[:root] || self
|
16
|
+
@__tasks__ = Hash.new
|
17
|
+
end
|
18
|
+
def __exec__(calling_task, args, block)
|
19
|
+
rvalue = nil
|
20
|
+
task_stack = DSLTasks::task_stack(@__root__)
|
21
|
+
task_stack.push self
|
22
|
+
unless block.nil?
|
23
|
+
args << block
|
24
|
+
end
|
25
|
+
rvalue = instance_exec(*args, &@__block__)
|
26
|
+
task_stack.pop
|
27
|
+
return rvalue
|
28
|
+
end
|
29
|
+
def __caller__()
|
30
|
+
(DSLTasks::task_stack(@__root__))[-2]
|
31
|
+
end
|
32
|
+
def lib(lib_name)
|
33
|
+
lib_name = lib_name.to_s
|
34
|
+
if lib_name.start_with?('/')
|
35
|
+
if File.exist?(lib_name)
|
36
|
+
unless @__lib_stack__.include?(fname)
|
37
|
+
@__lib_stack__.push(File.expand_path(lib_name))
|
38
|
+
instance_eval(File.read(lib_name), File.expand_path(lib_name))
|
39
|
+
@__lib_stack__.pop
|
40
|
+
end
|
41
|
+
else
|
42
|
+
raise "Lib file not found: #{lib_name}"
|
43
|
+
end
|
44
|
+
else
|
45
|
+
# search path if not absolute:
|
46
|
+
# directory of file of task from which lib was called
|
47
|
+
# directories in @__lib_dirs__, in order
|
48
|
+
dirnames = [File.dirname(@__lib_stack__[-1]), *@__lib_dirs__]
|
49
|
+
fnames = dirnames.map {|d| File.join(d, lib_name)}
|
50
|
+
fnames.map! {|f| f.end_with?('.rb') ? f : f+'.rb'}
|
51
|
+
found_lib = false
|
52
|
+
fnames.each do |fname|
|
53
|
+
if File.exist?(fname)
|
54
|
+
unless @__lib_stack__.include?(fname)
|
55
|
+
@__lib_stack__.push(File.expand_path(fname))
|
56
|
+
instance_eval(File.read(fname), File.expand_path(fname))
|
57
|
+
@__lib_stack__.pop
|
58
|
+
end
|
59
|
+
found_lib = true
|
60
|
+
break
|
61
|
+
end
|
62
|
+
end
|
63
|
+
if !found_lib
|
64
|
+
raise "Lib file not found in possible locations: #{fnames.join(',')}"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
def run_task(name, *args, block)
|
69
|
+
if @__tasks__.has_key?(name.to_sym)
|
70
|
+
task = @__tasks__[name.to_sym]
|
71
|
+
return task.__exec__(self, args, block)
|
72
|
+
elsif @__parent_task__
|
73
|
+
return @__parent_task__.run_task(name, *args, block)
|
74
|
+
else
|
75
|
+
raise "Unrecognized task: #{name}"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
def task(name, &block)
|
79
|
+
if block.nil?
|
80
|
+
if @__tasks__.has_key?(name.to_sym)
|
81
|
+
return @__tasks__[name.to_sym]
|
82
|
+
end
|
83
|
+
else
|
84
|
+
@__tasks__[name.to_sym] = Task.new(parent: self, lib_stack: @__lib_stack__.clone, name: name.to_sym, block: block, root: @__root__)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
def method_missing(name, *args, &block)
|
88
|
+
run_task(name, *args, block)
|
89
|
+
end
|
90
|
+
def respond_to_missing?(name, *args)
|
91
|
+
if @__tasks__.has_key?(name.to_sym)
|
92
|
+
return true
|
93
|
+
elsif @__parent_task__
|
94
|
+
return @__parent_task__.respond_to_missing?(name, *args)
|
95
|
+
else
|
96
|
+
return false
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
class Task
|
102
|
+
include TaskMixin
|
103
|
+
def initialize(*args)
|
104
|
+
__initialize_task_mixin__(*args)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
class DSLTaskContext
|
109
|
+
include TaskMixin
|
110
|
+
|
111
|
+
def initialize(base_file, lib_dirs=nil)
|
112
|
+
@__task_context__ = Hash.new
|
113
|
+
__initialize_task_mixin__(lib_stack: [base_file], lib_dirs: lib_dirs)
|
114
|
+
end
|
115
|
+
|
116
|
+
def execute(main, libs)
|
117
|
+
|
118
|
+
__lib_stack__.push(main)
|
119
|
+
(libs || []).each do |l|
|
120
|
+
lib l
|
121
|
+
end
|
122
|
+
__lib_stack__.pop
|
123
|
+
|
124
|
+
instance_eval(File.read(main), main)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
module_function
|
129
|
+
|
130
|
+
def task_stack(root)
|
131
|
+
@task_stacks ||= Hash.new {|h,k| h[k] = []}
|
132
|
+
return @task_stacks[root]
|
133
|
+
end
|
134
|
+
private :task_stack
|
135
|
+
|
136
|
+
def start(opts=nil)
|
137
|
+
lib_dirs = opts[:lib_dirs] || []
|
138
|
+
file = opts[:main]
|
139
|
+
if File.exist?(file)
|
140
|
+
file = File.expand_path(file)
|
141
|
+
context = DSLTaskContext.new(file, lib_dirs)
|
142
|
+
context.execute(file, opts[:libs])
|
143
|
+
else
|
144
|
+
raise "File not found: #{file}"
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|
data/lib/dsltasks.rb
ADDED
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dsltasks
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jonathan Johnson
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-15 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.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
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
|
+
description:
|
42
|
+
email:
|
43
|
+
- jonjohn@byu.net
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- ".travis.yml"
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- bin/console
|
55
|
+
- bin/setup
|
56
|
+
- dsltasks.gemspec
|
57
|
+
- lib/dsltasks.rb
|
58
|
+
- lib/dsltasks/dsltasks.rb
|
59
|
+
- lib/dsltasks/version.rb
|
60
|
+
homepage: https://github.com/thejonjohn/dsltasks
|
61
|
+
licenses:
|
62
|
+
- MIT
|
63
|
+
metadata: {}
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 2.5.1
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: Library and framework based on the concept of tasks for creating DSLs
|
84
|
+
test_files: []
|