Class: Pushapp::Config
- Inherits:
-
Object
- Object
- Pushapp::Config
- Defined in:
- lib/pushapp/config.rb
Constant Summary collapse
- @@known_tasks =
{}
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#remotes ⇒ Object
readonly
Returns the value of attribute remotes.
Class Method Summary collapse
Instance Method Summary collapse
- #group(group_name, options = {}, &block) ⇒ Object
-
#initialize(configuration_file = nil) ⇒ Config
constructor
A new instance of Config.
- #known_task(name) ⇒ Object
- #on(event, &block) ⇒ Object
- #remote(name, location, options = {}) ⇒ Object
- #remotes_grouped_by(group) ⇒ Object
- #remotes_matched(group_or_name) ⇒ Object
- #remotes_named_by(name) ⇒ Object
Constructor Details
#initialize(configuration_file = nil) ⇒ Config
Returns a new instance of Config.
25 26 27 28 29 30 |
# File 'lib/pushapp/config.rb', line 25 def initialize(configuration_file = nil) @file = configuration_file || Pushapp::DEFAULT_CONFIG_LOCATION @remotes = [] = {} @group_name = nil end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
5 6 7 |
# File 'lib/pushapp/config.rb', line 5 def file @file end |
#remotes ⇒ Object (readonly)
Returns the value of attribute remotes.
6 7 8 |
# File 'lib/pushapp/config.rb', line 6 def remotes @remotes end |
Class Method Details
.parse(configuration_file = nil) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/pushapp/config.rb', line 10 def self.parse(configuration_file = nil) require 'pushapp/tasks/base' require 'pushapp/tasks/script' require 'pushapp/tasks/rake' require 'pushapp/tasks/upstart' require 'pushapp/tasks/nginx_export' require 'pushapp/tasks/foreman_export' require 'pushapp/tasks/unicorn_signal' config = self.new(configuration_file) config.instance_eval(File.read(config.file)) config end |
.register_task(name, klass) ⇒ Object
89 90 91 |
# File 'lib/pushapp/config.rb', line 89 def self.register_task name, klass @@known_tasks[name.to_s] = klass end |
Instance Method Details
#group(group_name, options = {}, &block) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/pushapp/config.rb', line 48 def group(group_name, = {}, &block) @group_name = group_name.to_s = instance_eval &block if block_given? @group_name = nil = {} end |
#known_task(name) ⇒ Object
60 61 62 63 64 |
# File 'lib/pushapp/config.rb', line 60 def known_task name task = @@known_tasks[name.to_s] raise "Unkown task with name '#{name}'. Forget to register task?" unless task task end |
#on(event, &block) ⇒ Object
56 57 58 |
# File 'lib/pushapp/config.rb', line 56 def on event, &block remotes.each {|r| r.on(event, &block) if block_given? } end |
#remote(name, location, options = {}) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/pushapp/config.rb', line 32 def remote(name, location, = {}) name = name.to_s if remotes.any? {|r| r.location == location} raise "Can't have multiple remotes with same location" end full_name = [name, @group_name].compact.join('-') if remotes.any? {|r| r.full_name == full_name} raise "Can't have multiple remotes with same full_name. Remote '#{full_name}' already exists" end = Pushapp.rmerge(, ) remotes << Pushapp::Remote.new(name, @group_name, location, self, ) end |
#remotes_grouped_by(group) ⇒ Object
71 72 73 74 |
# File 'lib/pushapp/config.rb', line 71 def remotes_grouped_by(group) group = group.to_s remotes.select {|r| r.group == group } end |
#remotes_matched(group_or_name) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/pushapp/config.rb', line 76 def remotes_matched(group_or_name) case group_or_name when 'all' remotes when String remotes.select {|r| r.full_name == group_or_name || r.group == group_or_name} when Array group_or_name.map {|n| remotes_matched(n)}.flatten.compact.uniq else [] end end |
#remotes_named_by(name) ⇒ Object
66 67 68 69 |
# File 'lib/pushapp/config.rb', line 66 def remotes_named_by(name) name = name.to_s remotes.select {|r| r.full_name == name } end |