<commit_before>module Refinery
  class MenuItem < HashWithIndifferentAccess

    attr_accessor :menu_instance

    (ATTRIBUTES = [:id, :title, :parent_id, :lft, :rgt, :url, :menu_match, :type]).each do |attribute|
      class_eval %{
        def #{attribute}
          @#{attribute} ||= self[:#{attribute}]
        end

        def #{attribute}=(attr)
          @#{attribute} = attr
        end
      }
    end

    def inspect
      hash = {}

      ATTRIBUTES.each do |attribute|
        hash[attribute] = self[attribute]
      end

      hash
    end

    def children
      @children ||= menu_instance.select{|item|
        item.type == self.type && item.parent_id == self.id
      }
    end

    def descendants
      @descendants ||= menu_instance.select{|item|
        item.type == self.type && item.lft > self.lft && item.rgt < self.rgt
      }
    end

    def has_descendants?
      @has_descendants ||= menu_instance.any?{|item|
        item.type == self.type && item.lft > self.lft && item.rgt < self.rgt
      }
    end

    def parent
      @parent ||= self.parent_id ? menu_instance.detect{ |item|
        item.type == self.type && item.id == self.parent_id
      } : nil
    end

    def siblings
      @siblings ||= (parent.nil? ? menu_instance.roots : children) - [self]
    end
    alias_method :shown_siblings, :siblings

  end
end<commit_msg>Ensure that every selected set returns a ::Refinery::Menu instance so that all the same methods work as before you queried (could be improved).<commit_after>module Refinery
  class MenuItem < HashWithIndifferentAccess

    attr_accessor :menu_instance

    (ATTRIBUTES = [:id, :title, :parent_id, :lft, :rgt, :url, :menu_match, :type]).each do |attribute|
      class_eval %{
        def #{attribute}
          @#{attribute} ||= self[:#{attribute}]
        end

        def #{attribute}=(attr)
          @#{attribute} = attr
        end
      }
    end

    def inspect
      hash = {}

      ATTRIBUTES.each do |attribute|
        hash[attribute] = self[attribute]
      end

      hash
    end

    def children
      @children ||= menu_instance.class.new(menu_instance.select{|item|
        item.type == self.type && item.parent_id == self.id
      })
    end

    def descendants
      @descendants ||= menu_instance.class.new(menu_instance.select{|item|
        item.type == self.type && item.lft > self.lft && item.rgt < self.rgt
      })
    end

    def has_descendants?
      @has_descendants ||= menu_instance.class.new(menu_instance.any?{|item|
        item.type == self.type && item.lft > self.lft && item.rgt < self.rgt
      })
    end

    def parent
      @parent ||= self.parent_id ? menu_instance.detect{ |item|
        item.type == self.type && item.id == self.parent_id
      } : nil
    end

    def siblings
      @siblings ||= menu_instance.class.new((parent.nil? ? menu_instance.roots : children) - [self])
    end
    alias_method :shown_siblings, :siblings

  end
end
{'fraction_non_alphanumeric': 0.12618403247631935, 'fraction_numerical': 0.0, 'mean_word_length': 2.3374717832957113, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1439608', 'n_tokens_mistral': 974, 'n_tokens_neox': 932, 'n_words': 215}