Comments (4)
Hi troopswap, many thanks for your feedback.
I'll try to fix the issues within the next days.
from has_many_booleans.
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.
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.
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)
- Validations for booleans HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from has_many_booleans.