Module: BuildCloud::Component::InstanceMethods
- Defined in:
- lib/build-cloud/component.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #exists? ⇒ Boolean
- #has_key?(key) ⇒ Boolean
- #ready_timeout ⇒ Object
- #require_one_of(*required) ⇒ Object
- #required_options(*required) ⇒ Object
- #to_s ⇒ Object
- #wait_until_ready ⇒ Object
Instance Method Details
#[](key) ⇒ Object
13 14 15 |
# File 'lib/build-cloud/component.rb', line 13 def [](key) @options[key] end |
#exists? ⇒ Boolean
21 22 23 |
# File 'lib/build-cloud/component.rb', line 21 def exists? !read.nil? end |
#has_key?(key) ⇒ Boolean
17 18 19 |
# File 'lib/build-cloud/component.rb', line 17 def has_key?(key) @options.has_key?(key) end |
#ready_timeout ⇒ Object
25 26 27 |
# File 'lib/build-cloud/component.rb', line 25 def ready_timeout 30 end |
#require_one_of(*required) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/build-cloud/component.rb', line 79 def require_one_of( *required ) cn = self.class.name.split('::').last intersection = @options.keys & required if intersection.length != 1 raise "#{cn} requires only one of #{required.join(', ')}" end end |
#required_options(*required) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/build-cloud/component.rb', line 64 def ( *required ) cn = self.class.name.split('::').last missing = [] required.each do |o| missing << o unless @options.has_key?(o) end if missing.length > 0 raise "#{cn} requires missing #{missing.join(', ')} option#{missing.length > 1 ? 's' : ''}" end end |
#to_s ⇒ Object
92 93 94 |
# File 'lib/build-cloud/component.rb', line 92 def to_s return @options.to_yaml end |
#wait_until_ready ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/build-cloud/component.rb', line 29 def wait_until_ready unless read.class.method_defined?(:ready?) @log.debug("Can't wait for readiness on #{read.class.to_s}") return end timeout = ready_timeout # default from this superclass wait_timer = 1 start_time = Time.now.to_i begin if fog_object.ready? @log.info("Object ready") return true end @log.debug("Object not yet ready. Sleeping #{wait_timer}s") sleep( wait_timer ) if wait_timer < 60 wait_timer *= 2 end time_diff = Time.now.to_i - start_time end while time_diff < timeout @log.error("Timed out after #{timeout} waiting for #{read.class}") end |