amoeba 3.0.0 → 3.1.0

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,3 +1,4 @@
1
+
1
2
  u1 = User.create(name: 'Robert Johnson', email: 'bob@crossroads.com')
2
3
  u2 = User.create(name: 'Miles Davis', email: 'miles@kindofblue.com')
3
4
 
@@ -12,54 +13,20 @@ f1 = p1.create_post_config(is_visible: true, is_open: false, password: 'abcdefg1
12
13
  a1 = p1.create_account(title: 'Foo')
13
14
  h1 = p1.account.create_history(some_stuff: 'Bar')
14
15
  c1 = p1.comments.create(contents: 'I love it!', nerf: 'ratatat')
15
- c1.ratings.create(num_stars: 5)
16
- c1.ratings.create(num_stars: 5)
17
- c1.ratings.create(num_stars: 4)
18
- c1.ratings.create(num_stars: 3)
19
- c1.ratings.create(num_stars: 5)
20
- c1.ratings.create(num_stars: 5)
16
+ [5, 5, 4, 3, 5, 5].each { |stars| c1.ratings.create(num_stars: stars) }
21
17
 
22
18
  c2 = p1.comments.create(contents: 'I hate it!', nerf: 'whapaow')
23
- c2.ratings.create(num_stars: 3)
24
- c2.ratings.create(num_stars: 1)
25
- c2.ratings.create(num_stars: 4)
26
- c2.ratings.create(num_stars: 1)
27
- c2.ratings.create(num_stars: 1)
28
- c2.ratings.create(num_stars: 2)
19
+ [3, 1, 4, 1, 1, 2].each { |stars| c2.ratings.create(num_stars: stars) }
29
20
 
30
21
  c3 = p1.comments.create(contents: 'kthxbbq!!11!!!1!eleven!!', nerf: 'bonk')
31
- c3.ratings.create(num_stars: 0)
32
- c3.ratings.create(num_stars: 0)
33
- c3.ratings.create(num_stars: 1)
34
- c3.ratings.create(num_stars: 2)
35
- c3.ratings.create(num_stars: 1)
36
- c3.ratings.create(num_stars: 0)
37
-
38
- t1 = Tag.create(value: 'funny')
39
- t2 = Tag.create(value: 'wtf')
40
- t3 = Tag.create(value: 'cats')
41
-
42
- p1.tags << t1
43
- p1.tags << t2
44
- p1.tags << t3
45
- p1.save
22
+ [0, 0, 1, 2, 1, 0].each { |stars| c3.ratings.create(num_stars: stars) }
46
23
 
47
- w1 = Widget.create(value: 'My Sidebar')
48
- w2 = Widget.create(value: 'Photo Gallery')
49
- w3 = Widget.create(value: 'Share & Like')
24
+ %w(funny wtf cats).each { |value| p1.tags << Tag.create(value: value) }
50
25
 
51
- p1.widgets << w1
52
- p1.widgets << w2
53
- p1.widgets << w3
54
- p1.save
26
+ ['My Sidebar', 'Photo Gallery', 'Share & Like'].each { |value| p1.widgets << Widget.create(value: value) }
55
27
 
56
- n1 = Note.create(value: 'This is important')
57
- n2 = Note.create(value: "You've been warned")
58
- n3 = Note.create(value: "Don't forget")
28
+ ['This is important', "You've been warned", "Don't forget"].each { |value| p1.notes << Note.create(value: value) }
59
29
 
60
- p1.notes << n1
61
- p1.notes << n2
62
- p1.notes << n3
63
30
  p1.save
64
31
 
65
32
  c1 = Category.create(title: 'Umbrellas', description: 'Clown fart')
@@ -117,4 +84,16 @@ shirt1.save
117
84
  necklace1.sections << jewelry
118
85
  necklace1.sections << accessories
119
86
  necklace1.save
87
+
88
+
89
+ company = Company.create(name:'ABC Industries')
90
+ employee = company.employees.create(name:'Joe',ssn:'1111111111',salary:10000.0)
91
+ employee_address = employee.addresses.create(street: '123 My Street',unit:'103',city:'Hollywood',state:'CA',zip:'90210')
92
+ employee_address_2 = employee.addresses.create(street: '124 My Street',unit:'103',city:'Follywood',state:'CA',zip:'90210')
93
+ employee_photo = employee.photos.create(name: 'Portrait', size: 12345)
94
+ customer = company.customers.create(email:'my@email.address',password:'password')
95
+ customer_address = customer.addresses.create(street: '321 My Street',unit:'301',city:'Bollywood',state:'IN',zip:'11111')
96
+ customer_address_2 = customer.addresses.create(street: '321 My Drive',unit:'311',city:'Mollywood',state:'IN',zip:'21111')
97
+ customer_photo = customer.photos.create(name: 'Mug Shot', size: 54321)
98
+
120
99
  # }}}
@@ -70,24 +70,38 @@ class Post < ActiveRecord::Base
70
70
  end
71
71
  ])
72
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
73
91
  end
74
92
 
75
93
  class CustomThing < ActiveRecord::Base
76
94
  belongs_to :post
95
+
77
96
  class ArrayPack
78
97
  def self.load(str)
79
- unless str.present? && str.length > 0
80
- return []
81
- end
82
- if str.is_a?(Array)
83
- return str
84
- end
98
+ return [] unless str.present?
99
+ return str if str.is_a?(Array)
85
100
  str.split(',').map(&:to_i)
86
101
  end
102
+
87
103
  def self.dump(int_array)
88
- unless int_array.present? && int_array.length > 0
89
- return ''
90
- end
104
+ return '' unless int_array.present?
91
105
  int_array.join(',')
92
106
  end
93
107
  end
@@ -95,6 +109,7 @@ class CustomThing < ActiveRecord::Base
95
109
  serialize :value, ArrayPack
96
110
 
97
111
  before_create :hydrate_me
112
+
98
113
  def hydrate_me
99
114
  self.value = value
100
115
  end
@@ -185,10 +200,16 @@ class Product < ActiveRecord::Base
185
200
  has_many :images
186
201
  has_and_belongs_to_many :sections
187
202
 
203
+ SECTION_COUNT_QUERY = 'SELECT COUNT(*) AS section_count FROM products_sections WHERE product_id = ?'.freeze
204
+
188
205
  amoeba do
189
206
  enable
190
207
  propagate
191
208
  end
209
+
210
+ def section_count
211
+ ActiveRecord::Base.connection.select_one(SECTION_COUNT_QUERY, id)['section_count']
212
+ end
192
213
  end
193
214
 
194
215
  class Section < ActiveRecord::Base
@@ -230,14 +251,51 @@ end
230
251
  # Polymorphism
231
252
  class Address < ActiveRecord::Base
232
253
  belongs_to :addressable, polymorphic: true
254
+
255
+ amoeba do
256
+ enable
257
+ end
258
+ end
259
+
260
+ class Photo < ActiveRecord::Base
261
+ belongs_to :imageable, polymorphic: true
262
+
263
+ amoeba do
264
+ customize(lambda { |original_photo,new_photo|
265
+ new_photo.name = original_photo.name.to_s + ' Copy'
266
+ })
267
+ end
268
+ end
269
+
270
+ class Company < ActiveRecord::Base
271
+ has_many :employees
272
+ has_many :customers
273
+
274
+ amoeba do
275
+ include_associations :employees,
276
+ :customers
277
+ end
233
278
  end
234
279
 
235
280
  class Employee < ActiveRecord::Base
236
281
  has_many :addresses, as: :addressable
282
+ has_many :photos, as: :imageable
283
+ belongs_to :company
284
+
285
+ amoeba do
286
+ include_associations [:addresses, :photos]
287
+ end
288
+
237
289
  end
238
290
 
239
291
  class Customer < ActiveRecord::Base
240
292
  has_many :addresses, as: :addressable
293
+ has_many :photos, as: :imageable
294
+ belongs_to :company
295
+
296
+ amoeba do
297
+ enable
298
+ end
241
299
  end
242
300
 
243
301
  # Remapping and Method
@@ -258,7 +316,7 @@ class ObjectPrototype < MetalObject
258
316
  self.dup.becomes RealObject
259
317
  end
260
318
 
261
- def remap_subobjects( relation_name )
319
+ def remap_subobjects(relation_name)
262
320
  :subobjects if relation_name == :subobject_prototypes
263
321
  end
264
322
  end
@@ -268,7 +326,6 @@ class RealObject < MetalObject
268
326
  end
269
327
 
270
328
  class SubobjectPrototype < MetalObject
271
-
272
329
  amoeba do
273
330
  enable
274
331
  through :become_subobject
@@ -285,7 +342,6 @@ end
285
342
  # Check of changing boolean attributes
286
343
 
287
344
  class SuperAdmin < ::ActiveRecord::Base
288
-
289
345
  amoeba do
290
346
  set active: false
291
347
  prepend password: false
@@ -295,25 +351,21 @@ end
295
351
  # Proper inheritance
296
352
 
297
353
  class Box < ActiveRecord::Base
298
-
299
354
  has_many :products, class_name: 'BoxProduct'
300
355
  has_many :sub_products, class_name: 'BoxSubProduct'
301
356
 
302
357
  amoeba do
303
358
  enable
304
359
  end
305
-
306
360
  end
307
361
 
308
362
  class BoxProduct < ActiveRecord::Base
309
-
310
363
  belongs_to :box, class_name: 'Box'
311
364
 
312
365
  amoeba do
313
366
  enable
314
367
  propagate
315
368
  end
316
-
317
369
  end
318
370
 
319
371
  class BoxSubProduct < BoxProduct
@@ -325,4 +377,39 @@ end
325
377
 
326
378
  class BoxAnotherProduct < BoxProduct
327
379
  belongs_to :sub_product, class_name: 'BoxSubProduct'
328
- end
380
+ end
381
+
382
+ # Inclusion inheritance
383
+ class Stage < ActiveRecord::Base
384
+ has_many :listeners
385
+ has_many :specialists
386
+
387
+ amoeba do
388
+ include_association :listeners
389
+ include_association :specialists
390
+ nullify :external_id
391
+ propagate
392
+ end
393
+ end
394
+
395
+ class Participant < ActiveRecord::Base
396
+ belongs_to :stage
397
+ end
398
+
399
+ class Listener < Participant
400
+ end
401
+
402
+ class Specialist < Participant
403
+ end
404
+
405
+ class CustomStage < Stage
406
+ has_many :custom_rules, foreign_key: :stage_id
407
+
408
+ amoeba do
409
+ include_association :custom_rules
410
+ end
411
+ end
412
+
413
+ class CustomRule < ActiveRecord::Base
414
+ belongs_to :custom_stage
415
+ end
@@ -44,13 +44,19 @@ ActiveRecord::Schema.define do
44
44
  t.integer :product_id
45
45
  end
46
46
 
47
+ create_table :companies, force: true do |t|
48
+ t.string :name
49
+ end
50
+
47
51
  create_table :employees, force: true do |t|
52
+ t.integer :company_id
48
53
  t.string :name
49
54
  t.string :ssn
50
55
  t.decimal :salary
51
56
  end
52
57
 
53
58
  create_table :customers, force: true do |t|
59
+ t.integer :company_id
54
60
  t.string :email
55
61
  t.string :password
56
62
  t.decimal :balance
@@ -67,6 +73,14 @@ ActiveRecord::Schema.define do
67
73
  t.string :zip
68
74
  end
69
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
+
70
84
  create_table :post_configs, force: true do |t|
71
85
  t.integer :post_id
72
86
  t.integer :is_visible
@@ -199,4 +213,23 @@ ActiveRecord::Schema.define do
199
213
  t.timestamps null: true
200
214
  end
201
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
202
235
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amoeba
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vaughn Draughon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-07 00:00:00.000000000 Z
11
+ date: 2017-04-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -86,7 +86,6 @@ files:
86
86
  - Rakefile
87
87
  - amoeba.gemspec
88
88
  - defaults.reek
89
- - gemfiles/activerecord_3.2.gemfile
90
89
  - gemfiles/activerecord_4.0.gemfile
91
90
  - gemfiles/activerecord_4.1.gemfile
92
91
  - gemfiles/activerecord_4.2.gemfile
@@ -127,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
126
  version: '0'
128
127
  requirements: []
129
128
  rubyforge_project: amoeba
130
- rubygems_version: 2.4.3
129
+ rubygems_version: 2.5.1
131
130
  signing_key:
132
131
  specification_version: 4
133
132
  summary: Easy copying of rails models and their child associations.
@@ -1,17 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "~> 3.2.0"
6
-
7
- group :development, :test do
8
- gem "rake"
9
- gem "coveralls", :require => false
10
- end
11
-
12
- group :local_development do
13
- gem "pry"
14
- gem "appraisal"
15
- end
16
-
17
- gemspec :path => "../"