Class: Rumination::DevUser

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
lib/rumination/dev_user.rb

Constant Summary collapse

CannotBeInitialized =
Class.new(RuntimeError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ DevUser

Returns a new instance of DevUser.



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rumination/dev_user.rb', line 10

def initialize args={}
  super
  self.name ||= ENV["USER"]
  self.name ||= self.email[/^.*(?=@)/] if self.email.present?
  raise CannotBeInitialized, "Can't guess dev user name" unless self.name.present?
  self.password ||= ENV["DEV_PASSWORD"]
  raise CannotBeInitialized, "Can't guess dev user password" unless self.password.present?
  self.host ||= ENV["DEV_HOST"]
  raise CannotBeInitialized, "Can't guess dev user email" unless self.email.present? || self.host.present?
  self.email ||= [name, host].join("@")
end

Instance Attribute Details

#emailObject

Returns the value of attribute email.



8
9
10
# File 'lib/rumination/dev_user.rb', line 8

def email
  @email
end

#hostObject

Returns the value of attribute host.



8
9
10
# File 'lib/rumination/dev_user.rb', line 8

def host
  @host
end

#nameObject

Returns the value of attribute name.



8
9
10
# File 'lib/rumination/dev_user.rb', line 8

def name
  @name
end

#passwordObject

Returns the value of attribute password.



8
9
10
# File 'lib/rumination/dev_user.rb', line 8

def password
  @password
end

Instance Method Details

#attribute_namesObject



26
27
28
# File 'lib/rumination/dev_user.rb', line 26

def attribute_names
  %w[name password host email]
end

#attributesObject



22
23
24
# File 'lib/rumination/dev_user.rb', line 22

def attributes
  attribute_names.map{|attribute| [attribute, send(attribute)]}.to_h
end