[BioRuby] [GSoC] ORM styled NeXML

Naohisa GOTO ngoto at gen-info.osaka-u.ac.jp
Fri Jul 30 14:10:23 UTC 2010


Hi Anurag,

On Thu, 29 Jul 2010 22:15:11 +0530
Anurag Priyam <anurag08priyam at gmail.com> wrote:

> An object invocation of NeXML is very much ORM like. An Otus and a Tree
> class could very well be represented as:
> 
> class Otus
>   include Mapper
> 
>   property :id, :label
>   has_n :trees
> end
> 
> class Trees
>   include Mapper
> 
>   property :id, :label
>   belongs_to :otus
> end
> 
> And, one would be able to do following:
> 
> otus1.trees << trees1
> otus1.trees = [ trees2, trees3]
> otus1.trees
> # => trees1, trees2, trees3
> trees1.otus
> # => otus1

I think the "trees=" should wipe out existing values and then
overwrite with the given values, as "=" operator normally does,
but the above "trees=" seems to act like Array#concat.
I expect:
  otus1.trees << trees1
  otus1.trees
  # => [ trees1 ]
  otus1.trees = [ trees2, trees3 ]
  otus1.trees
  # => [ trees2, trees3 ]
  otus1.trees << trees4
  otus1.trees
  # => [ tree2, tree3, tree4 ]
  tree1.otus
  # => []
  tree2.otus
  # => [ otus1 ]

I also think that the "trees" and "outs" methods should always
return an Array, even when with zero or one value.

> NeXML::Mapper module defines the magic methods property, has_n, and
> belongs_to which will use reflection to define the needed methods.
> 
> The above representation of Otus and Trees class feels very succinct to me.
> It could be due to my Rails/Merb background but, others can see it as a DSL.
> 
> What is the take of others on this coding style( including acceptance in
> BioRuby ) ?

I think DSL-like codings are welcomed if their maintenance is easy.

In addition, please don't forget to write reference manual for
the methods by using RDoc. One way I know is to write dummy
method definitions. For example,

  # Trees in the Otu.
  # ---
  # *Returns*:: Array containing Trees objects
  def trees if false #dummy for RDoc


Naohisa Goto
ngoto at gen-info.osaka-u.ac.jp / ng at bioruby.org




More information about the BioRuby mailing list