Module: Capistrano::Configuration::Variables::SDB
- Defined in:
- lib/capistrano/sdb.rb
Overview
:nodoc:
Class Method Summary collapse
-
.included(base) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#initialize_with_sdb_variables(*args) ⇒ Object
self.included.
-
#method_missing_with_sdb_variables(sym, *args, &block) ⇒ Object
def respond_to_with_sdb_variables?.
-
#require_sdb(opts = nil) ⇒ Object
Boot the sdb system, including * creating a client * creating a domain for configuration.
-
#respond_to_with_sdb_variables?(sym) ⇒ Boolean
def initialize_with_sdb_variables.
-
#sdb_fetch(variable, reload = false) ⇒ Object
fetches a variable from sdb.
-
#sdb_has_key?(variable, reload = false) ⇒ Boolean
tests whether the sdb config defines a variable or not pass in :reload as the second param to force a re-download of config.
-
#sdb_set(variables) ⇒ Object
takes in a hash of variables to set.
Class Method Details
.included(base) ⇒ Object
:nodoc:
32 33 34 35 36 37 38 39 |
# File 'lib/capistrano/sdb.rb', line 32 def self.included( base ) #:nodoc: %w(initialize respond_to? method_missing).each do |m| base_name = m[/^\w+/] punct = m[/\W+$/] base.send :alias_method, "#{base_name}_without_sdb_variables#{punct}", m base.send :alias_method, m, "#{base_name}_with_sdb_variables#{punct}" end # each m end |
Instance Method Details
#initialize_with_sdb_variables(*args) ⇒ Object
self.included
41 42 43 |
# File 'lib/capistrano/sdb.rb', line 41 def initialize_with_sdb_variables(*args) #:nodoc: initialize_without_sdb_variables(*args) end |
#method_missing_with_sdb_variables(sym, *args, &block) ⇒ Object
def respond_to_with_sdb_variables?
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/capistrano/sdb.rb', line 57 def method_missing_with_sdb_variables( sym, *args, &block ) #:nodoc: return method_missing_without_sdb_variables( sym , *args, &block ) if( @_sdb_booting ) if( args.length == 0 && block.nil? ) if( sdb_local_override? ) if( respond_to_without_sdb_variables?( sym ) ) method_missing_without_sdb_variables( sym, *args, &block ) else sdb_download_config sdb_fetch( sym ) end else # if sdb_local_override? sdb_has_key?( sym ) ? sdb_fetch( sym ) : method_missing_without_sdb_variables( sym, *args, &block ) end # if sdb_local_override? else else # method_missing_without_sdb_variables( sym, *args, &block ) end # possible var end |
#require_sdb(opts = nil) ⇒ Object
Boot the sdb system, including
-
creating a client
-
creating a domain for configuration
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/capistrano/sdb.rb', line 80 def require_sdb( opts = nil ) opts ||= {} return if @booted @_sdb_booting = true raise "must specify aws_access_key_id and aws_secret_access_key" unless ( exists?( :aws_access_key_id ) && exists?( :aws_secret_access_key ) ) @stage = respond_to?( :stage ) ? stage : 'default' load_precedence_setting raise "no stage specified" if @stage.nil? logger.trace "booting sdb plugin with #{@precedence} precedence" default_client_params = { :protocol => 'http', :port => 80, :logger => ::SDB::Logger.new( logger ) } override_client_params = respond_to?( :sdb_client_params ) ? sdb_client_params : {} client_params = default_client_params.merge( override_client_params ) self._sdb_client = RightAws::SdbInterface.new( aws_access_key_id, aws_secret_access_key, client_params ) default_domain = ENV['SDBSELF._SDB_DOMAIN'] || "#{application}_cap_config" self._sdb_domain = default_domain self._sdb_domain = sdb_domain if( exists?(:sdb_domain) ) self._sdb_client.create_domain( self._sdb_domain ) @_sdb_booting = false @booted = true end |
#respond_to_with_sdb_variables?(sym) ⇒ Boolean
def initialize_with_sdb_variables
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/capistrano/sdb.rb', line 45 def respond_to_with_sdb_variables?( sym ) #:nodoc: return respond_to_without_sdb_variables?( sym ) if( @_sdb_booting ) if( sdb_local_override? ) return true if( respond_to_without_sdb_variables?( sym ) ) sdb_download_config return sdb_has_key?( sym ) else sdb_download_config return sdb_has_key?( sym ) || respond_to_without_sdb_variables?( sym ) end end |
#sdb_fetch(variable, reload = false) ⇒ Object
fetches a variable from sdb. pass in :reload as the second param to force a re-download of config.
117 118 119 120 121 122 123 124 125 126 |
# File 'lib/capistrano/sdb.rb', line 117 def sdb_fetch( variable, reload = false ) logger.trace( "fetching #{variable} for #{@stage} from remote location" ) sdb_download_config( reload ) if( variable ) raise IndexError, "`#{variable} not found" if( !sdb_has_key?( variable ) ) return @sdb_vars[variable.to_s] else return @sdb_vars end end |
#sdb_has_key?(variable, reload = false) ⇒ Boolean
tests whether the sdb config defines a variable or not pass in :reload as the second param to force a re-download of config.
110 111 112 113 |
# File 'lib/capistrano/sdb.rb', line 110 def sdb_has_key?( variable, reload = false ) sdb_download_config( reload ) return @sdb_vars.has_key?( variable.to_s ) end |
#sdb_set(variables) ⇒ Object
takes in a hash of variables to set.
129 130 131 132 |
# File 'lib/capistrano/sdb.rb', line 129 def sdb_set( variables ) require_sdb rval = self._sdb_client.put_attributes( self._sdb_domain, @stage, variables ) end |