Skip to content

Instantly share code, notes, and snippets.

@hemju
Last active August 29, 2015 14:03
Show Gist options
  • Select an option

  • Save hemju/94713cacdbac9d08071d to your computer and use it in GitHub Desktop.

Select an option

Save hemju/94713cacdbac9d08071d to your computer and use it in GitHub Desktop.

Revisions

  1. Helmut Michael Juskewycz revised this gist Jun 27, 2014. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -22,5 +22,6 @@ def import_file_data(file_path, content, import_type, strategy_name, additional_
    # maybe reload already returns the resource_import new and we don't need the last line at all? resource_import.reload
    # implicit returns always felt 'dirty' to me. For example ActiveRecord callbacks which return false
    # break the chain, so you have to know that to not break it unintentionally
    resource_import.reload
    resource_import
    end
  2. Helmut Michael Juskewycz revised this gist Jun 26, 2014. 1 changed file with 7 additions and 7 deletions.
    14 changes: 7 additions & 7 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -1,15 +1,15 @@
    def import_file_data(file_path, content, import_type, strategy_name, additional_attributes = {}, options = {})
    // probably file_path is a String and the result file_name as well
    # probably file_path is a String and the result file_name as well
    file_name = File.basename(file_path)

    // no idea what tempfile is, a string?
    # no idea what tempfile is, a string?
    tempfile = write_to_temp_file(content, file_name)
    uploaded_file = OpenStruct.new(:original_filename => file_name, :tempfile => tempfile)

    // Is this now an instance of ResourceImport or a result of a resource import?
    # Is this now an instance of ResourceImport or a result of a resource import?
    resource_import = ResourceImport.import!(user, project, uploaded_file, file_path, import_type, strategy_name, additional_attributes)

    // Ok, nothing ambiguous here
    # Ok, nothing ambiguous here
    resource_uploader = ResourceUploader.new(resource_import)
    resource_uploader.store!(tempfile)

    @@ -19,8 +19,8 @@ def import_file_data(file_path, content, import_type, strategy_name, additional_
    import_resource_import(resource_import)
    end

    // maybe reload already returns the resource_import new and we don't need the last line at all? resource_import.reload
    // implicit returns always felt 'dirty' to me. For example ActiveRecord callbacks which return false
    // break the chain, so you have to know that to not break it unintentionally
    # maybe reload already returns the resource_import new and we don't need the last line at all? resource_import.reload
    # implicit returns always felt 'dirty' to me. For example ActiveRecord callbacks which return false
    # break the chain, so you have to know that to not break it unintentionally
    resource_import
    end
  3. Helmut Michael Juskewycz revised this gist Jun 26, 2014. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -19,8 +19,7 @@ def import_file_data(file_path, content, import_type, strategy_name, additional_
    import_resource_import(resource_import)
    end

    // maybe reload already returns the resource_import new and we don't need the last line at all?
    resource_import.reload
    // maybe reload already returns the resource_import new and we don't need the last line at all? resource_import.reload
    // implicit returns always felt 'dirty' to me. For example ActiveRecord callbacks which return false
    // break the chain, so you have to know that to not break it unintentionally
    resource_import
  4. Helmut Michael Juskewycz revised this gist Jun 26, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -22,6 +22,6 @@ def import_file_data(file_path, content, import_type, strategy_name, additional_
    // maybe reload already returns the resource_import new and we don't need the last line at all?
    resource_import.reload
    // implicit returns always felt 'dirty' to me. For example ActiveRecord callbacks which return false
    // break the cahain
    // break the chain, so you have to know that to not break it unintentionally
    resource_import
    end
  5. Helmut Michael Juskewycz revised this gist Jun 26, 2014. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,15 @@
    def import_file_data(file_path, content, import_type, strategy_name, additional_attributes = {}, options = {})
    // probably file_path is a String and the result file_name as well
    file_name = File.basename(file_path)

    // no idea what tempfile is, a string?
    tempfile = write_to_temp_file(content, file_name)
    uploaded_file = OpenStruct.new(:original_filename => file_name, :tempfile => tempfile)

    // Is this now an instance of ResourceImport or a result of a resource import?
    resource_import = ResourceImport.import!(user, project, uploaded_file, file_path, import_type, strategy_name, additional_attributes)

    // Ok, nothing ambiguous here
    resource_uploader = ResourceUploader.new(resource_import)
    resource_uploader.store!(tempfile)

    @@ -15,6 +19,9 @@ def import_file_data(file_path, content, import_type, strategy_name, additional_
    import_resource_import(resource_import)
    end

    // maybe reload already returns the resource_import new and we don't need the last line at all?
    resource_import.reload
    // implicit returns always felt 'dirty' to me. For example ActiveRecord callbacks which return false
    // break the cahain
    resource_import
    end
  6. Helmut Michael Juskewycz created this gist Jun 26, 2014.
    20 changes: 20 additions & 0 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    def import_file_data(file_path, content, import_type, strategy_name, additional_attributes = {}, options = {})
    file_name = File.basename(file_path)

    tempfile = write_to_temp_file(content, file_name)
    uploaded_file = OpenStruct.new(:original_filename => file_name, :tempfile => tempfile)

    resource_import = ResourceImport.import!(user, project, uploaded_file, file_path, import_type, strategy_name, additional_attributes)

    resource_uploader = ResourceUploader.new(resource_import)
    resource_uploader.store!(tempfile)

    if options.fetch(:schedule, true)
    ResourceImportsService.new.schedule_import(resource_import)
    else
    import_resource_import(resource_import)
    end

    resource_import.reload
    resource_import
    end