Skip to content

Commit

Permalink
always overwrite columns even if you're nullifying a present value
Browse files Browse the repository at this point in the history
  • Loading branch information
seamusabshere committed Jul 23, 2013
1 parent e1fbba2 commit eb212f9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Expand Up @@ -4,6 +4,7 @@ unreleased

* no more unit conversions
* always nullifies blank strings
* always overwrites columns whether there was a non-null value there before or not (no more :overwrite option)

2.5.2 / 2013-07-05

Expand Down
27 changes: 5 additions & 22 deletions lib/data_miner/attribute.rb
Expand Up @@ -27,7 +27,6 @@ def check_options(options)
:delimiter,
:split,
:sprintf,
:overwrite,
:upcase,
:field_number,
:chars,
Expand All @@ -38,7 +37,6 @@ def check_options(options)
DEFAULT_SPLIT_KEEP = 0
DEFAULT_DELIMITER = ', '
DEFAULT_UPCASE = false
DEFAULT_OVERWRITE = true

# activerecord-3.2.6/lib/active_record/connection_adapters/column.rb
TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE', 'on', 'ON', 'yes', 'YES', 'y', 'Y']
Expand Down Expand Up @@ -101,10 +99,6 @@ def check_options(options)
# @return [TrueClass,FalseClass]
attr_reader :upcase

# Whether to overwrite the value in a local column if it is not null. Defaults to DEFAULT_OVERWRITE.
# @return [TrueClass,FalseClass]
attr_reader :overwrite

# @private
def initialize(step, name, options = {})
options = options.symbolize_keys
Expand All @@ -130,7 +124,6 @@ def initialize(step, name, options = {})
end
@upcase = options.fetch :upcase, DEFAULT_UPCASE
@sprintf = options[:sprintf]
@overwrite = options.fetch :overwrite, DEFAULT_OVERWRITE
@dictionary_mutex = ::Mutex.new
end

Expand Down Expand Up @@ -164,23 +157,13 @@ def field_name
@field_name = (hstore? ? hstore_key : name).to_sym
end


# # @private
# TODO make sure that nil handling is replicated when using upsert
# "_present" localvars used here aren't AS's present?... they mean non-nil
def set_from_row(local_record, remote_row)
previously_present = hstore? ? !local_record.send(hstore_column)[hstore_key].nil? : !local_record.send(name).nil?
would_be_present = nil
if overwrite or not previously_present
new_value = read remote_row
would_be_present = !new_value.nil?
if would_be_present or previously_present
if hstore?
local_record.send(hstore_column)[hstore_key] = new_value
else
local_record.send("#{name}=", new_value)
end
end
new_value = read remote_row
if hstore?
local_record.send(hstore_column)[hstore_key] = new_value
else
local_record.send("#{name}=", new_value)
end
end

Expand Down

0 comments on commit eb212f9

Please sign in to comment.