active_data 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a7a72a84858d1c5737ed98029682614052de1281e89d617d934a5ab7e16cd93c
4
- data.tar.gz: ca64b3895dd8bbdd4503e8a8425aef4c210e0fb33f15f456bfe69d25fe741776
3
+ metadata.gz: aec99c84b95cc5a79feaf4230cdbf4eb89780afc910bf03278d5f2377a48b0c5
4
+ data.tar.gz: 71941c2fd303ccca637d7f58646dc5a3e3417f506e8cee405a57649a3c770d6c
5
5
  SHA512:
6
- metadata.gz: 18452047bf27f1a2ea4b2428ebc0e887bce1fb03bbed3dc44a0e2867ad761dca984a828796cd4691b9c6a5240f432cfe4f6c79ff20197be044cd30971db84a41
7
- data.tar.gz: 9f11d63a14102cee31677b9a97bdda8ff90f734ca3d18d3473ee0fee9da2ae8a61c08e240e4697d4eb86d55f5b56b79412438eeb92fd7f8197098510f2969882
6
+ metadata.gz: 3603d8b5de895f35f5c19db31a1de8fa71853595a0d93cf772c2894ff0a89fec0afb1d3b3c6f56b8d410ea22339f5e9abe96ca1023a1b414b720f1526afcc09e
7
+ data.tar.gz: 35a90113764e1a5125d8cd205036e804e9dbfe7e2cb1ffdd812d6b99a5b0233c7efebafaab8452ef12d89c1a78f3d8ee212b55dd5ad59bbc8b399e80c256cbc8
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # master
2
2
 
3
+ # Version 1.1.2
4
+
5
+ ## Changes
6
+
7
+ * `ActiveData.base_concern` config option in addition to `ActiveData.base_class` (#64)
8
+
3
9
  # Version 1.1.1
4
10
 
5
11
  ## Changes
@@ -2,7 +2,7 @@ module ActiveData
2
2
  class Config
3
3
  include Singleton
4
4
 
5
- attr_accessor :include_root_in_json, :i18n_scope, :logger, :primary_attribute, :base_class,
5
+ attr_accessor :include_root_in_json, :i18n_scope, :logger, :primary_attribute, :base_class, :base_concern,
6
6
  :_normalizers, :_typecasters
7
7
 
8
8
  def self.delegated
@@ -3,22 +3,29 @@ module ActiveData
3
3
  module Associations
4
4
  module Reflections
5
5
  class EmbedsAny < Base
6
- def self.build(target, generated_methods, name, options = {}, &block)
7
- if block
8
- options[:class] = proc do |reflection|
9
- superclass = reflection.options[:class_name].to_s.presence.try(:constantize)
10
- klass = Class.new(superclass || ActiveData.base_class) do
11
- include ActiveData::Model
12
- include ActiveData::Model::Associations
13
- include ActiveData::Model::Lifecycle
14
- include ActiveData::Model::Primary
6
+ class << self
7
+ def build(target, generated_methods, name, options = {}, &block)
8
+ if block
9
+ options[:class] = proc do |reflection|
10
+ superclass = reflection.options[:class_name].to_s.presence.try(:constantize)
11
+ klass = build_class(superclass)
12
+ target.const_set(name.to_s.classify, klass)
13
+ klass.class_eval(&block)
14
+ klass
15
15
  end
16
- target.const_set(name.to_s.classify, klass)
17
- klass.class_eval(&block)
18
- klass
16
+ end
17
+ super
18
+ end
19
+
20
+ private def build_class(superclass)
21
+ Class.new(superclass || ActiveData.base_class) do
22
+ include ActiveData::Model
23
+ include ActiveData::Model::Associations
24
+ include ActiveData::Model::Lifecycle
25
+ include ActiveData::Model::Primary
26
+ include ActiveData.base_concern if ActiveData.base_concern
19
27
  end
20
28
  end
21
- super
22
29
  end
23
30
 
24
31
  def klass
@@ -1,3 +1,3 @@
1
1
  module ActiveData
2
- VERSION = '1.1.1'.freeze
2
+ VERSION = '1.1.2'.freeze
3
3
  end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+ require 'active_data/base'
3
+
4
+ describe ActiveData::Model::Associations::Reflections::EmbedsAny do
5
+ describe '#build' do
6
+ subject { described_class.build(User, User, :projects) {}.klass.new }
7
+
8
+ before do
9
+ stub_model(:project) do
10
+ include ActiveData::Model::Lifecycle
11
+ attribute :title, String
12
+ end
13
+ stub_model(:user) do
14
+ include ActiveData::Model::Associations
15
+
16
+ attribute :name, String
17
+ embeds_many :projects
18
+ end
19
+ end
20
+
21
+ it { is_expected.to be_a(ActiveData::Model) }
22
+ it { is_expected.to be_a(ActiveData::Model::Primary) }
23
+ it { is_expected.to be_a(ActiveData::Model::Lifecycle) }
24
+ it { is_expected.to be_a(ActiveData::Model::Associations) }
25
+
26
+ context 'when ActiveData.base_concern is defined' do
27
+ before do
28
+ stub_const('MyModule', Module.new)
29
+
30
+ allow(ActiveData).to receive(:base_concern).and_return(MyModule)
31
+
32
+ stub_model(:user) do
33
+ include ActiveData::Model::Associations
34
+
35
+ embeds_many :projects
36
+ end
37
+ end
38
+
39
+ it { is_expected.to be_a(MyModule) }
40
+ end
41
+ end
42
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_data
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - pyromaniac
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-08 00:00:00.000000000 Z
11
+ date: 2018-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -277,6 +277,7 @@ files:
277
277
  - spec/lib/active_data/model/associations/persistence_adapters/active_record_spec.rb
278
278
  - spec/lib/active_data/model/associations/references_many_spec.rb
279
279
  - spec/lib/active_data/model/associations/references_one_spec.rb
280
+ - spec/lib/active_data/model/associations/reflections/embeds_any_spec.rb
280
281
  - spec/lib/active_data/model/associations/reflections/embeds_many_spec.rb
281
282
  - spec/lib/active_data/model/associations/reflections/embeds_one_spec.rb
282
283
  - spec/lib/active_data/model/associations/reflections/references_many_spec.rb
@@ -347,6 +348,7 @@ test_files:
347
348
  - spec/lib/active_data/model/associations/persistence_adapters/active_record_spec.rb
348
349
  - spec/lib/active_data/model/associations/references_many_spec.rb
349
350
  - spec/lib/active_data/model/associations/references_one_spec.rb
351
+ - spec/lib/active_data/model/associations/reflections/embeds_any_spec.rb
350
352
  - spec/lib/active_data/model/associations/reflections/embeds_many_spec.rb
351
353
  - spec/lib/active_data/model/associations/reflections/embeds_one_spec.rb
352
354
  - spec/lib/active_data/model/associations/reflections/references_many_spec.rb