Class: Dflat::Home

Inherits:
Object
  • Object
show all
Includes:
LockIt::Mixin, Namaste::Mixin
Defined in:
lib/dflat/home.rb

Overview

< ::Dir

Constant Summary collapse

DEFAULT_PROPERTIES =
{ :objectScheme => 'Dflat/0.19', 
                     :manifestScheme => 'Checkm/0.1',
:fullScheme => 'Dnatural/0.19',
:deltaScheme => 'Dnatural/0.19',
                     :currentScheme => 'file',
:classScheme => 'CLOP/0.3' }

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, args = {}) ⇒ Home

Returns a new instance of Home.



28
29
30
31
# File 'lib/dflat/home.rb', line 28

def initialize path, args = {}
  @path = path
  @info = nil
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



27
28
29
# File 'lib/dflat/home.rb', line 27

def path
  @path
end

Class Method Details

.mkdir(path, integer = 0777, args = {}) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/dflat/home.rb', line 18

def self.mkdir path, integer=0777, args = {}
  ::Dir.mkdir path, integer
  d = Home.new path
  d.type = Dflat::VERSION
  d.info = args[:info] || DEFAULT_PROPERTIES
  d.init
  d
end

Instance Method Details

#[](version) ⇒ Object



104
105
106
# File 'lib/dflat/home.rb', line 104

def [] version
  export(version)
end

#checkoutObject



71
72
73
74
75
76
77
78
# File 'lib/dflat/home.rb', line 71

def checkout
  lock
  if current_version and not File.exists?  File.join(path, next_version)
	FileUtils.cp_r current.path, File.join(path, next_version)
  end
  unlock
  return version(next_version)
end

#commit(args = {}) ⇒ Object



80
81
82
83
84
85
# File 'lib/dflat/home.rb', line 80

def commit args = {}
  lock
  v = self.current = version(next_version)
  unlock
  v
end

#commit!Object



87
88
89
90
91
92
93
94
95
96
97
# File 'lib/dflat/home.rb', line 87

def commit!
  lock
  # xxx full -> redd?
  previous = current
  v = self.current = version(next_version)

  previous.to_delta(current)

  unlock
  v
end

#currentObject



50
51
52
53
54
# File 'lib/dflat/home.rb', line 50

def current
  v = current_version
  return nil unless v
  version(v)
end

#current=(version) ⇒ Object



108
109
110
111
112
113
114
# File 'lib/dflat/home.rb', line 108

def current= version
  version = version.version if version.respond_to? :version
  return false unless File.directory? File.join(path, version)
  File.open(File.join(path, 'current.txt'), 'w') { |f| f.write(version) }

  @current = version
end

#export(version) ⇒ Object



99
100
101
102
# File 'lib/dflat/home.rb', line 99

def export version
  v = version(version)
  return v if v.instance_of? Dflat::Version::Full
end

#infoObject



33
34
35
36
37
38
39
40
# File 'lib/dflat/home.rb', line 33

def info
  # xxx parse it with anvl
  return @info if @info
  return @info = {} unless File.exists? File.join(path, 'dflat-info.txt')

  anvl = open(File.join(path, 'dflat-info.txt')).read
  @info = ANVL.parse anvl
end

#info=(properties = @info) ⇒ Object



42
43
44
# File 'lib/dflat/home.rb', line 42

def info=(properties = @info)
  File.open(File.join(path, 'dflat-info.txt'), 'w') { |f| f.write(ANVL.to_anvl(properties)) }
end

#initObject



66
67
68
69
# File 'lib/dflat/home.rb', line 66

def init
  new_version('v001')
  self.current = 'v001'
end

#logObject



46
47
48
# File 'lib/dflat/home.rb', line 46

def log
  
end

#nextObject



56
57
58
59
# File 'lib/dflat/home.rb', line 56

def next
  v = next_version
  version(v) if File.exists? File.join(path, v)
end

#select(&block) ⇒ Object



120
121
122
123
# File 'lib/dflat/home.rb', line 120

def select &block
  d = Dflat::Version::Dir.new path
  d.select &block
end

#version(version) ⇒ Object



61
62
63
64
# File 'lib/dflat/home.rb', line 61

def version version
  # xxx use namaste 'type' to load the right dir..
  Dflat::Version::Dir.load File.join(path, version)
end

#versionsObject



116
117
118
# File 'lib/dflat/home.rb', line 116

def versions
  ::Dir.glob(File.join(path, 'v*')).map
end