Sha256: 99321e1ac1e13ce8200476abcff4b0ccc8cd52e382d87e45cf3fc2a96470be8d
Contents?: true
Size: 1.46 KB
Versions: 1
Compression:
Stored size: 1.46 KB
Contents
require 'rubytree' module Rooler class LiquidInspector def initialize(klass) @klass = klass @klass_name = klass.to_s.downcase end def tree add_liquid_methods_as_nodes(::Tree::TreeNode.new(@klass.to_s.downcase), @klass_name) end private # Recursive method. Infers a class name using the name of the provided TreeNode. Creates nodes any liquid methods belonging to that class. If any of those nodes # are also associations, it calls itself on that node. def add_liquid_methods_as_nodes(tree, klass_name) klass = klass_name.to_s.classify.constantize add_nodes_to_tree(tree, liquid_methods(klass)) associations(klass).each do |association| add_liquid_methods_as_nodes(tree[association.name.to_sym], association.class_name) end return tree end #iterate over nodes and add them to the tree. the << operator does not accept an array :( def add_nodes_to_tree(tree, nodes) nodes.each {|node| tree << ::Tree::TreeNode.new(node)} end #get associations haveing the same name as any liquid methods def associations(klass) liquid_methods = liquid_methods(klass) return klass.reflect_on_all_associations.select {|k| liquid_methods.include?(k.name.to_sym)} end def liquid_methods(klass) klass::LiquidDropClass.public_instance_methods.map(&:to_sym) - Liquid::Drop.public_instance_methods.map(&:to_sym) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rooler-0.0.5 | app/models/rooler/liquid_inspector.rb |