class Dflat::Home

Constants

DEFAULT_PROPERTIES

Attributes

path[R]

Public Class Methods

mkdir(path, integer=0777, args = {}) click to toggle source
# 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
new(path, args = {}) click to toggle source
# File lib/dflat/home.rb, line 28
def initialize path, args = {}
  @path = path
  @info = nil
end

Public Instance Methods

[](version) click to toggle source
# File lib/dflat/home.rb, line 104
def [] version
  export(version)
end
checkout() click to toggle source
# 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 = {}) click to toggle source
# File lib/dflat/home.rb, line 80
def commit args = {}
  lock
  v = self.current = version(next_version)
  unlock
  v
end
commit!() click to toggle source
# 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
current() click to toggle source
# File lib/dflat/home.rb, line 50
def current
  v = current_version
  return nil unless v
  version(v)
end
current=(version) click to toggle source
# 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) click to toggle source
# File lib/dflat/home.rb, line 99
def export version
  v = version(version)
  return v if v.instance_of? Dflat::Version::Full
end
info() click to toggle source
# 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) click to toggle source
# 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
init() click to toggle source
# File lib/dflat/home.rb, line 66
def init
  new_version('v001')
  self.current = 'v001'
end
log() click to toggle source
# File lib/dflat/home.rb, line 46
def log
  
end
next() click to toggle source
# File lib/dflat/home.rb, line 56
def next
  v = next_version
  version(v) if File.exists? File.join(path, v)
end
select(&block) click to toggle source
# File lib/dflat/home.rb, line 120
def select &block
  d = Dflat::Version::Dir.new path
  d.select &block
end
version(version) click to toggle source
# 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
versions() click to toggle source
# File lib/dflat/home.rb, line 116
def versions
  ::Dir.glob(File.join(path, 'v*')).map
end

Private Instance Methods

current_version() click to toggle source
# File lib/dflat/home.rb, line 130
def current_version
  @current ||= open(File.join(path, 'current.txt')).read.strip rescue nil
end
new_version(version) click to toggle source
# File lib/dflat/home.rb, line 126
def new_version version
  d = Dflat::Version::Full.mkdir File.join(path, version)
end
next_version() click to toggle source
# File lib/dflat/home.rb, line 134
def next_version
  "v%03d" % (current_version.sub(/^v/, '').to_i + 1)
end
update_directory_delta(from, to = current) click to toggle source
# File lib/dflat/home.rb, line 138
def update_directory_delta from, to = current
 
end