Class: ActsAsAssociateTree::NodeSet
- Inherits:
-
Object
- Object
- ActsAsAssociateTree::NodeSet
- Defined in:
- lib/acts_as_associate_tree/node_set.rb
Instance Attribute Summary collapse
-
#children_sets ⇒ Object
readonly
Returns the value of attribute children_sets.
-
#expandable ⇒ Object
readonly
for ‘symbol’ feature.
-
#mother_tree ⇒ Object
readonly
for ‘symbol’ feature.
-
#node_attrs_block ⇒ Object
readonly
Returns the value of attribute node_attrs_block.
-
#nodes_block ⇒ Object
readonly
Returns the value of attribute nodes_block.
-
#parent_set ⇒ Object
readonly
for ‘symbol’ feature.
-
#set_attrs_block ⇒ Object
readonly
Returns the value of attribute set_attrs_block.
-
#set_block ⇒ Object
readonly
Returns the value of attribute set_block.
-
#set_symbol ⇒ Object
readonly
for ‘symbol’ feature.
Instance Method Summary collapse
-
#children(&block) ⇒ Object
子节点属性.
-
#enable_expanding ⇒ Object
resymbolize def resymbol symbol set_symbol end.
-
#expand(parent_scope = Object) ⇒ Object
展开树集.
- #expandable? ⇒ Boolean
-
#initialize(mother_tree, parent_set = nil, &block) ⇒ NodeSet
constructor
A new instance of NodeSet.
-
#node_attrs(&block) ⇒ Object
节点属性 block 的执行结果需返回一个 hash.
-
#nodes(&block) ⇒ Object
节点集合.
-
#set_attrs(&block) ⇒ Object
树集的属性 block 的执行结果需返回一个 hash.
-
#symbol(sym) ⇒ Object
with symbol setting, you would be able to generate only a part of a tree instead of a whole one.
Constructor Details
#initialize(mother_tree, parent_set = nil, &block) ⇒ NodeSet
Returns a new instance of NodeSet.
5 6 7 8 9 10 11 12 13 |
# File 'lib/acts_as_associate_tree/node_set.rb', line 5 def initialize(mother_tree, parent_set = nil, &block) @children_sets = [] @set_symbol = '' @mother_tree = mother_tree @expandable = true @parent_set = parent_set self.instance_eval &block end |
Instance Attribute Details
#children_sets ⇒ Object (readonly)
Returns the value of attribute children_sets.
3 4 5 |
# File 'lib/acts_as_associate_tree/node_set.rb', line 3 def children_sets @children_sets end |
#expandable ⇒ Object (readonly)
for ‘symbol’ feature
4 5 6 |
# File 'lib/acts_as_associate_tree/node_set.rb', line 4 def @expandable end |
#mother_tree ⇒ Object (readonly)
for ‘symbol’ feature
4 5 6 |
# File 'lib/acts_as_associate_tree/node_set.rb', line 4 def mother_tree @mother_tree end |
#node_attrs_block ⇒ Object (readonly)
Returns the value of attribute node_attrs_block.
3 4 5 |
# File 'lib/acts_as_associate_tree/node_set.rb', line 3 def node_attrs_block @node_attrs_block end |
#nodes_block ⇒ Object (readonly)
Returns the value of attribute nodes_block.
3 4 5 |
# File 'lib/acts_as_associate_tree/node_set.rb', line 3 def nodes_block @nodes_block end |
#parent_set ⇒ Object (readonly)
for ‘symbol’ feature
4 5 6 |
# File 'lib/acts_as_associate_tree/node_set.rb', line 4 def parent_set @parent_set end |
#set_attrs_block ⇒ Object (readonly)
Returns the value of attribute set_attrs_block.
3 4 5 |
# File 'lib/acts_as_associate_tree/node_set.rb', line 3 def set_attrs_block @set_attrs_block end |
#set_block ⇒ Object (readonly)
Returns the value of attribute set_block.
3 4 5 |
# File 'lib/acts_as_associate_tree/node_set.rb', line 3 def set_block @set_block end |
#set_symbol ⇒ Object (readonly)
for ‘symbol’ feature
4 5 6 |
# File 'lib/acts_as_associate_tree/node_set.rb', line 4 def set_symbol @set_symbol end |
Instance Method Details
#children(&block) ⇒ Object
子节点属性
56 57 58 |
# File 'lib/acts_as_associate_tree/node_set.rb', line 56 def children(&block) @children_sets << NodeSet.new(mother_tree, self, &block) end |
#enable_expanding ⇒ Object
resymbolize def resymbol
symbol set_symbol
end
29 30 31 32 |
# File 'lib/acts_as_associate_tree/node_set.rb', line 29 def @expandable = true parent_set. unless parent_set.nil? end |
#expand(parent_scope = Object) ⇒ Object
展开树集
66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/acts_as_associate_tree/node_set.rb', line 66 def (parent_scope = Object) return [] unless nodes = parent_scope.instance_eval &nodes_block # Expand child set of each node = nodes.map do |node| node_attrs = generate_node_attrs(node) (node, node_attrs) end # Wrap a set around the expaned set = set_up_set_attributes(parent_scope, ) unless set_attrs_block.nil? end |
#expandable? ⇒ Boolean
60 61 62 |
# File 'lib/acts_as_associate_tree/node_set.rb', line 60 def end |
#node_attrs(&block) ⇒ Object
节点属性block 的执行结果需返回一个 hash
50 51 52 |
# File 'lib/acts_as_associate_tree/node_set.rb', line 50 def node_attrs(&block) @node_attrs_block = block end |
#nodes(&block) ⇒ Object
节点集合
43 44 45 |
# File 'lib/acts_as_associate_tree/node_set.rb', line 43 def nodes(&block) @nodes_block = block end |
#set_attrs(&block) ⇒ Object
树集的属性block 的执行结果需返回一个 hash
37 38 39 |
# File 'lib/acts_as_associate_tree/node_set.rb', line 37 def set_attrs(&block) @set_attrs_block = block end |
#symbol(sym) ⇒ Object
with symbol setting, you would be able to generate only a part of a tree instead of a whole one
16 17 18 19 20 21 22 |
# File 'lib/acts_as_associate_tree/node_set.rb', line 16 def symbol(sym) raise ConfigurationError.new('symbol Must be a SYMBOL') unless sym.kind_of? Symbol @set_symbol = sym return if mother_tree. == :all @expandable = false if mother_tree. == @set_symbol end |