amoeba 3.3.0 → 3.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,416 +0,0 @@
1
- class Topic < ActiveRecord::Base
2
- has_many :posts
3
- end
4
-
5
- class User < ActiveRecord::Base
6
- has_many :posts
7
- end
8
-
9
- class Author < ActiveRecord::Base
10
- has_many :posts, inverse_of: :author
11
- amoeba do
12
- enable
13
- end
14
- end
15
-
16
- class Post < ActiveRecord::Base
17
- belongs_to :topic
18
- belongs_to :owner, class_name: 'User'
19
- belongs_to :author, inverse_of: :posts
20
- has_one :post_config
21
- has_one :account
22
- has_one :history, through: :account
23
- has_many :comments
24
- has_many :supercats
25
- has_many :categories, through: :supercats
26
- has_many :post_widgets
27
- has_many :widgets, through: :post_widgets
28
- has_many :custom_things
29
- has_and_belongs_to_many :tags
30
- has_and_belongs_to_many :notes
31
-
32
- validates_presence_of :topic
33
- validates_presence_of :author
34
-
35
- amoeba do
36
- enable
37
- clone %i[widgets notes]
38
- prepend title: 'Copy of '
39
- append contents: ' (copied version)'
40
- regex contents: { replace: /dog/, with: 'cat' }
41
- customize([
42
- lambda do |orig_obj, copy_of_obj|
43
- orig_obj.comments.each do |oc|
44
- next unless oc.nerf == 'ratatat'
45
-
46
- hash = oc.attributes
47
- hash[:id] = nil
48
- hash[:post_id] = nil
49
- hash[:contents] = nil
50
-
51
- cc = Comment.new(hash)
52
-
53
- copy_of_obj.comments << cc
54
- end
55
- end,
56
- lambda do |orig_obj, copy_of_obj|
57
- orig_obj.comments.each do |oc|
58
- next unless oc.nerf == 'bonk'
59
-
60
- hash = oc.attributes
61
- hash[:id] = nil
62
- hash[:post_id] = nil
63
- hash[:contents] = nil
64
- hash[:nerf] = 'bonkers'
65
-
66
- cc = Comment.new(hash)
67
-
68
- copy_of_obj.comments << cc
69
- end
70
- end
71
- ])
72
- end
73
-
74
- def truthy?
75
- true
76
- end
77
-
78
- def falsey?
79
- false
80
- end
81
-
82
- class << self
83
- def tag_count
84
- ActiveRecord::Base.connection.select_one('SELECT COUNT(*) AS tag_count FROM posts_tags')['tag_count']
85
- end
86
-
87
- def note_count
88
- ActiveRecord::Base.connection.select_one('SELECT COUNT(*) AS note_count FROM notes_posts')['note_count']
89
- end
90
- end
91
- end
92
-
93
- class CustomThing < ActiveRecord::Base
94
- belongs_to :post
95
-
96
- class ArrayPack
97
- def self.load(str)
98
- return [] unless str.present?
99
- return str if str.is_a?(Array)
100
-
101
- str.split(',').map(&:to_i)
102
- end
103
-
104
- def self.dump(int_array)
105
- return '' unless int_array.present?
106
-
107
- int_array.join(',')
108
- end
109
- end
110
-
111
- serialize :value, ArrayPack
112
-
113
- before_create :hydrate_me
114
-
115
- def hydrate_me
116
- self.value = value
117
- end
118
- end
119
-
120
- class Account < ActiveRecord::Base
121
- belongs_to :post
122
- has_one :history
123
-
124
- amoeba do
125
- enable
126
- end
127
- end
128
-
129
- class History < ActiveRecord::Base
130
- belongs_to :account
131
- end
132
-
133
- class Category < ActiveRecord::Base
134
- has_many :supercats
135
- has_many :posts, through: :supercats
136
-
137
- amoeba do
138
- enable
139
- prepend ramblings: 'Copy of '
140
- set other_ramblings: 'La la la'
141
- end
142
- end
143
-
144
- class Supercat < ActiveRecord::Base
145
- belongs_to :post
146
- belongs_to :category
147
- has_many :superkittens
148
-
149
- amoeba do
150
- include_association :superkittens
151
- prepend ramblings: 'Copy of '
152
- set other_ramblings: 'La la la'
153
- end
154
- end
155
-
156
- class Superkitten < ActiveRecord::Base
157
- belongs_to :supercat
158
- end
159
-
160
- class PostConfig < ActiveRecord::Base
161
- belongs_to :post
162
- end
163
-
164
- class Comment < ActiveRecord::Base
165
- belongs_to :post
166
- has_many :ratings
167
- has_many :reviews
168
-
169
- amoeba do
170
- exclude_association :reviews
171
- end
172
- end
173
-
174
- class Review < ActiveRecord::Base
175
- belongs_to :comment
176
- end
177
-
178
- class Rating < ActiveRecord::Base
179
- belongs_to :comment
180
- end
181
-
182
- class Widget < ActiveRecord::Base
183
- has_many :post_widgets
184
- has_many :posts, through: :post_widgets
185
- end
186
-
187
- class PostWidget < ActiveRecord::Base
188
- belongs_to :post
189
- belongs_to :widget
190
- end
191
-
192
- class Tag < ActiveRecord::Base
193
- has_and_belongs_to_many :posts
194
- end
195
-
196
- class Note < ActiveRecord::Base
197
- has_and_belongs_to_many :posts
198
- end
199
-
200
- # Inheritance
201
- class Product < ActiveRecord::Base
202
- has_many :images
203
- has_and_belongs_to_many :sections
204
-
205
- SECTION_COUNT_QUERY = 'SELECT COUNT(*) AS section_count FROM products_sections WHERE product_id = ?'.freeze
206
-
207
- amoeba do
208
- enable
209
- propagate
210
- end
211
-
212
- def section_count
213
- ActiveRecord::Base.connection.select_one(SECTION_COUNT_QUERY, id)['section_count']
214
- end
215
- end
216
-
217
- class Section < ActiveRecord::Base
218
- end
219
-
220
- class Image < ActiveRecord::Base
221
- end
222
-
223
- class Shirt < Product
224
- amoeba do
225
- raised :submissive
226
- end
227
- end
228
-
229
- class Necklace < Product
230
- # Strange bug on rbx
231
- if defined?(::Rubinius)
232
- after_initialize :set_type
233
-
234
- def set_type
235
- self.type = 'Necklace'
236
- end
237
- end
238
-
239
- amoeba do
240
- raised :relaxed
241
- end
242
- end
243
-
244
- class BlackBox < Product
245
- amoeba do
246
- propagate :strict
247
- end
248
- end
249
-
250
- class SuperBlackBox < BlackBox
251
- end
252
-
253
- # Polymorphism
254
- class Address < ActiveRecord::Base
255
- belongs_to :addressable, polymorphic: true
256
-
257
- amoeba do
258
- enable
259
- end
260
- end
261
-
262
- class Photo < ActiveRecord::Base
263
- belongs_to :imageable, polymorphic: true
264
-
265
- amoeba do
266
- customize(lambda { |original_photo, new_photo|
267
- new_photo.name = original_photo.name.to_s + ' Copy'
268
- })
269
- end
270
- end
271
-
272
- class Company < ActiveRecord::Base
273
- has_many :employees
274
- has_many :customers
275
-
276
- amoeba do
277
- include_associations :employees,
278
- :customers
279
- end
280
- end
281
-
282
- class Employee < ActiveRecord::Base
283
- has_many :addresses, as: :addressable
284
- has_many :photos, as: :imageable
285
- belongs_to :company
286
-
287
- amoeba do
288
- include_associations %i[addresses photos]
289
- end
290
- end
291
-
292
- class Customer < ActiveRecord::Base
293
- has_many :addresses, as: :addressable
294
- has_many :photos, as: :imageable
295
- belongs_to :company
296
-
297
- amoeba do
298
- enable
299
- end
300
- end
301
-
302
- # Remapping and Method
303
-
304
- class MetalObject < ActiveRecord::Base
305
- end
306
-
307
- class ObjectPrototype < MetalObject
308
- has_many :subobject_prototypes, foreign_key: :parent_id
309
-
310
- amoeba do
311
- enable
312
- through :become_real
313
- remapper :remap_subobjects
314
- end
315
-
316
- def become_real
317
- dup.becomes RealObject
318
- end
319
-
320
- def remap_subobjects(relation_name)
321
- :subobjects if relation_name == :subobject_prototypes
322
- end
323
- end
324
-
325
- class RealObject < MetalObject
326
- has_many :subobjects, foreign_key: :parent_id
327
- end
328
-
329
- class SubobjectPrototype < MetalObject
330
- amoeba do
331
- enable
332
- through :become_subobject
333
- end
334
-
335
- def become_subobject
336
- dup.becomes Subobject
337
- end
338
- end
339
-
340
- class Subobject < MetalObject
341
- end
342
-
343
- # Check of changing boolean attributes
344
-
345
- class SuperAdmin < ::ActiveRecord::Base
346
- amoeba do
347
- set active: false
348
- prepend password: false
349
- end
350
- end
351
-
352
- # Proper inheritance
353
-
354
- class Box < ActiveRecord::Base
355
- has_many :products, class_name: 'BoxProduct'
356
- has_many :sub_products, class_name: 'BoxSubProduct'
357
-
358
- amoeba do
359
- enable
360
- end
361
- end
362
-
363
- class BoxProduct < ActiveRecord::Base
364
- belongs_to :box, class_name: 'Box'
365
-
366
- amoeba do
367
- enable
368
- propagate
369
- end
370
- end
371
-
372
- class BoxSubProduct < BoxProduct
373
- has_one :another_product, class_name: 'BoxAnotherProduct'
374
- end
375
-
376
- class BoxSubSubProduct < BoxSubProduct
377
- end
378
-
379
- class BoxAnotherProduct < BoxProduct
380
- belongs_to :sub_product, class_name: 'BoxSubProduct'
381
- end
382
-
383
- # Inclusion inheritance
384
- class Stage < ActiveRecord::Base
385
- has_many :listeners
386
- has_many :specialists
387
-
388
- amoeba do
389
- include_association :listeners
390
- include_association :specialists
391
- nullify :external_id
392
- propagate
393
- end
394
- end
395
-
396
- class Participant < ActiveRecord::Base
397
- belongs_to :stage
398
- end
399
-
400
- class Listener < Participant
401
- end
402
-
403
- class Specialist < Participant
404
- end
405
-
406
- class CustomStage < Stage
407
- has_many :custom_rules, foreign_key: :stage_id
408
-
409
- amoeba do
410
- include_association :custom_rules
411
- end
412
- end
413
-
414
- class CustomRule < ActiveRecord::Base
415
- belongs_to :custom_stage
416
- end
@@ -1,235 +0,0 @@
1
- ActiveRecord::Schema.define do
2
- self.verbose = false
3
-
4
- create_table :topics, force: true do |t|
5
- t.string :title
6
- t.string :description
7
- t.timestamps null: true
8
- end
9
-
10
- create_table :posts, force: true do |t|
11
- t.integer :topic_id
12
- t.integer :owner_id
13
- t.integer :author_id
14
- t.string :title
15
- t.string :contents
16
- t.timestamps null: true
17
- end
18
-
19
- create_table :products, force: true do |t|
20
- t.string :type
21
- t.string :title
22
- t.decimal :price
23
- t.decimal :weight
24
- t.decimal :cost
25
- t.decimal :sleeve
26
- t.decimal :collar
27
- t.decimal :length
28
- t.string :metal
29
- end
30
-
31
- create_table :products_sections, force: true do |t|
32
- t.integer :section_id
33
- t.integer :product_id
34
- end
35
-
36
- create_table :sections, force: true do |t|
37
- t.string :name
38
- t.integer :num_employees
39
- t.decimal :total_sales
40
- end
41
-
42
- create_table :images, force: true do |t|
43
- t.string :filename
44
- t.integer :product_id
45
- end
46
-
47
- create_table :companies, force: true do |t|
48
- t.string :name
49
- end
50
-
51
- create_table :employees, force: true do |t|
52
- t.integer :company_id
53
- t.string :name
54
- t.string :ssn
55
- t.decimal :salary
56
- end
57
-
58
- create_table :customers, force: true do |t|
59
- t.integer :company_id
60
- t.string :email
61
- t.string :password
62
- t.decimal :balance
63
- end
64
-
65
- create_table :addresses, force: true do |t|
66
- t.integer :addressable_id
67
- t.string :addressable_type
68
-
69
- t.string :street
70
- t.string :unit
71
- t.string :city
72
- t.string :state
73
- t.string :zip
74
- end
75
-
76
- create_table :photos, force: true do |t|
77
- t.integer :imageable_id
78
- t.string :imageable_type
79
-
80
- t.string :name
81
- t.integer :size
82
- end
83
-
84
- create_table :post_configs, force: true do |t|
85
- t.integer :post_id
86
- t.integer :is_visible
87
- t.integer :is_open
88
- t.string :password
89
- t.timestamps null: true
90
- end
91
-
92
- create_table :comments, force: true do |t|
93
- t.integer :post_id
94
- t.string :contents
95
- t.timestamps null: true
96
- end
97
-
98
- create_table :custom_things, force: true do |t|
99
- t.integer :post_id
100
- t.string :value
101
- t.timestamps null: true
102
- end
103
-
104
- create_table :comments, force: true do |t|
105
- t.integer :post_id
106
- t.string :contents
107
- t.string :nerf
108
- t.timestamps null: true
109
- end
110
-
111
- create_table :ratings, force: true do |t|
112
- t.integer :comment_id
113
- t.string :num_stars
114
- t.timestamps null: true
115
- end
116
-
117
- create_table :tags, force: true do |t|
118
- t.string :value
119
- t.timestamps null: true
120
- end
121
-
122
- create_table :users, force: true do |t|
123
- t.integer :post_id
124
- t.string :name
125
- t.string :email
126
- t.timestamps null: true
127
- end
128
-
129
- create_table :authors, force: true do |t|
130
- t.string :full_name
131
- t.string :nickname
132
- t.timestamps null: true
133
- end
134
-
135
- create_table :posts_tags, force: true do |t|
136
- t.integer :post_id
137
- t.integer :tag_id
138
- end
139
-
140
- create_table :notes, force: true do |t|
141
- t.string :value
142
- t.timestamps null: true
143
- end
144
-
145
- create_table :notes_posts, force: true do |t|
146
- t.integer :post_id
147
- t.integer :note_id
148
- end
149
-
150
- create_table :widgets, force: true do |t|
151
- t.string :value
152
- end
153
-
154
- create_table :post_widgets, force: true do |t|
155
- t.integer :post_id
156
- t.integer :widget_id
157
- end
158
-
159
- create_table :categories, force: true do |t|
160
- t.string :title
161
- t.string :description
162
- end
163
-
164
- create_table :supercats, force: true do |t|
165
- t.integer :post_id
166
- t.integer :category_id
167
- t.string :ramblings
168
- t.string :other_ramblings
169
- t.timestamps null: true
170
- end
171
-
172
- create_table :superkittens, force: true do |t|
173
- t.integer :supercat_id
174
- t.string :value
175
- t.timestamps null: true
176
- end
177
-
178
- create_table :accounts, force: true do |t|
179
- t.integer :post_id
180
- t.string :title
181
- t.timestamps null: true
182
- end
183
-
184
- create_table :histories, force: true do |t|
185
- t.integer :account_id
186
- t.string :some_stuff
187
- t.timestamps null: true
188
- end
189
-
190
- create_table :metal_objects, force: true do |t|
191
- t.string :type
192
- t.integer :parent_id
193
- t.timestamps null: true
194
- end
195
-
196
- create_table :super_admins, force: true do |t|
197
- t.string :email
198
- t.string :password
199
- t.boolean :active, null: false, default: true
200
- t.timestamps null: true
201
- end
202
-
203
- create_table :boxes, force: true do |t|
204
- t.string :title
205
- t.timestamps null: true
206
- end
207
-
208
- create_table :box_products, force: true do |t|
209
- t.string :type
210
- t.integer :box_id
211
- t.integer :box_sub_product_id
212
- t.string :title
213
- t.timestamps null: true
214
- end
215
-
216
- create_table :stages, force: true do |t|
217
- t.string :title
218
- t.string :type
219
- t.integer :external_id
220
- t.timestamps null: true
221
- end
222
-
223
- create_table :participants, force: true do |t|
224
- t.string :name
225
- t.string :type
226
- t.integer :stage_id
227
- t.timestamps
228
- end
229
-
230
- create_table :custom_rules, force: true do |t|
231
- t.string :description
232
- t.integer :stage_id
233
- t.timestamps
234
- end
235
- end