Class: MetaCon::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/metacon/project.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(relative_to = './') ⇒ Project

Returns a new instance of Project.



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/metacon/project.rb', line 9

def initialize(relative_to='./')
  @rel_dir = File.expand_path(relative_to)
  @mc_dir = Project.find_mc_dir(@rel_dir)
  if @mc_dir.nil?
    @root_dir = nil
    @valid = false
    @state = nil
  else
    @root_dir = File.expand_path(File.join(@mc_dir, '..'))
    @valid = true
    @state = SavedState.new(@mc_dir)
  end
end

Instance Attribute Details

#mc_dirObject

Returns the value of attribute mc_dir.



4
5
6
# File 'lib/metacon/project.rb', line 4

def mc_dir
  @mc_dir
end

#rel_dirObject

Returns the value of attribute rel_dir.



4
5
6
# File 'lib/metacon/project.rb', line 4

def rel_dir
  @rel_dir
end

#root_dirObject

Returns the value of attribute root_dir.



4
5
6
# File 'lib/metacon/project.rb', line 4

def root_dir
  @root_dir
end

#validObject

Returns the value of attribute valid.



4
5
6
# File 'lib/metacon/project.rb', line 4

def valid
  @valid
end

Class Method Details

.initialized?(relative_to = './') ⇒ Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/metacon/project.rb', line 5

def self.initialized?(relative_to='./')
  ! find_mc_dir(relative_to).nil?
end

Instance Method Details

#atomic(&block) ⇒ Object



40
41
42
43
44
# File 'lib/metacon/project.rb', line 40

def atomic(&block)
  @state.atomic do |s|
    yield self, s
  end
end

#can_switch?Boolean

Returns:

  • (Boolean)


63
64
65
66
# File 'lib/metacon/project.rb', line 63

def can_switch?
  # TODO: make sure submodules don't have stuff to stash etc.
  return true
end

#confObject



28
29
30
31
# File 'lib/metacon/project.rb', line 28

def conf
  refresh_conf if @config.nil?
  @config[current_state]
end

#conf_objObject



23
24
25
26
# File 'lib/metacon/project.rb', line 23

def conf_obj
  refresh_conf if @config.nil?
  @config
end

#current_stateObject



68
69
70
71
72
73
# File 'lib/metacon/project.rb', line 68

def current_state
  st = @state.readonly
  st[:os] = this_os if (st[:os] == '(this)' || st[:os] == '.')
  st[:host] = this_host if (st[:host] == '(this)' || st[:host] == '.')
  return st
end

#different_os?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/metacon/project.rb', line 36

def different_os?

end

#list(to_list) ⇒ Object



75
76
77
78
79
80
# File 'lib/metacon/project.rb', line 75

def list(to_list)
  return nil unless @valid
  refresh_conf
  cs = current_state
  @config.declared[to_list].keys | [cs[to_list]]
end

#switch(changes = {}) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/metacon/project.rb', line 46

def switch(changes={})
  return :nochange if changes=={}
  return :impossible unless can_switch?
  changed = false
  @state.atomic do |s|
    changes.each do |key, val|
      s[key] = val unless s[key] == val
    end
    changed = s.dirty
  end
  if changed
    return setup_context
  else
    return :nochange
  end
end

#this_hostObject



34
# File 'lib/metacon/project.rb', line 34

def this_host; `uname -n`.strip end

#this_osObject



33
# File 'lib/metacon/project.rb', line 33

def this_os; `uname -s`.strip.downcase end