Alright, we should definitely make it work as a Hash.

For the method missing option, we should use it if we can have the same
behavior that we have when we try to get a value from a Hash with a key
that doesn't exist. If that can't be done, we should just go with the Hash
option only.


On Tue, Jan 21, 2014 at 11:37 AM, DamirSvrtan <notifications@github.com>wrote:

> In lib/stormpath-sdk/resource/custom_data.rb:
>
> > @@ -0,0 +1,46 @@
> > +class Stormpath::Resource::CustomData < Stormpath::Resource::Instance
> > +  include Stormpath::Resource::Status
> > +
> > +  RESERVED_FIELDS = %w( href createdAt modifiedAt meta spMeta spmeta ionmeta ionMeta )
> > +
> > +  def get(property_name)
> > +    property_name = property_name.to_s.camelize(:lower)
> > +    property = get_property property_name
> > +    property
> > +  end
> > +
> > +  def put(property_name, property_value)
>
> Yes, we can make it in a way the hashes work, no problem.
>
> What's method_missing? method_missing is a method that gets hit every time
> you try to call a non existing method. So let's say someone wants to set or
> get some custom_field to custom data resource, he or she could just write:
>
> account.custom_data.custom_field = "value"account.custom_data.custom_field #=> value
>
> And we would could define it like this:
>
> def method_missing(meth, *args, &block)
>     if meth =~ /=$/
>       property_name = meth.to_s.chomp("=").camelize(:lower)
>       set_property property_name, args[0]
>     else
>       property_name = meth.to_s.camelize(:lower)
>       property = get_property property_name
>       property || super(meth, *args, &block)
>     end
>   end
>
> The problem with it is that we wouldn't be able to raise errors properly,
> i.e. if someone tries to call a method on custom_data but misspells it,
> such as "safe" instead of "save", he would get a nil returned (if safe
> isn't defined in custom_data), and the developer would think that
> everything is okay, but actually isn't.
>
> Do we want to risk that?
>
> —
> Reply to this email directly or view it on GitHub<https://github.com/stormpath/stormpath-sdk-ruby/pull/53/files#r9050845>
> .
>