Skip to content

Commit

Permalink
Metadata: Fix the form helper so it doesn't mutate arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamin-hull committed Oct 28, 2014
1 parent 73c9dcd commit fd4ae7b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/islay/form_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ def metadata(&blk)
# @return String
#
# @todo Support other types like URL, Email, etc.
def metadata_input(attribute_name, options = {}, &block)
def metadata_input(attribute_name, incoming_opts = {}, &block)
metaopts = object.metadata_attributes[attribute_name]
options = incoming_opts.dup

unless options.has_key?(:as)
options[:as] = case metaopts[:type]
Expand Down
5 changes: 4 additions & 1 deletion lib/islay/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ def define_validations(name, type, primitive, opts)

def define_attribute(name, type, primitive, opts)
raise ExistingAttributeError.new(name, @model) if column_names.include?(name)

reader = case primitive
when :array
%{
Expand All @@ -171,7 +172,9 @@ def define_attribute(name, type, primitive, opts)

writer = case primitive
when :array
%{self[_metadata.col] = data_column.merge('#{name}' => v)}
%{
self[_metadata.col] = data_column.merge('#{name}' => v)
}
else
%{self[_metadata.col] = data_column.merge('#{name}' => _metadata.coerce_#{primitive}(v))}
end
Expand Down
2 changes: 1 addition & 1 deletion lib/islay/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Islay
VERSION = "1.1.1"
VERSION = "1.1.2"
end

0 comments on commit fd4ae7b

Please sign in to comment.