Class: ActsAsAssociateTree::SetTree
- Inherits:
-
Object
- Object
- ActsAsAssociateTree::SetTree
- Defined in:
- lib/acts_as_associate_tree/set_tree.rb
Instance Attribute Summary collapse
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
-
#add_set(&set_block) ⇒ Object
添加一个新的节点集.
-
#enroot(root) ⇒ Object
添加根节点,如果不需要根节点,可以不添加,节点类型需为一个哈希.
-
#expand ⇒ Object
展开所有的节点集.
-
#expanding_symbol(type = nil) ⇒ Object
expanding_symbol = :all || :set_symbol.
-
#initialize ⇒ SetTree
constructor
A new instance of SetTree.
Constructor Details
#initialize ⇒ SetTree
Returns a new instance of SetTree.
4 5 6 7 |
# File 'lib/acts_as_associate_tree/set_tree.rb', line 4 def initialize @node_sets = [] @expanding_symbol = :all end |
Instance Attribute Details
#root ⇒ Object (readonly)
Returns the value of attribute root.
3 4 5 |
# File 'lib/acts_as_associate_tree/set_tree.rb', line 3 def root @root end |
Instance Method Details
#add_set(&set_block) ⇒ Object
添加一个新的节点集
25 26 27 28 |
# File 'lib/acts_as_associate_tree/set_tree.rb', line 25 def add_set(&set_block) @node_sets << NodeSet.new(self, &set_block) self end |
#enroot(root) ⇒ Object
添加根节点,如果不需要根节点,可以不添加,节点类型需为一个哈希
11 12 13 14 |
# File 'lib/acts_as_associate_tree/set_tree.rb', line 11 def enroot(root) raise ConfigurationError.new("Root configuration should be a HASH INSTANCE") unless root.kind_of?(Hash) @root = root end |
#expand ⇒ Object
展开所有的节点集
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/acts_as_associate_tree/set_tree.rb', line 32 def # Expand all node sets = [] @node_sets.each do |node_set| += node_set. end # set up root attributes unless @root.nil? @root[:children] = = @root end end |
#expanding_symbol(type = nil) ⇒ Object
expanding_symbol = :all || :set_symbol
17 18 19 20 21 |
# File 'lib/acts_as_associate_tree/set_tree.rb', line 17 def (type = nil) return @expanding_symbol if type.nil? raise ConfigurationError.new('expanding_symbol Must be a SYMBOL') unless type.kind_of? Symbol @expanding_symbol = type end |