Although my Ruby knowledge is fairly rudimentary I've been attempting
to read some of the DataMapper code since I was curious about the
issue regarding associations that I raised in an earlier post. I think
I'm slowly getting an understanding of how some things work, but there
are a couple of areas I'm struggling to understand. I'd really
appreciate some pointers from any of the experts here...
The definition of the 'has' method in module DataMapper::Associations
(associations.rb) includes the following -
...
def has(cardinality, name, options = {})
...
klass = ManyToMany if options[:through] == DataMapper::Resource
relationship = klass.setup(options.delete(:name), self, options)
...
I'm not sure how to interpret the semantics of 'options[:through] ==
DataMapper::Resource' in the second line above. My first impression
was that 'DataMapper::Resource' represents a constant containing the
definition of the Resource module. Yet I believe the value of 'options
[:through]' is the name of the specific resource that forms the join
model in the many-to-many association, something like ':tagging' for
example. Clearly I'm misunderstanding something - what's the right way
to read this?
Second question... The method 'setup' that is called on the ManyToMany
object 'klass' when the condition above succeeds is defined in
associations/manytomany.rb and adds new methods to model objects using
'model.class_eval...' (at least that's what I think is going on).
One of those methods, '#{name}_association', instantiates a new Proxy
object with 'association = Proxy.new(relationship, self)'. The Proxy
class is defined in the module as a subclass of
DataMapper::Associations::OneToMany::Proxy, which is where the 'new'
method is defined (in associations/onetomany.rb). 'new' includes a
call to 'super(attributes)'.
My question is what does 'super' refer to here? I understand it to be
a call to the method 'new' on Proxy's parent class. Yet Proxy is not
explicitly defined here as a subclass. I would take it to be a
subclass of Object, but Object.new(attributes) doesn't seem to fit in
this context.
As I say, I'm pretty new to Ruby so these questions probably reflect
my relative ignorance of the language, but I would appreciate it if
someone could clear up my misunderstanding.
Mark.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"DataMapper" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/datamapper?hl=en
-~----------~----~----~----~------~----~------~--~---