Sha256: f5b690b8f3910553757ac758db4ea33aa6f3762ea2801029f94fb5dd5cc36ddb

Contents?: true

Size: 926 Bytes

Versions: 4

Compression:

Stored size: 926 Bytes

Contents

module PushType
  module Nestable
    extend ActiveSupport::Concern

    def child_nodes
      self.class.child_nodes
    end

    def custom_child_order?
      self.class.child_order.present?
    end

    def sortable?
      !custom_child_order?
    end

    def children
      return super() unless custom_child_order?
      super.reorder(self.class.child_order)
    end

    module ClassMethods

      attr_reader :child_order

      def child_nodes
        types = @child_nodes || PushType.config.root_nodes
        PushType.node_types_from_list(types)
      end

      def has_child_nodes(*args)
        if args.last.is_a? Hash
          opts = args.pop
          @child_order = case opts[:order]
            when :blog then ['published_at DESC', 'created_at DESC']
            else opts[:order]
          end
        else
          @child_order = nil
        end
        @child_nodes = args
      end

    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
push_type_core-0.3.1 app/models/concerns/push_type/nestable.rb
push_type_core-0.2.1 app/models/concerns/push_type/nestable.rb
push_type_core-0.2.0 app/models/concerns/push_type/nestable.rb
push_type_core-0.2.0.beta2 app/models/concerns/push_type/nestable.rb