Sha256: 90129dc479a2a6d0b107da3da17d69b74b991126a3714ebb70605865671181b9

Contents?: true

Size: 974 Bytes

Versions: 3

Compression:

Stored size: 974 Bytes

Contents

module Noodall
  class Component
    include MongoMapper::EmbeddedDocument

    key :_type, String
    key :style, String

    embedded_in :node

    module ClassMethods
      def possible_slots
        Node.possible_slots
      end

      def allowed_positions(*args)
        warn "[DEPRECATION] `allowed_positions` is deprecated. Please use `Noodall::Node.slot` instead."
        allowed_positions = args.reject{|a| !Node.possible_slots.include?(a) }.uniq

        allowed_positions.each do |p|
          Node.send("#{p}_slot_components") << self
        end
      end

      def positions_classes(position)
        Node.send("#{position}_slot_components")
      end

      def positions_names(position)
        positions_classes(position).collect{|c| c.name.titleize }
      end

      # Allow us to set the component to nil if we get a blank
      def to_mongo(value)
        return nil if value.blank?
        super
      end

    end
    extend ClassMethods
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
noodall-core-0.8.2 lib/noodall/component.rb
noodall-core-0.8.1 lib/noodall/component.rb
noodall-core-0.8.0 lib/noodall/component.rb