Class: MetaCon::Project
- Inherits:
-
Object
- Object
- MetaCon::Project
- Defined in:
- lib/metacon/project.rb
Instance Attribute Summary collapse
-
#mc_dir ⇒ Object
Returns the value of attribute mc_dir.
-
#rel_dir ⇒ Object
Returns the value of attribute rel_dir.
-
#root_dir ⇒ Object
Returns the value of attribute root_dir.
-
#valid ⇒ Object
Returns the value of attribute valid.
Class Method Summary collapse
Instance Method Summary collapse
- #atomic(&block) ⇒ Object
- #can_switch? ⇒ Boolean
- #conf ⇒ Object
- #conf_obj ⇒ Object
- #current_state ⇒ Object
- #different_os? ⇒ Boolean
-
#initialize(relative_to = './') ⇒ Project
constructor
A new instance of Project.
- #list(to_list) ⇒ Object
- #switch(changes = {}) ⇒ Object
- #this_host ⇒ Object
- #this_os ⇒ Object
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.(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.(File.join(@mc_dir, '..')) @valid = true @state = SavedState.new(@mc_dir) end end |
Instance Attribute Details
#mc_dir ⇒ Object
Returns the value of attribute mc_dir.
4 5 6 |
# File 'lib/metacon/project.rb', line 4 def mc_dir @mc_dir end |
#rel_dir ⇒ Object
Returns the value of attribute rel_dir.
4 5 6 |
# File 'lib/metacon/project.rb', line 4 def rel_dir @rel_dir end |
#root_dir ⇒ Object
Returns the value of attribute root_dir.
4 5 6 |
# File 'lib/metacon/project.rb', line 4 def root_dir @root_dir end |
#valid ⇒ Object
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
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
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 |
#conf ⇒ Object
28 29 30 31 |
# File 'lib/metacon/project.rb', line 28 def conf refresh_conf if @config.nil? @config[current_state] end |
#conf_obj ⇒ Object
23 24 25 26 |
# File 'lib/metacon/project.rb', line 23 def conf_obj refresh_conf if @config.nil? @config end |
#current_state ⇒ Object
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
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_host ⇒ Object
34 |
# File 'lib/metacon/project.rb', line 34 def this_host; `uname -n`.strip end |
#this_os ⇒ Object
33 |
# File 'lib/metacon/project.rb', line 33 def this_os; `uname -s`.strip.downcase end |