Class: Nsync::Config
Instance Attribute Summary collapse
-
#lock_file ⇒ Object
optional.
-
#log ⇒ Object
optional.
-
#ordering ⇒ Object
optional.
-
#producer_instance ⇒ Object
optional.
-
#repo_path ⇒ Object
required to be user specified.
-
#repo_push_url ⇒ Object
optional.
-
#repo_url ⇒ Object
optional.
-
#version_manager ⇒ Object
required to be user specified.
Class Method Summary collapse
Instance Method Summary collapse
- #cd ⇒ Object
- #clear_class_mappings ⇒ Object
- #consumer_classes_for(producer_class) ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #local? ⇒ Boolean
- #lock ⇒ Object
- #map_class(producer_class, *consumer_classes) ⇒ Object
- #remote? ⇒ Boolean
- #remote_push? ⇒ Boolean
Constructor Details
#initialize ⇒ Config
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_file ⇒ Object
optional
15 16 17 |
# File 'lib/nsync/config.rb', line 15 def lock_file @lock_file end |
#log ⇒ Object
optional
15 16 17 |
# File 'lib/nsync/config.rb', line 15 def log @log end |
#ordering ⇒ Object
optional
15 16 17 |
# File 'lib/nsync/config.rb', line 15 def ordering @ordering end |
#producer_instance ⇒ Object
optional
15 16 17 |
# File 'lib/nsync/config.rb', line 15 def producer_instance @producer_instance end |
#repo_path ⇒ Object
required to be user specified
12 13 14 |
# File 'lib/nsync/config.rb', line 12 def repo_path @repo_path end |
#repo_push_url ⇒ Object
optional
15 16 17 |
# File 'lib/nsync/config.rb', line 15 def repo_push_url @repo_push_url end |
#repo_url ⇒ Object
optional
15 16 17 |
# File 'lib/nsync/config.rb', line 15 def repo_url @repo_url end |
#version_manager ⇒ Object
required to be user specified
12 13 14 |
# File 'lib/nsync/config.rb', line 12 def version_manager @version_manager end |
Class Method Details
Instance Method Details
#cd ⇒ Object
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_mappings ⇒ Object
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
84 85 86 |
# File 'lib/nsync/config.rb', line 84 def local? !repo_url end |
#lock ⇒ Object
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
88 89 90 |
# File 'lib/nsync/config.rb', line 88 def remote? !!repo_url end |
#remote_push? ⇒ Boolean
92 93 94 |
# File 'lib/nsync/config.rb', line 92 def remote_push? !!repo_push_url end |