Skip to content
This repository has been archived by the owner on Sep 18, 2019. It is now read-only.

Fix reset process when initialize with boolean parameter #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

joker1007
Copy link

if initialize is given false parameter,
Boolean attribute is resetted.

for example, definition like README

module MassAssignment
  def initialize(attributes = {})
    self.attributes = attributes
  end

  def attributes=(attributes = {})
    attributes.each do |attr,value|
      self.send("#{attr}=", value) if self.respond_to?("#{attr}=")
    end
  end
end

class City
  include Attrio
  include MassAssignment

  define_attributes do
    attr :name, String
    attr :capital, Boolean
  end
end

Object initialization

city = City.new(name: "Osaka", capital: false)
city.capital # => this should be `false`, but this is `nil`

Reason

obj.send("#{group}")[name].reset! if obj.send(name).blank?

false.blank? is true, and attribute is resetted.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant