Skip to content
flipback edited this page Nov 5, 2011 · 4 revisions

Best way to configure of tree is using templates. You can create template by Root#kind method with defaults attributes as node and make its instances. For example:

  tree = root :tree do
    # template
    kind :object do
      param_1 0
      param_2 "string_of_param"
    end
   
    # instances
    object :obj_1 
    object :obj_2
  end

  tree.obj_1.param_1 #=> 0
  tree.obj_2.param_1 #=> 0
  tree.obj_1.kind #=> :object
  tree.obj_2.kind #=> :object

Default attributes of template can be overridden in instance:

  tree = root :tree do
    kind :object do
      param_1 0
      param_2 "string_of_param"
    end

    object :obj_1 
    object :obj_2 do
      param_1 999
    end
  end

  tree.obj_1.param_1 #=> 0
  tree.obj_2.param_1 #=> 999

Also Lipa provide template for nesting nodes:

  tree = root :tree do
    kind :object do
      node :child do
        param_1 0
      end
    end

    object :obj_1 
  end

  tree.obj_1.child.param_1 #=> 0
Clone this wiki locally