Module: Customize::Characterize

Defined in:
lib/customize/characterize.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
7
8
# File 'lib/customize/characterize.rb', line 4

def self.included base
	base.extend ClassMethods
	base.has_many :characters, :class_name=>Customize::Character.name, :as=>:related
	base.accepts_nested_attributes_for :characters
end

Instance Method Details

#characterObject



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/customize/characterize.rb', line 13

def character
	@character ||= proc {
		ascent_ids =  self.class.include?(Customize::Inherited) ? self.ascent_ids : []
		all_character = Character.where(:related_id=>(ascent_ids | [self.id]), :related_type=>self.class.name)
		all_character.inject(HashWithIndifferentAccess.new) { |map, item| 
			map[item.key] = item.value
			map
		}
	}.call

end

#inherited_charactersObject



25
26
27
28
29
# File 'lib/customize/characterize.rb', line 25

def inherited_characters
	if self.class.include?(Customize::Inherited)
		Character.where(:related_id=>ascent_ids, :related_type=>self.class.name)
	end
end