Module: PostyClient::Command::FinderConcerns

Includes:
Resources
Included in:
DomainAliasCommand, UserAliasCommand, UserCommand
Defined in:
lib/posty_client/command/finder_concerns.rb

Instance Method Summary collapse

Instance Method Details

#find_domain_alias_by_domain_and_name(domain_name, name) ⇒ Object



40
41
42
43
44
# File 'lib/posty_client/command/finder_concerns.rb', line 40

def find_domain_alias_by_domain_and_name(domain_name, name)
  domain = find_domain_by_name(domain_name)
  
  DomainAlias.new(domain, name)
end

#find_domain_by_name(name) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/posty_client/command/finder_concerns.rb', line 17

def find_domain_by_name(name)
  domain = Domain.new(name)
  if domain.new_resource?
    say("Unknown domain #{name}", :red)
    exit 1
  end

  domain        
end

#find_user_alias_by_email_and_name(email, name) ⇒ Object



34
35
36
37
38
# File 'lib/posty_client/command/finder_concerns.rb', line 34

def find_user_alias_by_email_and_name(email, name)
  user = find_user_by_email(email)
  
  UserAlias.new(user, name)
end

#find_user_by_email(name) ⇒ Object



27
28
29
30
31
32
# File 'lib/posty_client/command/finder_concerns.rb', line 27

def find_user_by_email(name)
  user_name, domain_name = user_and_domain_from_email(name)
  domain = find_domain_by_name(domain_name)

  User.new(domain, user_name)
end

#user_and_domain_from_email(email) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/posty_client/command/finder_concerns.rb', line 6

def user_and_domain_from_email(email)
  parts = email.split("\@")

  unless parts.size == 2
    say("#{email} not an email address", :red)
    exit 1
  end

  return *parts
end