Class: Eventable::Categorylist

Inherits:
Object
  • Object
show all
Defined in:
app/models/eventable/categorylist.rb

Defined Under Namespace

Classes: CategoryItem

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event) ⇒ Categorylist

Returns a new instance of Categorylist.



23
24
25
26
# File 'app/models/eventable/categorylist.rb', line 23

def initialize(event)
  @event = event
  @items = Eventable::Category.all.map { |c| CategoryItem.new(event, c)}
end

Instance Attribute Details

#eventObject (readonly)

Returns the value of attribute event.



3
4
5
# File 'app/models/eventable/categorylist.rb', line 3

def event
  @event
end

#itemsObject (readonly)

Returns the value of attribute items.



3
4
5
# File 'app/models/eventable/categorylist.rb', line 3

def items
  @items
end

Instance Method Details

#errorsObject



28
29
30
# File 'app/models/eventable/categorylist.rb', line 28

def errors
  ActiveRecord::Errors.new(self)
end

#items_attributes=(attr) ⇒ Object



32
33
34
35
36
# File 'app/models/eventable/categorylist.rb', line 32

def items_attributes=(attr)
  attr.values.each do |a|
    @items.detect { |i| i.id == a[:id].to_i }.active = (a[:active] == '1')
  end
end

#saveObject



45
46
47
# File 'app/models/eventable/categorylist.rb', line 45

def save
  @event.category_ids = @items.select(&:active).map(&:id)
end

#update_attributes(attrs) ⇒ Object



38
39
40
41
42
43
# File 'app/models/eventable/categorylist.rb', line 38

def update_attributes(attrs)
  attrs.each do |k,v|
    send "#{k}=", v
  end
  save
end