Module: Acts::Container::InstanceMethods

Defined in:
lib/acts/container.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

:nodoc:



34
35
36
# File 'lib/acts/container.rb', line 34

def self.included(base) # :nodoc:
	base.extend ClassMethods
end

Instance Method Details

#<<(content) ⇒ Object

Raises:

  • (Exception)


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/acts/container.rb', line 46

def <<(content)
	content.container = nil
	self.containables.each do |containable|
		begin				
			 self.send(containable).<< content
			return # if it successfully adds we are done with this method.
			
		# there is probably a better way to do this. right now if it can't be added to the container
		# we just catch that exception and keep going until we iterate through all the possibilities
		rescue ActiveRecord::AssociationTypeMismatch
			next
		end
	end
	raise Exception.new("Unable to add content to container. Object type did not match any containable type.")
end

#contentsObject



38
39
40
41
42
43
44
# File 'lib/acts/container.rb', line 38

def contents
	contents = []
	self.containables.each do |containable|
		contents += self.send(containable)
	end
	contents
end

#message(message_string) ⇒ Object



62
63
64
65
66
67
68
# File 'lib/acts/container.rb', line 62

def message(message_string)
	self.handle.message(message_string) if self.respond_to?(:handle)

	self.contents.each do |content|
		content.message(message_string)
	end
end