class Treet::Farm
Attributes
repotype[R]
root[R]
xrefkey[R]
Public Class Methods
new(opts)
click to toggle source
# File lib/treet/farm.rb, line 8 def initialize(opts) raise Errno::ENOENT unless File.directory?(opts[:root]) @root = opts[:root] @xrefkey = opts[:xref] @repotype = opts[:repotype] || Treet::Repo end
plant(opts)
click to toggle source
“plant” a new farm: given an array of hashes (in JSON), create a directory of Treet
repositories, one per hash. Generate directory names for each repo.
# File lib/treet/farm.rb, line 38 def self.plant(opts) jsonfile = opts[:json] rootdir = opts[:root] array_of_hashes = JSON.load(File.open(jsonfile)) Dir.chdir(rootdir) do array_of_hashes.each do |h| uuid = SecureRandom.uuid thash = Treet::Hash.new(h) thash.to_repo(uuid, opts) end end self.new(opts) end
Public Instance Methods
add(hash, opts = {})
click to toggle source
add a new repo, with data from an input hash if an :id is provided, then the new repo will be stored under that directory name, otherwise a unique id will be generated
# File lib/treet/farm.rb, line 64 def add(hash, opts = {}) uuid = opts[:id] || SecureRandom.uuid thash = Treet::Hash.new(hash) repos[uuid] = thash.to_repo("#{root}/#{uuid}", opts.merge(:repotype => repotype)) end
count()
click to toggle source
# File lib/treet/farm.rb, line 76 def count xrefs.count end
export()
click to toggle source
export as an array, not as a hash the xref for each repo will be included under `xref.{xrefkey}`
# File lib/treet/farm.rb, line 32 def export repos.map {|xref,repo| repo.to_hash} end
patch(patches)
click to toggle source
apply patches to a farm of repos
# File lib/treet/farm.rb, line 55 def patch(patches) patches.map do |k,diffs| repos[k].patch(diffs) end end
repo(id, opts = {})
click to toggle source
# File lib/treet/farm.rb, line 23 def repo(id, opts = {}) repotype.new("#{root}/#{id}", opts) rescue Errno::ENOENT # no such repository exists nil end
repos(opts = {})
click to toggle source
# File lib/treet/farm.rb, line 16 def repos(opts = {}) xrefs.each_with_object({}) do |subdir,h| # in a Farm we are looking for repositories under the root h[subdir] = repo(subdir, opts) end end
xrefs()
click to toggle source
# File lib/treet/farm.rb, line 70 def xrefs Dir.chdir(root) do Dir.glob("*").select {|f| File.directory?(f)} end end