Module: RHC::ContextHelpers
Overview
Methods in this module should not attempt to read from the options hash in a recursive manner (server_context can’t read options.server).
Class Method Summary collapse
Instance Method Summary collapse
- #find_app(opts = {}) ⇒ Object
- #find_domain(opts = {}) ⇒ Object
- #find_membership_container(opts = {}) ⇒ Object
- #find_team(opts = {}) ⇒ Object
- #from_local_git(defaults, arg) ⇒ Object
- #namespace_context ⇒ Object
- #server_context(defaults = nil, arg = nil) ⇒ Object
Methods included from GitHelpers
#git_clone_application, #git_clone_deploy_hooks, #git_clone_repo, #git_cmd, #git_config_get, #git_config_set, #git_remote_add, #git_version, #has_git?
Class Method Details
.included(other) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 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 |
# File 'lib/rhc/context_helper.rb', line 11 def self.included(other) other.module_eval do def self.takes_team(opts={}) if opts[:argument] argument :team_name, "Name of a team", ["-t", "--team-name NAME"], :allow_nil => true, :covered_by => :team_id else #:nocov: option ["-t", "--team-name NAME"], "Name of a team", :covered_by => :team_id #:nocov: end option ["--team-id ID"], "ID of a team", :covered_by => :team_name end def self.takes_domain(opts={}) if opts[:argument] argument :namespace, "Name of a domain", ["-n", "--namespace NAME"], :allow_nil => true, :default => :from_local_git else #:nocov: option ["-n", "--namespace NAME"], "Name of a domain", :default => :from_local_git #:nocov: end end def self.takes_membership_container(opts={}) if opts && opts[:argument] if opts && opts[:writable] #:nocov: argument :namespace, "Name of a domain", ["-n", "--namespace NAME"], :allow_nil => true, :default => :from_local_git #:nocov: else argument :target, "The name of a domain, or an application name with domain (domain or domain/application)", ["--target NAME_OR_PATH"], :allow_nil => true, :covered_by => [:application_id, :namespace, :app] end end option ["-n", "--namespace NAME"], "Name of a domain" option ["-a", "--app NAME"], "Name of an application" unless opts && opts[:writable] option ["-t", "--team-name NAME"], "Name of a team" option ["--team-id ID"], "ID of a team" end def self.takes_application(opts={}) if opts[:argument] argument :app, "Name of an application", ["-a", "--app NAME"], :allow_nil => true, :default => :from_local_git, :covered_by => :application_id else option ["-a", "--app NAME"], "Name of an application", :default => :from_local_git, :covered_by => :application_id end option ["-n", "--namespace NAME"], "Name of a domain", :default => :from_local_git option ["--application-id ID"], "ID of an application", :hide => true, :default => :from_local_git, :covered_by => :app end end end |
Instance Method Details
#find_app(opts = {}) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/rhc/context_helper.rb', line 110 def find_app(opts={}) if id = .application_id.presence if opts.delete(:with_gear_groups) return rest_client.find_application_by_id_gear_groups(id, opts) else return rest_client.find_application_by_id(id, opts) end end option = (opts && opts[:app]) || .app domain, app = if option if option =~ /\// option.split(/\//) else [.namespace || namespace_context, option] end end if app.present? && domain.present? if opts.delete(:with_gear_groups) rest_client.find_application_gear_groups(domain, app, opts) else rest_client.find_application(domain, app, opts) end else raise ArgumentError, "You must specify an application with -a, or run this command from within Git directory cloned from CloudStrap." end end |
#find_domain(opts = {}) ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/rhc/context_helper.rb', line 74 def find_domain(opts={}) domain = .namespace || .target || namespace_context if domain rest_client.find_domain(domain) else raise ArgumentError, "You must specify a domain with -n." end end |
#find_membership_container(opts = {}) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/rhc/context_helper.rb', line 83 def find_membership_container(opts={}) domain, app = if .target.present? .target.split(/\//) elsif .namespace || .app if .app =~ /\// .app.split(/\//) else [.namespace || namespace_context, .app] end end if .team_id.present? rest_client.find_team_by_id(.team_id) elsif .team_name.present? rest_client.find_team(.team_name) elsif app && domain rest_client.find_application(domain, app) elsif domain rest_client.find_domain(domain) elsif opts && opts[:writable] raise ArgumentError, "You must specify a domain with -n, or a team with -t." else raise ArgumentError, "You must specify a domain with -n, an application with -a, or a team with -t." end end |
#find_team(opts = {}) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/rhc/context_helper.rb', line 62 def find_team(opts={}) if id = .team_id.presence return rest_client.find_team_by_id(id, opts) end team_name = (opts && opts[:team_name]) || .team_name if team_name.present? rest_client.find_team(team_name, opts) else raise ArgumentError, "You must specify a team name with -t, or a team id with --team-id." end end |
#from_local_git(defaults, arg) ⇒ Object
144 145 146 147 148 149 150 151 152 |
# File 'lib/rhc/context_helper.rb', line 144 def from_local_git(defaults, arg) @local_git_config ||= { :application_id => git_config_get('rhc.app-id').presence, :app => git_config_get('rhc.app-name').presence, :namespace => git_config_get('rhc.domain-name').presence, } defaults[arg] ||= @local_git_config[arg] unless @local_git_config[arg].nil? @local_git_config end |
#namespace_context ⇒ Object
154 155 156 157 158 159 160 161 |
# File 'lib/rhc/context_helper.rb', line 154 def namespace_context # right now we don't have any logic since we only support one domain # TODO: add domain lookup based on uuid domain = rest_client.domains.first raise RHC::NoDomainsForUser if domain.nil? domain.name end |
#server_context(defaults = nil, arg = nil) ⇒ Object
138 139 140 141 142 |
# File 'lib/rhc/context_helper.rb', line 138 def server_context(defaults=nil, arg=nil) value = ENV['LIBRA_SERVER'] || (!.clean && config['libra_server']) || "api.startappcloud.com" defaults[arg] = value if defaults && arg value end |