box 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/box.rb +29 -11
  2. data/lib/box/version.rb +2 -2
  3. metadata +3 -3
data/lib/box.rb CHANGED
@@ -1,22 +1,40 @@
1
1
  module Box
2
2
  class File
3
- def self.load
4
- files = {}
3
+ def self.caller_files(keep = 3)
4
+ ## Here there be dragons.
5
+ caller(1).map { |line| line.split(/:(?=\d|in )/, 3)[0,1] }.flatten
6
+ end
7
+
8
+ def self.inline_templates
9
+ prioritized_callers = caller_files.reverse
5
10
 
6
- if defined?(DATA)
7
- DATA.read.split(/^@@ /).each do |chunk|
8
- if chunk != ""
9
- file_name = chunk.match(/(\A\w+.\w+)/)[0]
10
- file_content = chunk.split(/\A\w+.\w+\n/)[1]
11
+ ## ARGH, loops! I'm sorry.
12
+ loop do
13
+ file = prioritized_callers.shift
11
14
 
12
- files[file_name] = file_content
13
- end
15
+ begin
16
+ io = ::IO.respond_to?(:binread) ? ::IO.binread(file) : ::IO.read(file)
17
+ app, @data = io.gsub("\r\n", "\n").split(/^__END__$/, 2)
18
+ rescue Errno::ENOENT
19
+ app, @data = nil
14
20
  end
21
+
22
+ break if @data || prioritized_callers.empty?
15
23
  end
16
24
 
17
- files
25
+ if @data
26
+ file_names = @data.scan(/^@@\s*(\S*)\s*$/).flatten
27
+ file_contents = @data.split(/\n^@@.*$\n/)
28
+ file_contents.shift
29
+ end
30
+
31
+ unless file_names.nil?
32
+ Hash[file_names.zip(file_contents)]
33
+ else
34
+ {}
35
+ end
18
36
  end
19
37
  end
20
38
 
21
- FILES = Box::File.load
39
+ FILES = Box::File.inline_templates
22
40
  end
@@ -1,8 +1,8 @@
1
1
  module Box
2
2
  module Version
3
3
  MAJOR = 0
4
- MINOR = 0
5
- PATCH = 2
4
+ MINOR = 1
5
+ PATCH = 0
6
6
 
7
7
  def self.to_s
8
8
  [MAJOR, MINOR, PATCH].join('.')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: box
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-21 00:00:00.000000000 Z
12
+ date: 2013-01-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -56,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
56
56
  version: '0'
57
57
  requirements: []
58
58
  rubyforge_project:
59
- rubygems_version: 1.8.22
59
+ rubygems_version: 1.8.24
60
60
  signing_key:
61
61
  specification_version: 3
62
62
  summary: A dead simple inline filesystem for your ruby scripts