dflat 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,19 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ gem "namaste"
7
+ gem "anvl"
8
+ gem "lockit"
9
+ gem "checkm"
10
+ gem "i18n"
11
+
12
+ # Add dependencies to develop your gem here.
13
+ # Include everything needed to run rake, tests, features, etc.
14
+ group :development do
15
+ gem "shoulda", ">= 0"
16
+ gem "bundler", "~> 1.0.0"
17
+ gem "jeweler", "~> 1.5.1"
18
+ gem "rcov", ">= 0"
19
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,31 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ anvl (0.1.0)
5
+ checkm (0.0.1)
6
+ git (1.2.5)
7
+ i18n (0.4.1)
8
+ jeweler (1.5.1)
9
+ bundler (~> 1.0.0)
10
+ git (>= 1.2.5)
11
+ rake
12
+ lockit (0.0.0)
13
+ namaste (0.0.0)
14
+ i18n
15
+ rake (0.8.7)
16
+ rcov (0.9.9)
17
+ shoulda (2.11.3)
18
+
19
+ PLATFORMS
20
+ ruby
21
+
22
+ DEPENDENCIES
23
+ anvl
24
+ bundler (~> 1.0.0)
25
+ checkm
26
+ i18n
27
+ jeweler (~> 1.5.1)
28
+ lockit
29
+ namaste
30
+ rcov
31
+ shoulda
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Chris Beer
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = dflat
2
+
3
+ Ruby implementation of Dflat
4
+
5
+ == Contributing to dflat
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 Chris Beer. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,52 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "dflat"
16
+ gem.homepage = "http://github.com/cbeer/dflat"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{Ruby Dflat implementation}
19
+ gem.email = "chris@cbeer.info"
20
+ gem.authors = ["Chris Beer"]
21
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
22
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
23
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
24
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ require 'rcov/rcovtask'
36
+ Rcov::RcovTask.new do |test|
37
+ test.libs << 'test'
38
+ test.pattern = 'test/**/test_*.rb'
39
+ test.verbose = true
40
+ end
41
+
42
+ task :default => :test
43
+
44
+ require 'rake/rdoctask'
45
+ Rake::RDocTask.new do |rdoc|
46
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
47
+
48
+ rdoc.rdoc_dir = 'rdoc'
49
+ rdoc.title = "dflat #{version}"
50
+ rdoc.rdoc_files.include('README*')
51
+ rdoc.rdoc_files.include('lib/**/*.rb')
52
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
data/lib/dflat.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'dflat/home'
2
+ require 'dflat/dir'
3
+ require 'dnatural'
4
+ module Dflat
5
+ VERSION = 'Dflat/0.19'
6
+ end
data/lib/dflat/dir.rb ADDED
@@ -0,0 +1,6 @@
1
+ module Dflat
2
+ class Dir < ::Dir
3
+ include Namaste::Mixin
4
+ include LockIt::Mixin
5
+ end
6
+ end
data/lib/dflat/home.rb ADDED
@@ -0,0 +1,107 @@
1
+ require 'namaste'
2
+ require 'lockit'
3
+ require 'anvl'
4
+ require 'dnatural'
5
+
6
+ module Dflat
7
+ class Home # < ::Dir
8
+ include Namaste::Mixin
9
+ include LockIt::Mixin
10
+
11
+ DEFAULT_PROPERTIES = { :objectScheme => 'Dflat/0.19',
12
+ :manifestScheme => 'Checkm/0.1',
13
+ :fullScheme => 'Dnatural/0.19',
14
+ :deltaScheme => 'Dnatural/0.19',
15
+ :currentScheme => 'file',
16
+ :classScheme => 'CLOP/0.3' }
17
+
18
+ def self.mkdir path, integer=0777, args = {}
19
+ Dir.mkdir path, integer
20
+ d = Home.new path
21
+ d.type = Dflat::VERSION
22
+ v = d.version! 'v001', nil
23
+ d.info = args[:info] || DEFAULT_PROPERTIES
24
+ d
25
+ end
26
+
27
+ attr_reader :path
28
+ def initialize path, args = {}
29
+ @path = path
30
+ @info = nil
31
+ end
32
+
33
+ def info
34
+ # xxx parse it with anvl
35
+ return @info if @info
36
+ return @info = {} unless File.exists? File.join(path, 'dflat-info.txt')
37
+
38
+ anvl = open(File.join(path, 'dflat-info.txt')).read
39
+ @info = ANVL.parse anvl
40
+ end
41
+
42
+ def info=(properties = @info)
43
+ File.open(File.join(path, 'dflat-info.txt'), 'w') { |f| f.write(ANVL.to_anvl(properties)) }
44
+ end
45
+
46
+ def log
47
+
48
+ end
49
+
50
+ def current
51
+ v = current_version
52
+ return nil unless v
53
+ version(v)
54
+ end
55
+
56
+ def version version
57
+ # xxx use namaste 'type' to load the right dir..
58
+ Dnatural::Dir.new File.join(path, version)
59
+ end
60
+
61
+ def version! dest = nil, src = nil
62
+ lock
63
+ dest ||= next_version
64
+ if src
65
+ FileUtils.cp_r File.join(path, src), File.join(path, dest)
66
+ else
67
+ if current_version
68
+ FileUtils.cp_r current.path, File.join(path, dest)
69
+ else
70
+ new_version(dest)
71
+ self.current = dest
72
+ end
73
+ end
74
+
75
+ unlock
76
+ return version(dest)
77
+ end
78
+
79
+ def current= version
80
+ version = version.version if version.respond_to? :version
81
+ return false unless File.directory? File.join(path, version)
82
+ File.open(File.join(path, 'current.txt'), 'w') { |f| f.write(version) }
83
+ @current = version
84
+ end
85
+
86
+ def versions
87
+ ::Dir.glob(File.join(path, 'v*')).map
88
+ end
89
+
90
+ def select &block
91
+ d = Dir.new path
92
+ d.select &block
93
+ end
94
+ private
95
+ def new_version version
96
+ d = Dnatural::Dir.mkdir File.join(path, version)
97
+ end
98
+
99
+ def current_version
100
+ @current ||= open(File.join(path, 'current.txt')).read.strip rescue nil
101
+ end
102
+
103
+ def next_version
104
+ "v%03d" % (self.versions.map { |x| File.basename(x).sub(/^v/, '').to_i }.max + 1)
105
+ end
106
+ end
107
+ end
data/lib/dnatural.rb ADDED
@@ -0,0 +1,81 @@
1
+ require 'checkm'
2
+ require 'namaste'
3
+ require 'fileutils'
4
+ require 'lockit'
5
+
6
+ module Dnatural
7
+ VERSION = 'Dnatural/0.17'
8
+ class Dir < ::Dir
9
+ include Namaste::Mixin
10
+ include LockIt::Mixin
11
+
12
+ def self.mkdir path, integer=0777, args = {}
13
+ super path, integer
14
+ d = Dir.new path
15
+ d.type = Dnatural::VERSION
16
+
17
+ ::Dir.chdir(d.path) do
18
+ ::Dir.mkdir 'admin'
19
+ ::Dir.mkdir 'consumer'
20
+ ::Dir.mkdir 'producer'
21
+ ::Dir.mkdir 'system'
22
+ end
23
+
24
+ d
25
+ end
26
+
27
+ def version
28
+ File.basename(path)
29
+ end
30
+
31
+ def manifest
32
+ data = ''
33
+ data = open(File.join(path, 'manifest.txt')).read if File.exists? File.join(path, 'manifest.txt')
34
+ @manifest ||= Checkm::Manifest.new data
35
+ end
36
+
37
+ def manifest!
38
+ @manifest = nil
39
+ manifest
40
+ end
41
+
42
+ def list
43
+ glob('**/*')
44
+ end
45
+
46
+ def add src, dest, options = {}
47
+ file = FileUtils.cp src, File.join(path, dest), options
48
+
49
+ manifest!
50
+
51
+ lock
52
+ m = manifest.add dest, :base => path
53
+ File.open(File.join(path, 'manifest.txt'), 'w') do |f|
54
+ f.write(m.to_s)
55
+ end
56
+
57
+ unlock
58
+
59
+ File.new File.join(path, dest)
60
+ end
61
+
62
+ def remove list, options = {}
63
+ list = [list] if list.instance_of? String
64
+ FileUtils.rm list.map { |x| File.join(path, x) }, options
65
+
66
+ m = manifest!
67
+ lock
68
+
69
+ list.each do |l|
70
+ m = m.remove l
71
+ end
72
+
73
+ File.open(File.join(path, 'manifest.txt'), 'w') do |f|
74
+ f.write(m.to_s)
75
+ end
76
+
77
+ unlock
78
+ end
79
+
80
+ end
81
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'dflat'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,73 @@
1
+ require 'helper'
2
+ require 'tempfile'
3
+
4
+ class TestDflat < Test::Unit::TestCase
5
+ context "Dflat home" do
6
+ setup do
7
+ t = Tempfile.new 'dflat'
8
+ d = File.dirname t.path
9
+
10
+ FileUtils.rm_rf File.join(d, 'test')
11
+ @dflat = Dflat::Home.mkdir File.join(d, 'test')
12
+ end
13
+
14
+ should "contain core files" do
15
+ files = []
16
+ Dir.chdir(@dflat.path) do
17
+ files = Dir.glob(File.join('**', '*'))
18
+ end
19
+ assert_contains(files, '0=dflat_0.19')
20
+ assert_contains(files, 'current.txt')
21
+ assert_contains(files, 'dflat-info.txt')
22
+ assert_contains(files, 'v001')
23
+ assert_contains(files, 'v001/0=dnatural_0.17')
24
+ end
25
+
26
+ should "point to versioned content" do
27
+ assert_equal(File.basename(@dflat.current.path), 'v001')
28
+ assert_equal(open(File.join(@dflat.path, 'current.txt')).read, 'v001')
29
+ end
30
+
31
+
32
+ should "have dflat info" do
33
+ info = @dflat.info
34
+ assert_equal(info[:objectScheme], 'Dflat/0.19')
35
+ end
36
+
37
+ should "update dflat info" do
38
+ info = @dflat.info
39
+ info[:test] = 'abcdef'
40
+ @dflat.info = info
41
+ info = @dflat.info
42
+ assert_equal(info[:test], 'abcdef')
43
+ end
44
+
45
+ should "add file to current version" do
46
+ file = @dflat.current.add 'LICENSE.txt', 'producer/abcdef'
47
+ lines = @dflat.current.manifest!.to_s.split "\n"
48
+ assert_equal(lines[0], '#%checkm_0.7')
49
+ assert_match(/producer\/abcdef/, lines[1])
50
+ assert_equal(@dflat.current.manifest.valid?, true)
51
+ end
52
+
53
+ should "remove file from current version" do
54
+ file = @dflat.current.add 'LICENSE.txt', 'producer/abcdef'
55
+ @dflat.current.remove 'producer/abcdef'
56
+ lines = @dflat.current.manifest!.to_s.split "\n"
57
+ assert_equal(lines.length, 1)
58
+ assert_equal(lines[0], '#%checkm_0.7')
59
+ end
60
+
61
+ should "do basic dnatural versioning" do
62
+ version = @dflat.version!
63
+
64
+ assert_equal(@dflat.current.version, 'v001')
65
+ assert_equal(open(File.join(@dflat.path, 'current.txt')).read, 'v001')
66
+
67
+ @dflat.current = version
68
+
69
+ assert_equal(File.basename(version.path), 'v002')
70
+ assert_equal(open(File.join(@dflat.path, 'current.txt')).read, 'v002')
71
+ end
72
+ end
73
+ end
metadata ADDED
@@ -0,0 +1,210 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dflat
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Chris Beer
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-11-26 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ type: :runtime
23
+ prerelease: false
24
+ name: namaste
25
+ version_requirements: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 3
31
+ segments:
32
+ - 0
33
+ version: "0"
34
+ requirement: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ type: :runtime
37
+ prerelease: false
38
+ name: anvl
39
+ version_requirements: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
48
+ requirement: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ type: :runtime
51
+ prerelease: false
52
+ name: lockit
53
+ version_requirements: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ requirement: *id003
63
+ - !ruby/object:Gem::Dependency
64
+ type: :runtime
65
+ prerelease: false
66
+ name: checkm
67
+ version_requirements: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ requirement: *id004
77
+ - !ruby/object:Gem::Dependency
78
+ type: :runtime
79
+ prerelease: false
80
+ name: i18n
81
+ version_requirements: &id005 !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ hash: 3
87
+ segments:
88
+ - 0
89
+ version: "0"
90
+ requirement: *id005
91
+ - !ruby/object:Gem::Dependency
92
+ type: :development
93
+ prerelease: false
94
+ name: shoulda
95
+ version_requirements: &id006 !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ hash: 3
101
+ segments:
102
+ - 0
103
+ version: "0"
104
+ requirement: *id006
105
+ - !ruby/object:Gem::Dependency
106
+ type: :development
107
+ prerelease: false
108
+ name: bundler
109
+ version_requirements: &id007 !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ~>
113
+ - !ruby/object:Gem::Version
114
+ hash: 23
115
+ segments:
116
+ - 1
117
+ - 0
118
+ - 0
119
+ version: 1.0.0
120
+ requirement: *id007
121
+ - !ruby/object:Gem::Dependency
122
+ type: :development
123
+ prerelease: false
124
+ name: jeweler
125
+ version_requirements: &id008 !ruby/object:Gem::Requirement
126
+ none: false
127
+ requirements:
128
+ - - ~>
129
+ - !ruby/object:Gem::Version
130
+ hash: 1
131
+ segments:
132
+ - 1
133
+ - 5
134
+ - 1
135
+ version: 1.5.1
136
+ requirement: *id008
137
+ - !ruby/object:Gem::Dependency
138
+ type: :development
139
+ prerelease: false
140
+ name: rcov
141
+ version_requirements: &id009 !ruby/object:Gem::Requirement
142
+ none: false
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ hash: 3
147
+ segments:
148
+ - 0
149
+ version: "0"
150
+ requirement: *id009
151
+ description:
152
+ email: chris@cbeer.info
153
+ executables: []
154
+
155
+ extensions: []
156
+
157
+ extra_rdoc_files:
158
+ - LICENSE.txt
159
+ - README.rdoc
160
+ files:
161
+ - .document
162
+ - Gemfile
163
+ - Gemfile.lock
164
+ - LICENSE.txt
165
+ - README.rdoc
166
+ - Rakefile
167
+ - VERSION
168
+ - lib/dflat.rb
169
+ - lib/dflat/dir.rb
170
+ - lib/dflat/home.rb
171
+ - lib/dnatural.rb
172
+ - test/helper.rb
173
+ - test/test_dflat.rb
174
+ has_rdoc: true
175
+ homepage: http://github.com/cbeer/dflat
176
+ licenses:
177
+ - MIT
178
+ post_install_message:
179
+ rdoc_options: []
180
+
181
+ require_paths:
182
+ - lib
183
+ required_ruby_version: !ruby/object:Gem::Requirement
184
+ none: false
185
+ requirements:
186
+ - - ">="
187
+ - !ruby/object:Gem::Version
188
+ hash: 3
189
+ segments:
190
+ - 0
191
+ version: "0"
192
+ required_rubygems_version: !ruby/object:Gem::Requirement
193
+ none: false
194
+ requirements:
195
+ - - ">="
196
+ - !ruby/object:Gem::Version
197
+ hash: 3
198
+ segments:
199
+ - 0
200
+ version: "0"
201
+ requirements: []
202
+
203
+ rubyforge_project:
204
+ rubygems_version: 1.3.7
205
+ signing_key:
206
+ specification_version: 3
207
+ summary: Ruby Dflat implementation
208
+ test_files:
209
+ - test/helper.rb
210
+ - test/test_dflat.rb