Created
June 18, 2010 13:27
-
-
Save knowtheory/443628 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'dm-core' | |
| require 'dm-migrations' | |
| DataMapper.setup(:default, "sqlite::in_memory:") | |
| class User | |
| def password=(value) | |
| raise NotImplementedError.new("I pity da f00!") | |
| end | |
| end | |
| class Guest < User | |
| include DataMapper::Resource | |
| # This overwrites the inherited method in 0.9.11, | |
| # in 1.0 it appears to call super() | |
| property :id, Serial | |
| property :password, String, :default => 'blank' | |
| end | |
| class Admin < User | |
| include DataMapper::Resource | |
| property :id, Serial | |
| property :password, String, :default => 'happycow' | |
| end | |
| DataMapper.auto_migrate! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| >> g = Guest.create | |
| => #<Guest @id=2 @password="blank"> | |
| >> g.password = "Taco" | |
| NotImplementedError: I pity da f00! | |
| from (irb):7:in `password=' | |
| from (irb):32 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
09:13:54 < solnic> knowtheory: afair there's a piece of code that looks if there's a public method defined named the same as the property which is about to be created
09:14:03 < solnic> knowtheory: if there's a clash it raises an error
09:14:18 < solnic> knowtheory: so for instance you cannot write property :model, String etc
09:14:39 < solnic> knowtheory: I didn't do it; it was already there since I believe 0.10.2
09:14:46 < knowtheory> oh i see, you're saying that the property method fails instead of overwriting/loading
09:14:57 < solnic> knowtheory: yeah
09:15:06 < solnic> knowtheory: but lemme check the code
09:15:34 *** jtrupiano ~jtrupiano@12.167.154.53 has joined #datamapper
09:15:40 < knowtheory> solnic: it looks like that's only true for things reserved by DataMapper
09:15:49 < knowtheory> line 785 of property in dm-core 1.0
09:15:53 @ssmoot solnic: knowtheorySounds like you'd got it, but here's mah pastie: http://pastie.org/1010017
09:17:32 < solnic> knowtheory: ah! you're right it only checks for DM::Resource priv and instance methods
09:18:05 *** jed ~Adium@cpe-071-076-003-040.sc.res.rr.com has left #datamapper []
09:18:54 < solnic> ssmoot, knowtheory: in 1.0.0 property setters are chainable, so yeah it will call method coming from the parent class
09:19:30 @ssmoot solnic: is there a way to disable that and force an overwrite? Can you point me to the codes?
09:20:47 < solnic> ssmoot: I don't think so :( here's how the setters are generated: http://github.com/datamapper/dm-core/blob/master/lib/dm-core/model/property.rb#L269
09:21:25 < knowtheory> ssmoot & solnic here's the full spike: https://gist.github.com/8876263c0ca3f02149ac
09:22:18 < solnic> knowtheory: yeah that's the expected behavior since chainable is used...I'm not sure if it's possible to avoid that
09:23:05 @ssmoot solnic: the Chainable call is new to me, but basically if I monkey-patch to make use of chainable { } optional I can revert to the overwriting behavior?
09:24:27 *** postmodern ~postmoder@c-76-105-159-111.hsd1.or.comcast.net has quit [Quit: Leaving]
09:24:47 < solnic> ssmoot: yes if you define a setter w/o chainable block it should work for you
09:24:54 *** myabc ~alexbcole@gateway.spiekermannpartners.com has joined #datamapper
09:25:19 @ssmoot solnic: thanks sir.