Module: Noodall::Component::ClassMethods

Included in:
Noodall::Component
Defined in:
lib/noodall/component.rb

Instance Method Summary collapse

Instance Method Details

#allowed_positions(*args) ⇒ Object



15
16
17
# File 'lib/noodall/component.rb', line 15

def allowed_positions(*args)
  @allowed_positions = args.reject{|a| !Node.possible_slots.include?(a) }.uniq
end

#positionsObject



19
20
21
# File 'lib/noodall/component.rb', line 19

def positions
  @allowed_positions || []
end

#positions_classes(position) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/noodall/component.rb', line 23

def positions_classes(position)
  classes = []
  ObjectSpace.each_object(Class) do |c|
    next unless c.ancestors.include?(Component) and (c != Component) and c.positions.include?(position)
    classes << c
  end
  classes
end

#positions_names(position) ⇒ Object



32
33
34
# File 'lib/noodall/component.rb', line 32

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

#possible_slotsObject



11
12
13
# File 'lib/noodall/component.rb', line 11

def possible_slots
  Node.possible_slots
end

#to_mongo(value) ⇒ Object

Allow us to set the component to nil if we get a blank



37
38
39
40
# File 'lib/noodall/component.rb', line 37

def to_mongo(value)
  return nil if value.blank?
  super
end