loki 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -3,3 +3,4 @@
3
3
  .bundle
4
4
  Gemfile.lock
5
5
  pkg/*
6
+ example
@@ -0,0 +1,12 @@
1
+ Loki
2
+ ====
3
+
4
+ Loki is a highly experimental and simplistic Rake-like DSL. It is intended to work well with Thor.
5
+
6
+ This project is decidedly not ready for any kind of serious use yet.
7
+
8
+ License
9
+ -------
10
+
11
+ Copyright (c) 2011 Patrick Hogan, released under the MIT License.
12
+ http://www.opensource.org/licenses/mit-license
data/bin/loki CHANGED
@@ -2,4 +2,6 @@
2
2
 
3
3
  # require "rubygems"
4
4
 
5
- require File.expand_path(File.join(File.dirname(__FILE__), "..", "lib", "loki"))
5
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "lib", "loki"))
6
+
7
+ puts "This doesn't do anything useful yet."
@@ -15,7 +15,7 @@ require "loki/task/make"
15
15
 
16
16
  module Loki
17
17
 
18
- def self.task(name = :task, &block)
18
+ def task(name = :task, &block)
19
19
  task = Task::Task.new(name)
20
20
  task.instance_eval(&block)
21
21
  # task.list
@@ -27,7 +27,7 @@ module Loki
27
27
 
28
28
  def self.block_unique_id(&block)
29
29
  source = block.source_location
30
- ::File.expand_path(source[0]) + ":#{source[1]}"
30
+ ::File.expand_path(source[0]) + ":" + source[1].to_s
31
31
  end
32
32
 
33
33
  end # module
@@ -19,8 +19,8 @@ module Loki
19
19
  yield FilePath.new(file) if block_given?
20
20
  end
21
21
  end
22
-
23
-
22
+
23
+
24
24
  def interpolate_each(result_pattern, &block)
25
25
  each do |source_path|
26
26
  yield source_path, interpolate(source_path, result_pattern) if block_given?
@@ -51,8 +51,8 @@ module Loki
51
51
  def to_s
52
52
  @path.to_s
53
53
  end
54
-
55
-
54
+
55
+
56
56
  private
57
57
 
58
58
  def interpolate(source_path, result_pattern)
@@ -3,7 +3,7 @@ module Loki
3
3
  IDENTITY_MAP = {}
4
4
 
5
5
  module Identity
6
- def self.included(other)
6
+ def self.included(other)
7
7
  other.class_eval %{
8
8
  class << self
9
9
  alias_method :__#{other.to_s.gsub(':','')}_new, :new
@@ -1,7 +1,7 @@
1
1
  module Loki
2
2
  class Logger
3
3
  include Singleton
4
-
4
+
5
5
 
6
6
  COLORS = {
7
7
  :red => 31,
@@ -26,6 +26,11 @@ module Loki
26
26
  end
27
27
 
28
28
 
29
+ def indented?
30
+ @indent > 0
31
+ end
32
+
33
+
29
34
  def push
30
35
  @indent += 1
31
36
  end
@@ -44,10 +49,10 @@ module Loki
44
49
  def line
45
50
  $stdout.puts("-" * 80) if @indent == 0
46
51
  end
47
-
48
-
52
+
53
+
49
54
  public
50
-
55
+
51
56
  def paint(text, color = :white)
52
57
  "\e[#{COLORS[color]}m#{text}\e[0m"
53
58
  end
@@ -11,7 +11,7 @@ module Loki
11
11
 
12
12
 
13
13
  def work(&block)
14
- Loki.logger.puts "#{@name}"
14
+ Loki.logger.puts "#{@name}" if Loki.logger.indented?
15
15
  Loki.logger.push
16
16
  yield if block_given?
17
17
  Loki.logger.pull
@@ -56,7 +56,12 @@ module Loki
56
56
 
57
57
 
58
58
  def siblings
59
- @parent.children.reject { |task| task == self }
59
+ @parent.children.reject { |child| child.equal?(self) }
60
+ end
61
+
62
+
63
+ def siblings_prior
64
+ @parent.children.take_while { |child| !child.equal?(self) }
60
65
  end
61
66
 
62
67
 
@@ -4,7 +4,8 @@ module Loki
4
4
  include Identity
5
5
 
6
6
 
7
- def initialize(path)
7
+ def initialize(path, sources = nil)
8
+ @sources = Array(sources).map { |s| File.new(s) }
8
9
  @path = FilePath.new(path)
9
10
  super(@path.relative)
10
11
  end
@@ -15,6 +16,21 @@ module Loki
15
16
  end
16
17
 
17
18
 
19
+ def sources
20
+ @sources.collect(&:path)
21
+ end
22
+
23
+
24
+ def source_path
25
+ @sources.first.path
26
+ end
27
+
28
+
29
+ def result_path
30
+ @path.path
31
+ end
32
+
33
+
18
34
  def path
19
35
  @path.path
20
36
  end
@@ -31,7 +47,7 @@ module Loki
31
47
 
32
48
 
33
49
  def up_to_date?
34
- @children.none? { |task| task.time > time }
50
+ (@children + @sources).none? { |task| task.time > time }
35
51
  end
36
52
 
37
53
 
@@ -1,39 +1,42 @@
1
1
  module Loki
2
2
  module Task
3
- class Make < File
4
- include Identity
5
-
6
-
7
- def initialize(path, sources = nil)
8
- @sources = Array(sources).map { |s| File.new(s) }
9
- super(path)
10
- end
11
-
12
-
13
- def sources
14
- @sources.collect(&:path)
3
+ class Make < Task
4
+
5
+ def initialize(result_pattern, source_pattern = nil, &block)
6
+ @source_pattern = FilePattern.new(source_pattern)
7
+ @result_pattern = FilePattern.new(result_pattern)
8
+ @block = block
9
+ @expanded = false
10
+ super(source_pattern.to_s + " => " + result_pattern.to_s)
11
+ @children = nil
15
12
  end
16
13
 
17
14
 
18
- def source_path
19
- @sources.first.path
15
+ def children
16
+ @children ||= expand_patterns
20
17
  end
21
18
 
22
19
 
23
- def result_path
24
- @path.path
25
- end
26
-
27
-
28
- def up_to_date?
29
- (@children + @sources).none? { |task| task.time > time }
30
- end
31
-
32
- def test?
33
- @children.find_all { |task| task.time > time }.each do |o|
34
- ap "#{o.name} #{o.time}"
20
+ private
21
+
22
+ def expand_patterns
23
+ @children = []
24
+ if @source_pattern.nil?
25
+ if @result_pattern.individual?
26
+ add_dependency(File.new(@result_pattern.to_s), &@block)
27
+ else
28
+ raise "result must specify a single file if no source pattern specified"
29
+ end
30
+ else
31
+ if @result_pattern.individual?
32
+ add_dependency(File.new(@result_pattern, @source_pattern.to_a), &@block)
33
+ else
34
+ @source_pattern.interpolate_each(@result_pattern) do |source_path, result_path|
35
+ add_dependency(File.new(result_path, source_path), &@block)
36
+ end
37
+ end
35
38
  end
36
- (@children + @sources).reject(&:sham?).none? { |task| task.time > time }
39
+ @children
37
40
  end
38
41
 
39
42
  end # class
@@ -23,19 +23,7 @@ module Loki
23
23
 
24
24
 
25
25
  def make(result_pattern, source_pattern = nil, &block)
26
- if source_pattern.nil?
27
- add_dependency Make.new(result_pattern), &block
28
- else
29
- source_pattern = FilePattern.new(source_pattern)
30
- result_pattern = FilePattern.new(result_pattern)
31
- if result_pattern.individual?
32
- add_dependency Make.new(result_pattern, source_pattern.to_a), &block
33
- else
34
- source_pattern.interpolate_each(result_pattern) do |source_path, result_path|
35
- add_dependency Make.new(result_path, source_path), &block
36
- end
37
- end
38
- end
26
+ add_dependency Make.new(result_pattern, source_pattern, &block)
39
27
  end
40
28
 
41
29
 
@@ -49,7 +37,7 @@ module Loki
49
37
 
50
38
  def work
51
39
  super do
52
- @children.each do |task|
40
+ children.each do |task|
53
41
  task.work unless task.done?
54
42
  end
55
43
  end
@@ -57,18 +45,18 @@ module Loki
57
45
 
58
46
 
59
47
  def done?
60
- @children.reject(&:sham?).all?(&:done?)
48
+ children.reject(&:sham?).all?(&:done?)
61
49
  end
62
50
 
63
51
 
64
52
  def time
65
- @children.collect(&:time).max || super
53
+ children.collect(&:time).max || super
66
54
  end
67
55
 
68
56
 
69
57
  def list
70
58
  super do
71
- @children.each do |task|
59
+ children.each do |task|
72
60
  task.list
73
61
  end
74
62
  end
@@ -80,7 +68,7 @@ module Loki
80
68
  def add_dependency(task, &block)
81
69
  unless children.include?(task)
82
70
  task.parent = self
83
- children << task
71
+ @children << task
84
72
  task.evaluate(&block) if block_given?
85
73
  end
86
74
  task
@@ -1,3 +1,3 @@
1
1
  module Loki
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,8 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: loki
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 23
4
5
  prerelease:
5
- version: 0.0.2
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 4
10
+ version: 0.0.4
6
11
  platform: ruby
7
12
  authors:
8
13
  - Patrick Hogan
@@ -10,7 +15,7 @@ autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
17
 
13
- date: 2011-06-24 00:00:00 Z
18
+ date: 2011-06-30 00:00:00 Z
14
19
  dependencies: []
15
20
 
16
21
  description: A highly experimental and simplistic Rake-like DSL.
@@ -25,6 +30,7 @@ extra_rdoc_files: []
25
30
  files:
26
31
  - .gitignore
27
32
  - Gemfile
33
+ - README.markdown
28
34
  - Rakefile
29
35
  - bin/loki
30
36
  - lib/loki.rb
@@ -53,7 +59,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
53
59
  requirements:
54
60
  - - ">="
55
61
  - !ruby/object:Gem::Version
56
- hash: -3930385297513677759
62
+ hash: 3
57
63
  segments:
58
64
  - 0
59
65
  version: "0"
@@ -62,14 +68,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
62
68
  requirements:
63
69
  - - ">="
64
70
  - !ruby/object:Gem::Version
65
- hash: -3930385297513677759
71
+ hash: 3
66
72
  segments:
67
73
  - 0
68
74
  version: "0"
69
75
  requirements: []
70
76
 
71
77
  rubyforge_project:
72
- rubygems_version: 1.8.5
78
+ rubygems_version: 1.7.2
73
79
  signing_key:
74
80
  specification_version: 3
75
81
  summary: A highly experimental and simplistic Rake-like DSL.