Class: Readme

Inherits:
Object
  • Object
show all
Defined in:
app/models/readme.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(work, current_user) ⇒ Readme

Returns a new instance of Readme.



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

def initialize(work, current_user)
  @work = work
  @current_user = current_user
end

Instance Attribute Details

#current_userObject (readonly)

Returns the value of attribute current_user.



3
4
5
# File 'app/models/readme.rb', line 3

def current_user
  @current_user
end

#workObject (readonly)

Returns the value of attribute work.



3
4
5
# File 'app/models/readme.rb', line 3

def work
  @work
end

Instance Method Details

#attach(readme_file_param) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/models/readme.rb', line 10

def attach(readme_file_param)
  return "A README file is required!" if readme_file_param.blank? && blank?
  return nil if readme_file_param.blank?
  remove_old_readme

  key = upload_readme(readme_file_param)
  if key
    @file_names = [readme_file_param.original_filename]
    @s3_readme_idx = 0
    log_changes
    nil
  else
    "An error uploading your README was encountered.  Please try again."
  end
end

#blank?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'app/models/readme.rb', line 26

def blank?
  s3_readme_idx.nil?
end

#file_nameObject



30
31
32
33
# File 'app/models/readme.rb', line 30

def file_name
  return nil if blank?
  file_names[s3_readme_idx]
end