Giter Site home page Giter Site logo

Comments (4)

janlelis avatar janlelis commented on September 24, 2024

Hi troopswap, many thanks for your feedback.

I'll try to fix the issues within the next days.

from has_many_booleans.

janlelis avatar janlelis commented on September 24, 2024

Hi troopswap,
the second issue is solved with this push. The default for :false_values is now the ar's one and there is a new :true_values array and :unknown_value option. The :unknown_value will be the new value for a boolean, if it is not in :false_values or :true_values. Default for unknown is true, you can change it to false for ar behaviour.

However, I haven't solved the first issue so far... Your suggestions are good and would lead to something like this:
def initialize(attributes = nil) # :nodoc:
super()
initialize_booleans
self.attributes = attributes unless attributes.nil?
yield self if block_given?
end

The only problem is, that the after_initialize callback wouldn't have access to the new attrs. It's probably time for some meta programming voodoo xD,

from has_many_booleans.

janlelis avatar janlelis commented on September 24, 2024

Ok, should now work, thank you again :)

inialize code:
def initialize(attributes = nil) # :nodoc:

  if init_callback_defined = respond_to?(:after_initialize)
    instance_eval do
      alias tmp_after_initialize after_initialize
      undef after_initialize
    end
  end

  super()
  initialize_booleans
  self.attributes = attributes unless attributes.nil?
  result = yield self if block_given?

  if init_callback_defined
    instance_eval do
      alias after_initialize tmp_after_initialize
      undef tmp_after_initialize
      if RAILS2
        callback(:after_initialize)
      else
        _run_initialize_callbacks
      end
    end
  end

  result
end

from has_many_booleans.

 avatar commented on September 24, 2024

This looks really nice, thanks for the prompt response also.
P.S it was me who posted under "troopswap" account before on accident :)

from has_many_booleans.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.