@@ -4,144 +4,96 @@ module HasContent
44 extend ActiveSupport ::Concern
55
66 included do
7- # Base content types
8- has_many :universes
9- has_many :characters
10- has_many :items
11- has_many :locations
7+ Rails . application . config . content_types [ :all ] . each do |content_type |
8+ content_type_sym = content_type . name . downcase . pluralize . to_sym # :characters
129
13- # Extended content types
14- has_many :creatures
15- has_many :races
16- has_many :religions
17- has_many :magics
18- has_many :languages
19- has_many :groups
20- has_many :floras
21- has_many :towns
22- has_many :countries
23- has_many :landmarks
24-
25- # Collective content types
26- has_many :scenes
10+ #has_many :characters, :locations, etc
11+ has_many content_type_sym , dependent : :destroy
12+ end
2713
2814 has_many :attribute_fields
2915 has_many :attribute_categories
3016 has_many :attribute_values , class_name : 'Attribute'
3117
18+ # {
19+ # characters: [...],
20+ # locations: [...]
21+ # }
3222 def content
33- @user_content ||= {
34- characters : characters ,
35- items : items ,
36- locations : locations ,
37- universes : universes ,
38- creatures : creatures ,
39- races : races ,
40- religions : religions ,
41- magics : magics ,
42- languages : languages ,
43- scenes : scenes ,
44- groups : groups ,
45- towns : towns ,
46- countries : countries ,
47- landmarks : landmarks
48- }
23+ @user_content ||= begin
24+ content_value = { }
25+ Rails . application . config . content_types [ :all ] . each do |type |
26+ relation = type . name . downcase . pluralize . to_sym # :characters
27+ content_value [ relation ] = send ( relation )
28+ end
29+
30+ content_value
31+ end
4932 end
5033
34+ # [..., ...]
5135 def content_list
52- @user_content_list ||= [
53- universes ,
54- characters ,
55- items ,
56- locations ,
57- creatures ,
58- races ,
59- religions ,
60- magics ,
61- languages ,
62- scenes ,
63- groups ,
64- towns ,
65- countries ,
66- landmarks
67- ] . flatten
36+ @user_content_list ||= begin
37+ Rails . application . config . content_types [ :all ] . map do |type |
38+ relation = type . name . downcase . pluralize . to_sym # :characters
39+ send ( relation )
40+ end
41+ end . flatten
6842 end
6943
44+ # {
45+ # characters: [...],
46+ # locations: [...]
47+ # }
7048 def content_in_universe universe_id
71- @user_content_in_universe ||= {
72- characters : characters . in_universe ( universe_id ) ,
73- items : items . in_universe ( universe_id ) ,
74- locations : locations . in_universe ( universe_id ) ,
75- creatures : creatures . in_universe ( universe_id ) ,
76- races : races . in_universe ( universe_id ) ,
77- religions : religions . in_universe ( universe_id ) ,
78- magics : magics . in_universe ( universe_id ) ,
79- languages : languages . in_universe ( universe_id ) ,
80- scenes : scenes . in_universe ( universe_id ) ,
81- groups : groups . in_universe ( universe_id ) ,
82- towns : towns . in_universe ( universe_id ) ,
83- landmarks : landmarks . in_universe ( universe_id ) ,
84- countries : countries . in_universe ( universe_id )
85- }
49+ @user_content_in_universe ||= begin
50+ content_value = { }
51+ Rails . application . config . content_types [ :all ] . each do |type |
52+ relation = type . name . downcase . pluralize . to_sym # :characters
53+ content_value [ relation ] = send ( relation ) . in_universe ( universe_id )
54+ end
55+
56+ content_value
57+ end
8658 end
8759
60+ # 5
8861 def content_count
89- @user_content_count ||= [
90- characters . length ,
91- items . length ,
92- locations . length ,
93- universes . length ,
94- creatures . length ,
95- races . length ,
96- religions . length ,
97- magics . length ,
98- languages . length ,
99- scenes . length ,
100- groups . length ,
101- towns . length ,
102- landmarks . length ,
103- countries . length
104- ] . sum
62+ @user_content_count ||= begin
63+ Rails . application . config . content_types [ :all ] . map do |type |
64+ relation = type . name . downcase . pluralize . to_sym # :characters
65+ send ( relation ) . count
66+ end . sum
67+ end
10568 end
10669
70+ # {
71+ # characters: [...],
72+ # locations: [...],
73+ # }
10774 def public_content
108- {
109- characters : characters . is_public ,
110- items : items . is_public ,
111- locations : locations . is_public ,
112- universes : universes . is_public ,
113- creatures : creatures . is_public ,
114- races : races . is_public ,
115- religions : religions . is_public ,
116- magics : magics . is_public ,
117- languages : languages . is_public ,
118- scenes : scenes . is_public ,
119- groups : groups . is_public ,
120- towns : towns . is_public ,
121- countries : countries . is_public ,
122- landmarks : landmarks . is_public
123- }
75+ @user_public_content ||= begin
76+ content_value = { }
77+ Rails . application . config . content_types [ :all ] . each do |type |
78+ relation = type . name . downcase . pluralize . to_sym # :characters
79+ content_value [ relation ] = send ( relation ) . is_public
80+ end
81+
82+ content_value
83+ end
12484 end
12585
86+ # 8
12687 def public_content_count
127- [
128- characters . is_public . length ,
129- items . is_public . length ,
130- locations . is_public . length ,
131- universes . is_public . length ,
132- creatures . is_public . length ,
133- races . is_public . length ,
134- religions . is_public . length ,
135- magics . is_public . length ,
136- languages . is_public . length ,
137- scenes . is_public . length ,
138- groups . is_public . length ,
139- towns . is_public . length ,
140- countries . is_public . length ,
141- landmarks . is_public . length
142- ] . sum
88+ @user_content_count ||= begin
89+ Rails . application . config . content_types [ :all ] . map do |type |
90+ relation = type . name . downcase . pluralize . to_sym # :characters
91+ send ( relation ) . is_public . count
92+ end . sum
93+ end
14394 end
14495
96+ # [..., ..., ...]
14597 def recent_content_list
14698 content_types = Rails . application . config . content_types [ :all ]
14799
0 commit comments