Method: ActiveComponent::Base.json_create
- Defined in:
- lib/active_component/base.rb
.json_create(json_hash) ⇒ Tree::TreeNode
Creates a Tree::TreeNode object instance from a given JSON Hash representation. This requires the JSON gem to be available, or else the operation fails with a warning message.
817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 |
# File 'lib/active_component/base.rb', line 817 def self.json_create(json_hash) begin require 'json' node = new(json_hash["node_name"], json_hash["node_content"]) json_hash["children"].each do |child| node << child end if json_hash["children"] return node rescue LoadError => e warn "The JSON gem couldn't be loaded. Due to this we cannot serialize the tree to a JSON representation." end end |