Class: Decidim::DataPortabilityFileReader
- Inherits:
-
Object
- Object
- Decidim::DataPortabilityFileReader
- Defined in:
- lib/decidim/data_portability_file_reader.rb
Overview
This class generates the information needed to be read by DataPortability. It creates the file_name, file_path, check that the token is valid and generates the token if no exists. Originally meant for DataPortability functionality and adding user images to this file, but other usage can be found.
Direct Known Subclasses
Instance Method Summary collapse
-
#file_name ⇒ Object
Returns a String with the filename of the file to be read or generate.
-
#file_path ⇒ Object
Returns a String with the absolute file_path to be read or generate.
- #file_path_reader ⇒ Object
-
#initialize(user, token = nil) ⇒ DataPortabilityFileReader
constructor
Public: Initialize the reader with a user, and token.
-
#token ⇒ Object
Returns a the token or generate a new one.
-
#valid_token? ⇒ Boolean
Check if token is present and length equal 10.
Constructor Details
#initialize(user, token = nil) ⇒ DataPortabilityFileReader
Public: Initialize the reader with a user, and token
user - The user of data portability to be zipped. token - The token to be send by email, and return to controller.
12 13 14 15 16 |
# File 'lib/decidim/data_portability_file_reader.rb', line 12 def initialize(user, token = nil) @user = user @organization = user.organization @token = token end |
Instance Method Details
#file_name ⇒ Object
Returns a String with the filename of the file to be read or generate.
19 20 21 22 23 24 25 26 27 |
# File 'lib/decidim/data_portability_file_reader.rb', line 19 def file_name name = "" name += @user.nickname name += "-" name += @organization.name.parameterize name += "-" name += token name + ".zip" end |
#file_path ⇒ Object
Returns a String with the absolute file_path to be read or generate.
30 31 32 33 34 |
# File 'lib/decidim/data_portability_file_reader.rb', line 30 def file_path directory_name = Rails.root.join(Decidim::DataPortabilityUploader.new.store_dir) FileUtils.mkdir_p(directory_name) unless File.exist?(directory_name) directory_name + file_name end |
#file_path_reader ⇒ Object
36 37 38 |
# File 'lib/decidim/data_portability_file_reader.rb', line 36 def file_path_reader Decidim::DataPortabilityUploader.new.retrieve_from_store!(file_name) end |
#token ⇒ Object
Returns a the token or generate a new one
46 47 48 |
# File 'lib/decidim/data_portability_file_reader.rb', line 46 def token @token ||= generate_new_token end |
#valid_token? ⇒ Boolean
Check if token is present and length equal 10
41 42 43 |
# File 'lib/decidim/data_portability_file_reader.rb', line 41 def valid_token? token.present? && token.length == 10 end |