Class: Dandelion::Workspace

Inherits:
Object
  • Object
show all
Defined in:
lib/dandelion/workspace.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo, adapter, config = nil) ⇒ Workspace

Returns a new instance of Workspace.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/dandelion/workspace.rb', line 7

def initialize(repo, adapter, config = nil)
  @repo = repo
  @adapter = adapter

  if config.is_a?(Hash)
    @config = Config.new(data: config)
  else
    @config = config || Config.new
  end

  @config.defaults(revision_file: '.revision', local_path: '')
end

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



5
6
7
# File 'lib/dandelion/workspace.rb', line 5

def adapter
  @adapter
end

#configObject (readonly)

Returns the value of attribute config.



5
6
7
# File 'lib/dandelion/workspace.rb', line 5

def config
  @config
end

Instance Method Details

#changesetObject



24
25
26
# File 'lib/dandelion/workspace.rb', line 24

def changeset
  Changeset.new(tree, remote_commit, @config)
end

#local_commitObject



28
29
30
# File 'lib/dandelion/workspace.rb', line 28

def local_commit
  lookup(local_sha)
end

#lookup(val) ⇒ Object

Raises:



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/dandelion/workspace.rb', line 41

def lookup(val)
  result = lookup_sha(val) ||
    lookup_ref(val) ||
    lookup_ref("refs/tags/#{val}") ||
    lookup_ref("refs/branches/#{val}") ||
    lookup_ref("refs/heads/#{val}")

  raise RevisionError.new(val) unless result

  result
end

#remote_commitObject



32
33
34
35
# File 'lib/dandelion/workspace.rb', line 32

def remote_commit
  sha = remote_sha
  sha ? lookup(remote_sha) : nil
end

#remote_commit=(commit) ⇒ Object



37
38
39
# File 'lib/dandelion/workspace.rb', line 37

def remote_commit=(commit)
  self.remote_sha = commit.oid
end

#treeObject



20
21
22
# File 'lib/dandelion/workspace.rb', line 20

def tree
  Tree.new(@repo, local_commit)
end