csv_party 0.0.1.pre8 → 0.0.1.pre9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/csv_party.rb +32 -12
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: b70149f2976c65072cd5ba2e20b1187f250ed7cf
         | 
| 4 | 
            +
              data.tar.gz: 64c20377be56bc6b01249b092d01e41f8caf756e
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: fa5d31d3102e420b6f5f4d63bea3b13c8a9752a77047d28e32804abdc3ba07e2e21a68e9cf5ec909dd474537345bd4785750cdfaf0fb7112138fbae9d5082ec8
         | 
| 7 | 
            +
              data.tar.gz: fd46166bafee072f6308212cd5c3d028d560078e7800f61b003d7c0a050afc6919ce14cf680465e4beb70860baa3630c44377c283e723c5440033fc1e8e28f48
         | 
    
        data/lib/csv_party.rb
    CHANGED
    
    | @@ -3,7 +3,8 @@ require 'bigdecimal' | |
| 3 3 | 
             
            require 'ostruct'
         | 
| 4 4 |  | 
| 5 5 | 
             
            class CSVParty
         | 
| 6 | 
            -
              attr_accessor :columns, :row_importer, :importer, :error_processor
         | 
| 6 | 
            +
              attr_accessor :columns, :row_importer, :importer, :error_processor,
         | 
| 7 | 
            +
                            :dependencies
         | 
| 7 8 |  | 
| 8 9 | 
             
              attr_reader :imported_rows, :skipped_rows, :aborted_rows,
         | 
| 9 10 | 
             
                          :abort_message
         | 
| @@ -11,13 +12,12 @@ class CSVParty | |
| 11 12 | 
             
              def initialize(csv_path, options = {})
         | 
| 12 13 | 
             
                initialize_import_settings
         | 
| 13 14 | 
             
                initialize_counters_and_statuses
         | 
| 15 | 
            +
                initialize_dependencies(options)
         | 
| 14 16 |  | 
| 15 | 
            -
                dependencies = options.delete(:dependencies)
         | 
| 16 17 | 
             
                @headers = CSV.new(File.open(csv_path), options).shift
         | 
| 17 18 | 
             
                options[:headers] = true
         | 
| 18 19 | 
             
                @csv = CSV.new(File.open(csv_path), options)
         | 
| 19 20 |  | 
| 20 | 
            -
                setup_dependencies(dependencies)
         | 
| 21 21 | 
             
                raise_unless_named_parsers_are_valid
         | 
| 22 22 | 
             
                raise_unless_csv_has_all_headers
         | 
| 23 23 | 
             
              end
         | 
| @@ -87,6 +87,17 @@ class CSVParty | |
| 87 87 | 
             
                @error_processor = block
         | 
| 88 88 | 
             
              end
         | 
| 89 89 |  | 
| 90 | 
            +
              def self.depends_on(*args)
         | 
| 91 | 
            +
                args.each do |arg|
         | 
| 92 | 
            +
                  dependencies << arg
         | 
| 93 | 
            +
                  attr_accessor arg
         | 
| 94 | 
            +
                end
         | 
| 95 | 
            +
              end
         | 
| 96 | 
            +
             | 
| 97 | 
            +
              def self.dependencies
         | 
| 98 | 
            +
                @dependencies ||= []
         | 
| 99 | 
            +
              end
         | 
| 100 | 
            +
             | 
| 90 101 | 
             
              def self.columns
         | 
| 91 102 | 
             
                @columns ||= {}
         | 
| 92 103 | 
             
              end
         | 
| @@ -243,20 +254,12 @@ class CSVParty | |
| 243 254 | 
             
                          File has these headers: #{@headers.join(', ')}."
         | 
| 244 255 | 
             
              end
         | 
| 245 256 |  | 
| 246 | 
            -
              def setup_dependencies(dependencies)
         | 
| 247 | 
            -
                return unless dependencies
         | 
| 248 | 
            -
             | 
| 249 | 
            -
                dependencies.each do |dependency, value|
         | 
| 250 | 
            -
                  self.class.class_eval { attr_accessor dependency }
         | 
| 251 | 
            -
                  send("#{dependency}=", value)
         | 
| 252 | 
            -
                end
         | 
| 253 | 
            -
              end
         | 
| 254 | 
            -
             | 
| 255 257 | 
             
              def initialize_import_settings
         | 
| 256 258 | 
             
                @columns = self.class.columns
         | 
| 257 259 | 
             
                @row_importer = self.class.row_importer
         | 
| 258 260 | 
             
                @importer = self.class.importer
         | 
| 259 261 | 
             
                @error_processor = self.class.error_processor
         | 
| 262 | 
            +
                @dependencies = self.class.dependencies
         | 
| 260 263 | 
             
              end
         | 
| 261 264 |  | 
| 262 265 | 
             
              def initialize_counters_and_statuses
         | 
| @@ -265,6 +268,20 @@ class CSVParty | |
| 265 268 | 
             
                @aborted_rows = []
         | 
| 266 269 | 
             
                @aborted = false
         | 
| 267 270 | 
             
              end
         | 
| 271 | 
            +
             | 
| 272 | 
            +
              def initialize_dependencies(options)
         | 
| 273 | 
            +
                dependencies.each do |dependency|
         | 
| 274 | 
            +
                  if options.has_key? dependency
         | 
| 275 | 
            +
                    send("#{dependency}=", options.delete(dependency))
         | 
| 276 | 
            +
                  else
         | 
| 277 | 
            +
                    raise MissingDependencyError,
         | 
| 278 | 
            +
                          <<-MESSAGE
         | 
| 279 | 
            +
            This importer depends on #{dependency}, but you didn't include it.
         | 
| 280 | 
            +
            Here's how you do that: #{self.class.name}.new('path/to/csv', #{dependency}: #{dependency})
         | 
| 281 | 
            +
                          MESSAGE
         | 
| 282 | 
            +
                  end
         | 
| 283 | 
            +
                end
         | 
| 284 | 
            +
              end
         | 
| 268 285 | 
             
            end
         | 
| 269 286 |  | 
| 270 287 | 
             
            class UnknownParserError < ArgumentError
         | 
| @@ -279,6 +296,9 @@ end | |
| 279 296 | 
             
            class MissingColumnError < ArgumentError
         | 
| 280 297 | 
             
            end
         | 
| 281 298 |  | 
| 299 | 
            +
            class MissingDependencyError < ArgumentError
         | 
| 300 | 
            +
            end
         | 
| 301 | 
            +
             | 
| 282 302 | 
             
            class SkippedRowError < RuntimeError
         | 
| 283 303 | 
             
            end
         | 
| 284 304 |  | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: csv_party
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0.1. | 
| 4 | 
            +
              version: 0.0.1.pre9
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Rico Jones
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2017-05- | 
| 11 | 
            +
            date: 2017-05-03 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies: []
         | 
| 13 13 | 
             
            description: A gem for making CSV imports a little more fun.
         | 
| 14 14 | 
             
            email: rico@toasterlovin.com
         |