Class: V::Adapters::Git::Environment

Inherits:
Object
  • Object
show all
Defined in:
lib/v/adapters/git/environment.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Environment

Returns a new instance of Environment.



12
13
14
15
16
17
18
19
# File 'lib/v/adapters/git/environment.rb', line 12

def initialize(attrs = {})
  assign attrs

  assign_directories
  assign_git
  assign_string
  assign_worker
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(op_sym, *args, &callback) ⇒ Object

Tries to schedule an operation.



31
32
33
# File 'lib/v/adapters/git/environment.rb', line 31

def method_missing(op_sym, *args, &callback)
  schedule Operations.new(op_sym, *args, &callback)
end

Instance Attribute Details

#bareObject (readonly)

Returns the value of attribute bare.



7
8
9
# File 'lib/v/adapters/git/environment.rb', line 7

def bare
  @bare
end

#branchesObject (readonly)

Returns the value of attribute branches.



7
8
9
# File 'lib/v/adapters/git/environment.rb', line 7

def branches
  @branches
end

#git_dirObject (readonly)

Returns the value of attribute git_dir.



7
8
9
# File 'lib/v/adapters/git/environment.rb', line 7

def git_dir
  @git_dir
end

#indexObject (readonly)

Returns the value of attribute index.



7
8
9
# File 'lib/v/adapters/git/environment.rb', line 7

def index
  @index
end

#to_sObject (readonly)

Returns the value of attribute to_s.



7
8
9
# File 'lib/v/adapters/git/environment.rb', line 7

def to_s
  @to_s
end

#work_treeObject (readonly)

Returns the value of attribute work_tree.



7
8
9
# File 'lib/v/adapters/git/environment.rb', line 7

def work_tree
  @work_tree
end

Class Method Details

.which_git=(path) ⇒ Object



9
# File 'lib/v/adapters/git/environment.rb', line 9

def self.which_git=(path) @@which_git = path end

Instance Method Details

#commits(path = '.') ⇒ Object

Returns collection of commits for current branch.



53
54
55
# File 'lib/v/adapters/git/environment.rb', line 53

def commits(path = '.')
  @branches.current.commits path
end

#headObject

Returns head for current branch. This is a moving target.



57
58
59
# File 'lib/v/adapters/git/environment.rb', line 57

def head
  @branches.current.head
end

#inspectObject



40
41
42
# File 'lib/v/adapters/git/environment.rb', line 40

def inspect
  @git_dir
end

#new?Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
27
28
# File 'lib/v/adapters/git/environment.rb', line 21

def new?
  schedule {
    path = File.join @git_dir, 'refs', 'heads'
    entries = Dir.entries(path) - %w[ . .. ]

    entries.size == 0
  }
end

#originObject



49
50
51
# File 'lib/v/adapters/git/environment.rb', line 49

def origin
  @remotes['origin']
end

#remotesObject

Convenience



46
47
48
# File 'lib/v/adapters/git/environment.rb', line 46

def remotes
  @remotes
end

#schedule(op = nil, &block) ⇒ Object

Schedules operation or proc for execution.



36
37
38
# File 'lib/v/adapters/git/environment.rb', line 36

def schedule(op = nil, &block)
  @worker.enq block || op, self
end