Class: UnderConstructionEmailStorage

Inherits:
Object
  • Object
show all
Extended by:
ActiveModel::Naming
Includes:
ActiveModel::Conversion, ActiveModel::Validations
Defined in:
app/models/under_construction_email_storage.rb

Defined Under Namespace

Classes: UniquenessValidator

Constant Summary collapse

FILE_PATH =
Rails.root + "db/under_construction_mails.txt"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ UnderConstructionEmailStorage

Returns a new instance of UnderConstructionEmailStorage.



26
27
28
29
30
# File 'app/models/under_construction_email_storage.rb', line 26

def initialize(attributes = {})
  attributes.each do |name, value|
    send("#{name}=", value)
  end
end

Instance Attribute Details

#emailObject

Returns the value of attribute email.



6
7
8
# File 'app/models/under_construction_email_storage.rb', line 6

def email
  @email
end

Class Method Details

.emailsObject

return emails in a array



44
45
46
47
48
49
50
# File 'app/models/under_construction_email_storage.rb', line 44

def self.emails
  File.open(FILE_PATH, "r") do |f|
    f.readlines
  end
rescue Errno::ENOENT
  []
end

.no_emails?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'app/models/under_construction_email_storage.rb', line 52

def self.no_emails?
  emails.empty?
end

.remove_fileObject



56
57
58
59
60
# File 'app/models/under_construction_email_storage.rb', line 56

def self.remove_file
  if File.exist? FILE_PATH
    FileUtils.rm FILE_PATH
  end
end

Instance Method Details

#persisted?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'app/models/under_construction_email_storage.rb', line 32

def persisted?
  false
end

#save_to_fileObject

save submitted mail to a text file



37
38
39
40
41
# File 'app/models/under_construction_email_storage.rb', line 37

def save_to_file
  File.open(FILE_PATH, "a") do |f|
    f.puts email
  end
end