Sha256: cc0f7ae9f0f275d4948185ced35d668b618118401e941ccb43d8ddaa4df93a1c

Contents?: true

Size: 989 Bytes

Versions: 32

Compression:

Stored size: 989 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 descendable?
      !child_nodes.empty?
    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.subclasses_from_list(:node, 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

32 entries across 32 versions & 1 rubygems

Version Path
push_type_core-0.9.5 app/models/concerns/push_type/nestable.rb
push_type_core-0.9.3 app/models/concerns/push_type/nestable.rb
push_type_core-0.9.2 app/models/concerns/push_type/nestable.rb
push_type_core-0.9.1 app/models/concerns/push_type/nestable.rb
push_type_core-0.9.0 app/models/concerns/push_type/nestable.rb
push_type_core-0.9.0.beta.4 app/models/concerns/push_type/nestable.rb
push_type_core-0.9.0.beta.3 app/models/concerns/push_type/nestable.rb
push_type_core-0.9.0.beta.2 app/models/concerns/push_type/nestable.rb
push_type_core-0.8.2 app/models/concerns/push_type/nestable.rb
push_type_core-0.8.1 app/models/concerns/push_type/nestable.rb
push_type_core-0.8.0 app/models/concerns/push_type/nestable.rb
push_type_core-0.8.0.beta.3 app/models/concerns/push_type/nestable.rb
push_type_core-0.8.0.beta.2 app/models/concerns/push_type/nestable.rb
push_type_core-0.8.0.beta.1 app/models/concerns/push_type/nestable.rb
push_type_core-0.7.0 app/models/concerns/push_type/nestable.rb
push_type_core-0.7.0.beta.1 app/models/concerns/push_type/nestable.rb
push_type_core-0.6.0 app/models/concerns/push_type/nestable.rb
push_type_core-0.6.0.beta.4 app/models/concerns/push_type/nestable.rb
push_type_core-0.6.0.beta.3 app/models/concerns/push_type/nestable.rb
push_type_core-0.6.0.beta.2 app/models/concerns/push_type/nestable.rb