Class: Nsync::Config

Inherits:
Object
  • Object
show all
Includes:
Lockfile
Defined in:
lib/nsync/config.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



20
21
22
23
24
# File 'lib/nsync/config.rb', line 20

def initialize
  clear_class_mappings
  self.log = ::Logger.new(STDERR)
  self.lock_file = "/tmp/nsync.lock"
end

Instance Attribute Details

#lock_fileObject

optional



15
16
17
# File 'lib/nsync/config.rb', line 15

def lock_file
  @lock_file
end

#logObject

optional



15
16
17
# File 'lib/nsync/config.rb', line 15

def log
  @log
end

#orderingObject

optional



15
16
17
# File 'lib/nsync/config.rb', line 15

def ordering
  @ordering
end

#producer_instanceObject

optional



15
16
17
# File 'lib/nsync/config.rb', line 15

def producer_instance
  @producer_instance
end

#repo_pathObject

required to be user specified



12
13
14
# File 'lib/nsync/config.rb', line 12

def repo_path
  @repo_path
end

#repo_push_urlObject

optional



15
16
17
# File 'lib/nsync/config.rb', line 15

def repo_push_url
  @repo_push_url
end

#repo_urlObject

optional



15
16
17
# File 'lib/nsync/config.rb', line 15

def repo_url
  @repo_url
end

#version_managerObject

required to be user specified



12
13
14
# File 'lib/nsync/config.rb', line 12

def version_manager
  @version_manager
end

Class Method Details

.run {|Nsync.config| ... } ⇒ Object

Yields:



80
81
82
# File 'lib/nsync/config.rb', line 80

def self.run
  yield Nsync.config
end

Instance Method Details

#cdObject



39
40
41
42
43
44
45
46
47
# File 'lib/nsync/config.rb', line 39

def cd
  old_pwd = FileUtils.pwd
  begin
    FileUtils.cd repo_path
    yield
  ensure
    FileUtils.cd old_pwd
  end
end

#clear_class_mappingsObject



55
56
57
# File 'lib/nsync/config.rb', line 55

def clear_class_mappings
  @class_mappings = {}
end

#consumer_classes_for(producer_class) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/nsync/config.rb', line 59

def consumer_classes_for(producer_class)
  Array(@class_mappings[producer_class]).map do |klass|
    begin
      CoreExtensions.constantize(klass)
    rescue NameError => e
      log.error(e.inspect)
      log.warn("[NSYNC] Could not find class '#{klass}'; skipping")
      nil
    end
  end.compact
end

#local?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/nsync/config.rb', line 84

def local?
  !repo_url
end

#lockObject



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/nsync/config.rb', line 26

def lock
  ret = nil
  success = with_lock_file(lock_file) do
    ret = yield
  end
  if success != false
    return ret
  else
    log.error("[NSYNC] Could not obtain lock!; exiting")
    return false
  end
end

#map_class(producer_class, *consumer_classes) ⇒ Object



50
51
52
53
# File 'lib/nsync/config.rb', line 50

def map_class(producer_class, *consumer_classes)
  @class_mappings[producer_class] ||= []
  @class_mappings[producer_class] += consumer_classes
end

#remote?Boolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/nsync/config.rb', line 88

def remote?
  !!repo_url
end

#remote_push?Boolean

Returns:

  • (Boolean)


92
93
94
# File 'lib/nsync/config.rb', line 92

def remote_push?
  !!repo_push_url
end