Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ParseModel::Model initialize bug? #13

Open
runkmc opened this issue Jan 30, 2013 · 2 comments
Open

ParseModel::Model initialize bug? #13

runkmc opened this issue Jan 30, 2013 · 2 comments

Comments

@runkmc
Copy link
Contributor

runkmc commented Jan 30, 2013

When ParseModel is added to a project using bundler, ParseModel::Model initialize, when given a hash as an argument, assigns that hash to @PFObject. I got this in the console:

a = MyClass.new( {timer: Time.now} )
a.PFObject.class
>  Hash

When I add ParseModel to my project as a submodule, everything works as it should.

@adelevie
Copy link
Owner

Hmm, that is odd. The issue can probably be traced here in initialize (duh) https://github.com/adelevie/ParseModel/blob/master/lib/ParseModel/Model.rb. Could be a RubyMotion bug...I do know that when over-riding init, you need to return self, otherwise your instantiation will just return the last expression and not the object instance.

Maybe this is unsatisfactory, but what would you think if I eliminated mass-assignment? Seems to have caused issues in the Rails-ecosystem. Especially considering Parse lets you "create" a column by simply writing to it...

@runkmc
Copy link
Contributor Author

runkmc commented Jan 30, 2013

I've poked around Model.rb. The problem seems to be that line 7,

if arg.is_a?(PFObject)

returns true for any non nil object. The second if statement that checks for a hash never gets called as a result. I don't see why using bundler causes this to happen vs. just placing the files in lib/ or vendor/ or whatever.

In the meantime, I've overridden the module's initialize method to allow me to do roughly the same thing, only with a block instead of a hash:

def initialize(pf_object=nil)
  @PFObject = pf_object || PFObject.objectWithClassName(self.class.to_s)
  yield self if block_given?
end

As for eliminating mass assignment, I guess I don't know enough to form a strong opinion. Added security is always nice, but I don't know nearly enough about Parse in general to know what the risks of mass assignment are here.

It's probably not the direction you want to go, but if you'd like me to submit my init method in a pull request, just let me know.

*Edit for clarity

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

No branches or pull requests

2 participants