trax_model 0.0.98 → 0.0.99

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -0
  3. data/lib/trax/model.rb +6 -16
  4. data/lib/trax/model/attributes.rb +1 -1
  5. data/lib/trax/model/attributes/definitions.rb +4 -0
  6. data/lib/trax/model/attributes/{mixin.rb → dsl.rb} +2 -12
  7. data/lib/trax/model/attributes/types/boolean.rb +1 -2
  8. data/lib/trax/model/attributes/types/enum.rb +0 -2
  9. data/lib/trax/model/attributes/types/integer.rb +2 -2
  10. data/lib/trax/model/attributes/types/set.rb +67 -0
  11. data/lib/trax/model/attributes/types/string.rb +3 -3
  12. data/lib/trax/model/attributes/types/struct.rb +5 -3
  13. data/lib/trax/model/attributes/types/uuid_array.rb +0 -2
  14. data/lib/trax/model/{sti.rb → core_extensions.rb} +2 -2
  15. data/lib/trax/model/core_extensions/string.rb +17 -0
  16. data/lib/trax/model/extensions_for.rb +18 -0
  17. data/lib/trax/model/extensions_for/base.rb +31 -0
  18. data/lib/trax/model/extensions_for/boolean.rb +29 -0
  19. data/lib/trax/model/extensions_for/enumerable.rb +18 -0
  20. data/lib/trax/model/extensions_for/integer.rb +10 -0
  21. data/lib/trax/model/extensions_for/numeric.rb +46 -0
  22. data/lib/trax/model/extensions_for/set.rb +10 -0
  23. data/lib/trax/model/extensions_for/string.rb +30 -0
  24. data/lib/trax/model/extensions_for/struct.rb +191 -0
  25. data/lib/trax/model/extensions_for/struct_fields.rb +21 -0
  26. data/lib/trax/model/extensions_for/struct_fields/boolean.rb +32 -0
  27. data/lib/trax/model/extensions_for/struct_fields/enum.rb +20 -0
  28. data/lib/trax/model/extensions_for/struct_fields/float.rb +12 -0
  29. data/lib/trax/model/extensions_for/struct_fields/integer.rb +12 -0
  30. data/lib/trax/model/extensions_for/struct_fields/numeric.rb +52 -0
  31. data/lib/trax/model/extensions_for/struct_fields/string.rb +29 -0
  32. data/lib/trax/model/extensions_for/struct_fields/time.rb +54 -0
  33. data/lib/trax/model/matchable.rb +3 -10
  34. data/lib/trax/model/mixins.rb +3 -0
  35. data/lib/trax/model/mixins/freezable.rb +31 -0
  36. data/lib/trax/model/mixins/restorable.rb +63 -0
  37. data/lib/trax/model/mixins/sti_enum.rb +4 -5
  38. data/lib/trax/model/mixins/unique_id.rb +85 -0
  39. data/lib/trax/model/railtie.rb +4 -2
  40. data/lib/trax/validators/json_attribute_validator.rb +1 -0
  41. data/lib/trax_model/version.rb +1 -1
  42. data/spec/db/schema/default_tables.rb +1 -17
  43. data/spec/db/schema/pg_tables.rb +15 -0
  44. data/spec/support/models.rb +11 -16
  45. data/spec/support/pg/models.rb +31 -6
  46. data/spec/trax/model/attributes/types/set_spec.rb +68 -0
  47. data/spec/trax/model/attributes/types/struct_spec.rb +6 -0
  48. data/spec/trax/model/extensions_for/boolean_spec.rb +26 -0
  49. data/spec/trax/model/extensions_for/numeric_spec.rb +53 -0
  50. data/spec/trax/model/extensions_for/string_spec.rb +25 -0
  51. data/spec/trax/model/extensions_for/struct_spec.rb +223 -0
  52. data/spec/trax/model/extensions_for_spec.rb +0 -0
  53. data/spec/trax/model/{freezable_spec.rb → mixins/freezable_spec.rb} +1 -1
  54. data/spec/trax/model/{restorable_spec.rb → mixins/restorable_spec.rb} +1 -1
  55. data/spec/trax/model/{unique_id_spec.rb → mixins/unique_id_spec.rb} +1 -1
  56. data/trax_model.gemspec +4 -5
  57. metadata +49 -59
  58. data/lib/trax/model/enum.rb +0 -64
  59. data/lib/trax/model/freezable.rb +0 -29
  60. data/lib/trax/model/mti.rb +0 -11
  61. data/lib/trax/model/mti/abstract.rb +0 -65
  62. data/lib/trax/model/mti/entity.rb +0 -62
  63. data/lib/trax/model/mti/namespace.rb +0 -21
  64. data/lib/trax/model/restorable.rb +0 -61
  65. data/lib/trax/model/scopes.rb +0 -16
  66. data/lib/trax/model/sti/attributes.rb +0 -94
  67. data/lib/trax/model/string_extensions.rb +0 -11
  68. data/lib/trax/model/struct_extensions.rb +0 -185
  69. data/lib/trax/model/unique_id.rb +0 -83
  70. data/spec/trax/model/sti/attributes_spec.rb +0 -15
  71. data/spec/trax/model/struct_extensions_spec.rb +0 -16
File without changes
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe ::Trax::Model::Freezable do
3
+ describe ::Trax::Model::Mixins::Freezable do
4
4
  subject{ ::Message.create(:title => "Whatever") }
5
5
 
6
6
  its(:status) { should eq "queued" }
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe ::Trax::Model::Restorable do
3
+ describe ::Trax::Model::Mixins::Restorable do
4
4
  subject{ ::Message.create(:title => "Whatever") }
5
5
 
6
6
  its(:deleted) { should be false }
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
- describe ::Trax::Model::UniqueId do
2
+ describe ::Trax::Model::Mixins::UniqueId do
3
3
  subject{ ::Product }
4
4
 
5
5
  its(:uuid_prefix) { should be_instance_of(::Trax::Model::UUIDPrefix) }
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.version = TraxModel::VERSION
9
9
  spec.authors = ["Jason Ayre"]
10
10
  spec.email = ["jasonayre@gmail.com"]
11
- spec.summary = %q{Higher level ActiveRecord models for rails}
12
- spec.description = %q{Supports uuid defaults and mapping, default attributes, and various other utilities via composition}
11
+ spec.summary = %q{Better ActiveRecord attributes, conventions, utilities}
12
+ spec.description = %q{ActiveRecord attributes DDL, struct/array attribute types, an enum implementation that doesn't suck, etc..}
13
13
  spec.homepage = "http://github.com/jasonayre/trax_model"
14
14
  spec.license = "MIT"
15
15
 
@@ -18,10 +18,9 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "trax_core", "~> 0.0.83"
21
+ spec.add_dependency "trax_core", "~> 0.0.84"
22
22
  spec.add_dependency "default_value_for", "~> 3.0.0"
23
- spec.add_dependency "simple_enum"
24
- spec.add_development_dependency "hashie", ">= 3.4.2"
23
+ # spec.add_development_dependency "hashie", ">= 3.4.4"
25
24
  spec.add_development_dependency "rails", "~> 4.2.0"
26
25
  spec.add_development_dependency "activerecord", "~> 4.2.0"
27
26
  spec.add_development_dependency "bundler", "~> 1.6"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trax_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.98
4
+ version: 0.0.99
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Ayre
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-17 00:00:00.000000000 Z
11
+ date: 2016-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: trax_core
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.0.83
19
+ version: 0.0.84
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.0.83
26
+ version: 0.0.84
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: default_value_for
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -38,34 +38,6 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 3.0.0
41
- - !ruby/object:Gem::Dependency
42
- name: simple_enum
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: hashie
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: 3.4.2
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: 3.4.2
69
41
  - !ruby/object:Gem::Dependency
70
42
  name: rails
71
43
  requirement: !ruby/object:Gem::Requirement
@@ -304,8 +276,8 @@ dependencies:
304
276
  - - ">="
305
277
  - !ruby/object:Gem::Version
306
278
  version: '0'
307
- description: Supports uuid defaults and mapping, default attributes, and various other
308
- utilities via composition
279
+ description: ActiveRecord attributes DDL, struct/array attribute types, an enum implementation
280
+ that doesn't suck, etc..
309
281
  email:
310
282
  - jasonayre@gmail.com
311
283
  executables: []
@@ -325,42 +297,52 @@ files:
325
297
  - lib/trax/model/attributes.rb
326
298
  - lib/trax/model/attributes/attribute.rb
327
299
  - lib/trax/model/attributes/definitions.rb
300
+ - lib/trax/model/attributes/dsl.rb
328
301
  - lib/trax/model/attributes/errors.rb
329
302
  - lib/trax/model/attributes/fields.rb
330
- - lib/trax/model/attributes/mixin.rb
331
303
  - lib/trax/model/attributes/type.rb
332
304
  - lib/trax/model/attributes/types.rb
333
305
  - lib/trax/model/attributes/types/array.rb
334
306
  - lib/trax/model/attributes/types/boolean.rb
335
307
  - lib/trax/model/attributes/types/enum.rb
336
308
  - lib/trax/model/attributes/types/integer.rb
309
+ - lib/trax/model/attributes/types/set.rb
337
310
  - lib/trax/model/attributes/types/string.rb
338
311
  - lib/trax/model/attributes/types/struct.rb
339
312
  - lib/trax/model/attributes/types/uuid_array.rb
340
313
  - lib/trax/model/attributes/value.rb
341
- - lib/trax/model/enum.rb
314
+ - lib/trax/model/core_extensions.rb
315
+ - lib/trax/model/core_extensions/string.rb
342
316
  - lib/trax/model/errors.rb
343
- - lib/trax/model/freezable.rb
317
+ - lib/trax/model/extensions_for.rb
318
+ - lib/trax/model/extensions_for/base.rb
319
+ - lib/trax/model/extensions_for/boolean.rb
320
+ - lib/trax/model/extensions_for/enumerable.rb
321
+ - lib/trax/model/extensions_for/integer.rb
322
+ - lib/trax/model/extensions_for/numeric.rb
323
+ - lib/trax/model/extensions_for/set.rb
324
+ - lib/trax/model/extensions_for/string.rb
325
+ - lib/trax/model/extensions_for/struct.rb
326
+ - lib/trax/model/extensions_for/struct_fields.rb
327
+ - lib/trax/model/extensions_for/struct_fields/boolean.rb
328
+ - lib/trax/model/extensions_for/struct_fields/enum.rb
329
+ - lib/trax/model/extensions_for/struct_fields/float.rb
330
+ - lib/trax/model/extensions_for/struct_fields/integer.rb
331
+ - lib/trax/model/extensions_for/struct_fields/numeric.rb
332
+ - lib/trax/model/extensions_for/struct_fields/string.rb
333
+ - lib/trax/model/extensions_for/struct_fields/time.rb
344
334
  - lib/trax/model/matchable.rb
345
335
  - lib/trax/model/mixin.rb
346
336
  - lib/trax/model/mixins.rb
347
337
  - lib/trax/model/mixins/field_scopes.rb
338
+ - lib/trax/model/mixins/freezable.rb
348
339
  - lib/trax/model/mixins/id_scopes.rb
340
+ - lib/trax/model/mixins/restorable.rb
349
341
  - lib/trax/model/mixins/sort_by_scopes.rb
350
342
  - lib/trax/model/mixins/sti_enum.rb
351
- - lib/trax/model/mti.rb
352
- - lib/trax/model/mti/abstract.rb
353
- - lib/trax/model/mti/entity.rb
354
- - lib/trax/model/mti/namespace.rb
343
+ - lib/trax/model/mixins/unique_id.rb
355
344
  - lib/trax/model/railtie.rb
356
345
  - lib/trax/model/registry.rb
357
- - lib/trax/model/restorable.rb
358
- - lib/trax/model/scopes.rb
359
- - lib/trax/model/sti.rb
360
- - lib/trax/model/sti/attributes.rb
361
- - lib/trax/model/string_extensions.rb
362
- - lib/trax/model/struct_extensions.rb
363
- - lib/trax/model/unique_id.rb
364
346
  - lib/trax/model/uuid.rb
365
347
  - lib/trax/model/uuid_array.rb
366
348
  - lib/trax/model/uuid_prefix.rb
@@ -384,18 +366,22 @@ files:
384
366
  - spec/trax/model/attributes/fields_spec.rb
385
367
  - spec/trax/model/attributes/types/enum_spec.rb
386
368
  - spec/trax/model/attributes/types/integer_spec.rb
369
+ - spec/trax/model/attributes/types/set_spec.rb
387
370
  - spec/trax/model/attributes/types/struct_spec.rb
388
371
  - spec/trax/model/attributes_spec.rb
389
372
  - spec/trax/model/errors_spec.rb
390
- - spec/trax/model/freezable_spec.rb
373
+ - spec/trax/model/extensions_for/boolean_spec.rb
374
+ - spec/trax/model/extensions_for/numeric_spec.rb
375
+ - spec/trax/model/extensions_for/string_spec.rb
376
+ - spec/trax/model/extensions_for/struct_spec.rb
377
+ - spec/trax/model/extensions_for_spec.rb
391
378
  - spec/trax/model/matchable_spec.rb
392
379
  - spec/trax/model/mixins/field_scopes_spec.rb
380
+ - spec/trax/model/mixins/freezable_spec.rb
381
+ - spec/trax/model/mixins/restorable_spec.rb
393
382
  - spec/trax/model/mixins/sti_enum_spec.rb
383
+ - spec/trax/model/mixins/unique_id_spec.rb
394
384
  - spec/trax/model/registry_spec.rb
395
- - spec/trax/model/restorable_spec.rb
396
- - spec/trax/model/sti/attributes_spec.rb
397
- - spec/trax/model/struct_extensions_spec.rb
398
- - spec/trax/model/unique_id_spec.rb
399
385
  - spec/trax/model/uuid_prefix_spec.rb
400
386
  - spec/trax/model/uuid_spec.rb
401
387
  - spec/trax/model_spec.rb
@@ -428,7 +414,7 @@ rubyforge_project:
428
414
  rubygems_version: 2.4.5
429
415
  signing_key:
430
416
  specification_version: 4
431
- summary: Higher level ActiveRecord models for rails
417
+ summary: Better ActiveRecord attributes, conventions, utilities
432
418
  test_files:
433
419
  - spec/db/database.yml
434
420
  - spec/db/schema/default_tables.rb
@@ -439,18 +425,22 @@ test_files:
439
425
  - spec/trax/model/attributes/fields_spec.rb
440
426
  - spec/trax/model/attributes/types/enum_spec.rb
441
427
  - spec/trax/model/attributes/types/integer_spec.rb
428
+ - spec/trax/model/attributes/types/set_spec.rb
442
429
  - spec/trax/model/attributes/types/struct_spec.rb
443
430
  - spec/trax/model/attributes_spec.rb
444
431
  - spec/trax/model/errors_spec.rb
445
- - spec/trax/model/freezable_spec.rb
432
+ - spec/trax/model/extensions_for/boolean_spec.rb
433
+ - spec/trax/model/extensions_for/numeric_spec.rb
434
+ - spec/trax/model/extensions_for/string_spec.rb
435
+ - spec/trax/model/extensions_for/struct_spec.rb
436
+ - spec/trax/model/extensions_for_spec.rb
446
437
  - spec/trax/model/matchable_spec.rb
447
438
  - spec/trax/model/mixins/field_scopes_spec.rb
439
+ - spec/trax/model/mixins/freezable_spec.rb
440
+ - spec/trax/model/mixins/restorable_spec.rb
448
441
  - spec/trax/model/mixins/sti_enum_spec.rb
442
+ - spec/trax/model/mixins/unique_id_spec.rb
449
443
  - spec/trax/model/registry_spec.rb
450
- - spec/trax/model/restorable_spec.rb
451
- - spec/trax/model/sti/attributes_spec.rb
452
- - spec/trax/model/struct_extensions_spec.rb
453
- - spec/trax/model/unique_id_spec.rb
454
444
  - spec/trax/model/uuid_prefix_spec.rb
455
445
  - spec/trax/model/uuid_spec.rb
456
446
  - spec/trax/model_spec.rb
@@ -1,64 +0,0 @@
1
- # An opinionated enum preconfiguration:
2
- # Uses simple_enum instead of active record built in enum, due to the complete
3
- # and utter polution it causes to your classes. in addition, AR does not prefix
4
- # enums with anything, i.e.
5
- # class User
6
- # enum :gender => [:unknown, :male, :female]
7
- # enum :locale => [:unknown, :en, :ca]
8
- # will break because :unknown cant be used twice, since it defines an User.unknown
9
- # method, the value which does not even make sense in alot of situations, out of context
10
- #
11
- # So, we use simple_enum instead, which will allow us to do that
12
- # in addition, I dont like that simple_enum does not allow you to raise errrors at the activerecord
13
- # level using validations, therefore you cant reuse the same interface for displaying errors
14
- # to the user if an invalid value is picked
15
- # so validation is added when an enum is defined
16
- # also defines just 2 generic scopes, by_enum_name, and by_enum_name_not, which accept multiple args
17
- # i.e. by_gender(:male), by_gender_not(:female, :unknown)
18
- # in interest of not polluting the class with scopes for each individual enum value
19
-
20
- module Trax
21
- module Model
22
- module Enum
23
- extend ::Trax::Model::Mixin
24
-
25
- module ClassMethods
26
- def define_scopes_for_trax_enum(enum_name)
27
- scope_method_name = :"by_#{enum_name}"
28
- scope_not_method_name = :"by_#{enum_name}_not"
29
-
30
- self.scope scope_method_name, lambda { |*values|
31
- enum_hash = self.__send__("#{enum_name}".pluralize).hash
32
- where(enum_name => enum_hash.with_indifferent_access.slice(*values.flatten.compact.uniq).values)
33
- }
34
- self.scope scope_not_method_name, lambda { |*values|
35
- enum_hash = self.__send__("#{enum_name}".pluralize).hash
36
- where.not(enum_name => enum_hash.with_indifferent_access.slice(*values.flatten.compact.uniq).values)
37
- }
38
- end
39
-
40
- #todo: ew need to clean this up
41
- def as_enum(enum_name, enum_mapping, options = {})
42
- enum_values = enum_mapping.is_a?(Hash) ? enum_mapping.keys : enum_mapping
43
- options.assert_valid_keys(:prefix, :source, :message, :default, :validate)
44
-
45
- options[:message] ||= "Invalid value selected for #{enum_name}"
46
- options[:prefix] ||= true
47
- options[:source] ||= enum_name
48
- default_value = options.extract!(:default)[:default] if options.key?(:default)
49
-
50
- validation_options = { :in => enum_values, :message => options.extract!(:message)[:message] }
51
-
52
- self.validates_inclusion_of(enum_name, validation_options) unless options.key?(:validate) && !options[:validate]
53
-
54
- options.delete(:validate) if options.key?(:validate)
55
-
56
- define_scopes_for_trax_enum(enum_name)
57
-
58
- super(enum_name, enum_mapping, options)
59
- self.default_value_for(enum_name) { default_value } if default_value
60
- end
61
- end
62
- end
63
- end
64
- end
@@ -1,29 +0,0 @@
1
- module Trax
2
- module Model
3
- module Freezable
4
- extend ::Trax::Model::Mixin
5
-
6
- included do
7
- class_attribute :freezable_fields
8
- self.freezable_fields = ::ActiveSupport::OrderedOptions.new
9
- end
10
-
11
- module ClassMethods
12
- def freezable_by_enum(options = {})
13
- freezable_fields.merge!(options)
14
- define_frozen_validators_for_enum(options)
15
- end
16
-
17
- def define_frozen_validators_for_enum(options)
18
- self.class_eval do
19
- options.each_pair do |enum_method, frozen_states|
20
- validates_with ::FrozenValidator, :if => lambda { |record|
21
- frozen_states.any?{ |state| state == :"#{record.send(enum_method)}" } && !record.changed.include?("#{enum_method}")
22
- }
23
- end
24
- end
25
- end
26
- end
27
- end
28
- end
29
- end
@@ -1,11 +0,0 @@
1
- module Trax
2
- module Model
3
- module MTI
4
- extend ::ActiveSupport::Autoload
5
-
6
- autoload :Abstract
7
- autoload :Entity
8
- autoload :Namespace
9
- end
10
- end
11
- end
@@ -1,65 +0,0 @@
1
- module Trax
2
- module Model
3
- module MTI
4
- module Abstract
5
- extend ::ActiveSupport::Concern
6
-
7
- included do
8
- class_attribute :mti_config
9
-
10
- self.abstract_class = true
11
- self.mti_config = ::ActiveSupport::HashWithIndifferentAccess.new({
12
- :foreign_key => :id
13
- })
14
-
15
- scope :records, lambda{
16
- map(&:entity)
17
- }
18
- end
19
-
20
- module ClassMethods
21
- def inherited(subklass)
22
- super(subklass)
23
-
24
- subklass.after_create do |record|
25
- entity_model = mti_config[:class_name].constantize.new
26
-
27
- record.attributes.each_pair do |k,v|
28
- entity_model.__send__("#{k}=", v) if entity_model.respond_to?(k)
29
- end
30
-
31
- entity_model.save
32
- end
33
-
34
- subklass.after_update do |record|
35
- entity_model = record.entity
36
-
37
- if record.changed.any?
38
- record.changes.each_pair do |k,v|
39
- entity_model.__send__("#{k}=", v[1]) if entity.respond_to?(:"#{k}")
40
- end
41
- end
42
-
43
- entity_model.save if entity_model.changed.any?
44
- end
45
-
46
- subklass.after_destroy do |record|
47
- entity_model = record.entity
48
-
49
- entity_model.destroy
50
- end
51
- end
52
-
53
- def entity_model(options)
54
- valid_options = options.assert_valid_keys(:class_name, :foreign_key)
55
-
56
- mti_config.merge!(valid_options)
57
-
58
- self.has_one(:entity, mti_config.symbolize_keys)
59
- self.accepts_nested_attributes_for(:entity)
60
- end
61
- end
62
- end
63
- end
64
- end
65
- end
@@ -1,62 +0,0 @@
1
- module Trax
2
- module Model
3
- module MTI
4
- module Entity
5
- extend ::ActiveSupport::Concern
6
-
7
- included do
8
- class_attribute :_mti_namespace
9
-
10
- scope :records, lambda{
11
- map(&:entity)
12
- }
13
-
14
- scope :fully_loaded, lambda{
15
- relation = current_scope.dup
16
- entity_ids = relation.pluck(:id)
17
- entity_types = entity_ids.map { |id| ::Trax::Model::UUID.new(id[0..1]) }
18
- .map(&:record_type)
19
- .flatten
20
- .compact
21
- .uniq
22
-
23
- relation_names = entity_types.map{ |type| :"#{type.name.demodulize.underscore}_entity" }
24
-
25
- current_scope.includes(relation_names).references(relation_names)
26
- }
27
- end
28
-
29
- def model_type
30
- @model_type ||= uuid.record_type
31
- end
32
-
33
- def model_type_key
34
- :"#{model_type.name.demodulize.underscore}_entity"
35
- end
36
-
37
- def model
38
- @model ||= __send__(model_type_key)
39
- end
40
-
41
- def uuid
42
- @uuid ||= self[:id].uuid
43
- end
44
-
45
- module ClassMethods
46
- def mti_namespace(namespace)
47
- _mti_namespace = (namespace.is_a?(String)) ? namespace.constantize : namespace
48
-
49
- _mti_namespace.all.reject{|model| model.abstract_class }.each do |subclass|
50
- key = :"#{subclass.name.demodulize.underscore}_entity"
51
- has_one key, :class_name => subclass.name, :foreign_key => :id
52
- end
53
- end
54
-
55
- def multiple_table_inheritance_namespace(namespace)
56
- mti_namespace(namespace)
57
- end
58
- end
59
- end
60
- end
61
- end
62
- end