Module: Imports::Processing
- Included in:
- Import
- Defined in:
- app/models/imports/processing.rb
Class Method Summary collapse
Instance Method Summary collapse
- #csv_data ⇒ Object
- #s3_service ⇒ Object
-
#time_zone_parser ⇒ Object
TODO: This should absolutely be moved into organization.rb.
Class Method Details
.included(base) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'app/models/imports/processing.rb', line 3 def self.included(base) base.class_eval do attr_accessible :s3_bucket, :s3_key, :s3_etag belongs_to :user belongs_to :organization validates_presence_of :user validates_associated :user validates_presence_of :s3_bucket validates_presence_of :s3_key validates_presence_of :s3_etag end end |
Instance Method Details
#csv_data ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/models/imports/processing.rb', line 25 def csv_data return @csv_data if @csv_data @csv_data = if File.file?(self.s3_key) File.read(self.s3_key) else s3_bucket = s3_service.buckets.find(self.s3_bucket) if self.s3_bucket.present? s3_object = s3_bucket.objects.find(self.s3_key) if s3_bucket s3_object.content(true) if s3_object end # Make sure the csv file is valid utf-8. if @csv_data @csv_data.encode! "UTF-8", :invalid => :replace, :undef => :replace, :replace => "" @csv_data = @csv_data.chars.map { |c| c if c.valid_encoding? }.compact.join end @csv_data end |
#s3_service ⇒ Object
46 47 48 49 50 51 |
# File 'app/models/imports/processing.rb', line 46 def s3_service access_key_id = Rails.application.config.s3.access_key_id secret_access_key = Rails.application.config.s3.secret_access_key S3::Service.new(:access_key_id => access_key_id, :secret_access_key => secret_access_key) end |
#time_zone_parser ⇒ Object
TODO: This should absolutely be moved into organization.rb
20 21 22 23 |
# File 'app/models/imports/processing.rb', line 20 def time_zone_parser @parser ||= ActiveSupport::TimeZone.create(self.organization.time_zone) @parser end |