Class: RHC::Commands::Member

Inherits:
Base show all
Defined in:
lib/rhc/commands/member.rb

Constant Summary

Constants included from Helpers

Helpers::BOUND_WARNING, Helpers::PREFIX, Helpers::ROLES

Instance Method Summary collapse

Methods inherited from Base

#initialize

Methods included from RHC::ContextHelpers

#find_app, #find_domain, #find_membership_container, #find_team, #from_local_git, included, #namespace_context, #server_context

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?

Methods included from Helpers

#agree, #certificate_file, #client_from_options, #collect_env_vars, #color, #confirm_action, #date, #datetime_rfc3339, #debug, #debug?, #debug_error, #decode_json, #deprecated, #deprecated_command, #disable_deprecated?, #distance_of_time_in_words, #env_var_regex_pattern, #error, #exec, #host_exists?, #hosts_file_contains?, #human_size, #info, #interactive?, #jruby?, #mac?, #openshift_online_server?, #openshift_rest_endpoint, #openshift_server, #openshift_url, #pluralize, #results, #role_name, #run_with_tee, #ssh_string, #ssh_string_parts, #ssl_options, #success, #system_path, #table_heading, #to_host, #to_uri, #token_for_user, #unix?, #user_agent, #warn, #windows?, #with_tolerant_encoding

Methods included from OutputHelpers

#default_display_env_var, #display_app, #display_app_configurations, #display_authorization, #display_cart, #display_cart_storage_info, #display_cart_storage_list, #display_deployment, #display_deployment_list, #display_domain, #display_env_var_list, #display_key, #display_team, #format_cart_gears, #format_cart_header, #format_gear_info, #format_key_header, #format_scaling_info, #format_usage_message

Constructor Details

This class inherits a constructor from RHC::Commands::Base

Instance Method Details

#add(members) ⇒ Object

Raises:

  • (ArgumentError)


182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/rhc/commands/member.rb', line 182

def add(members)
  target = find_membership_container :writable => true

  role = get_role_option(options, target)
  type = get_type_option(options)
  global = !!options.global

  raise ArgumentError, 'You must pass at least one member to this command.' unless members.present?
  raise ArgumentError, "The --global option can only be used with '--type team'." if global && !team?(type)

  say "Adding #{pluralize(members.length, role_name(role))} to #{target.class.model_name.downcase} ... "

  members = search_teams(members, global).map{|member| member.id} if team?(type) && !options.ids
  target.update_members(changes_for(members, role, type))

  success "done"

  0
end

#list(_) ⇒ Object



79
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/rhc/commands/member.rb', line 79

def list(_)
  target = find_membership_container

  members = target.members
  if options.all
    show_members = members.sort
  else
    show_members = members.select do |m|
      if m.owner?
        true
      elsif m.explicit_role?
        true
      elsif m.from.any? {|f| f["type"] != "team" }
        true
      else
        false
      end
    end.sort
  end
  show_name = show_members.any?{ |m| m.name.presence && m.name != m. }
   = show_members.any?{ |m| m..presence }

  if show_members.present?
    say table(show_members.map do |member|
      [
        ((member.name || "") if show_name),
        ((member. || "") if ),
        role_description(member, member.teams(members)),
        (member.id if options.ids),
        member.type
      ].compact
    end, :header => [
      ('Name' if show_name),
      ('Login' if ),
      'Role',
      ("ID" if options.ids),
      "Type"
    ].compact)
  else
    info "The #{target.class.model_name.downcase} #{target.name} does not have any members."
  end

  if show_members.count < members.count
    paragraph do
      info "Pass --all to display all members, including members of teams."
    end
  end

  0
end

#remove(members) ⇒ Object



278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
# File 'lib/rhc/commands/member.rb', line 278

def remove(members)
  target = find_membership_container :writable => true
  type = get_type_option(options)

  if options.all
    say "Removing all members from #{target.class.model_name.downcase} ... "
    target.delete_members
    success "done"

  else
    raise ArgumentError, 'You must pass at least one member to this command.' unless members.present?

    say "Removing #{pluralize(members.length, 'member')} from #{target.class.model_name.downcase} ... "

    members = search_team_members(target.members, members).map{|member| member.id} if team?(type) && !options.ids
    target.update_members(changes_for(members, 'none', type))

    success "done"
  end

  0
end

#update(members) ⇒ Object

Raises:

  • (ArgumentError)


236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/rhc/commands/member.rb', line 236

def update(members)
  target = find_domain
  role = get_role_option(options, target)
  type = get_type_option(options)

  raise ArgumentError, 'You must pass at least one member to this command.' unless members.present?

  say "Updating #{pluralize(members.length, role_name(role))} to #{target.class.model_name.downcase} ... "

  members = search_team_members(target.members, members).map{|member| member.id} if team?(type) && !options.ids
  target.update_members(changes_for(members, role, type))

  success "done"

  0
end