activerecord_to_poro 0.0.3 → 0.0.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 22303b2e1fdea401dba91cc9d58cd87f13d3f711
4
- data.tar.gz: 83b8bf5c084aa93fb5b5614369a049aaa763dd24
3
+ metadata.gz: 24e632b82acbcdf3589327c6d5af701573ba97cf
4
+ data.tar.gz: 0e7f98e49af88b6644f2f1d5da2a91d02fbf8529
5
5
  SHA512:
6
- metadata.gz: 906060ece82669221ba6883bd97dfeb3ee0a862b634025896cfe97b5ddb4731fdf4c169e34bfd5d1dc8b6abb7551a50a0d3bcf16b5c08fd40b765a69032b9b53
7
- data.tar.gz: 9b59fdd62577e984c6d0fdfc4a84cc8e31b12c53c29ada165f30de83302765c79e652b036c9551e511c3f1a42cca71f875e8cea640018d0c0b75b8c97ab9d4d2
6
+ metadata.gz: 73cdfc500b19c1a94cc1875db048748dc952fc286e37605ea1a8ce83e76bb4cfeb18e3c1364a7c72e6004003a0c55eadc6db785f6b8dbdacb7f7444fd2e01139
7
+ data.tar.gz: 84437b91e7943cd95e8c98e90f8aa7901f0345b25e92917a9d4349f01a2464724a3e6935492e27de2bfba201ae54d803d7d1192a8db967785d36da8af7eb98e9
data/.travis.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.1.0
3
+ - 2.1
4
4
  notifications:
5
5
  recipients:
6
6
  - shad0wrunner@gmx.de
@@ -13,7 +13,8 @@ module ActiverecordToPoro
13
13
  attr_accessor :association_converters,
14
14
  :use_lazy_loading,
15
15
  :except_attributes,
16
- :only_attributes
16
+ :only_attributes,
17
+ :use_mass_assignment
17
18
 
18
19
  class << self
19
20
  private :new
@@ -24,10 +25,11 @@ module ActiverecordToPoro
24
25
  except: nil,
25
26
  only: nil,
26
27
  name: nil,
28
+ use_mass_assignment_constructor: true,
27
29
  load_source: DefaultPoroClassBuilder.new(ar_class).(),
28
30
  convert_associations: {})
29
31
 
30
- new(load_source, ar_class).tap do|new_mapper|
32
+ new(load_source, ar_class, use_mass_assignment_constructor).tap do|new_mapper|
31
33
  new_mapper.fetcher(:public_send)
32
34
 
33
35
  new_mapper.association_converters = convert_associations
@@ -43,6 +45,11 @@ module ActiverecordToPoro
43
45
  end
44
46
  end
45
47
 
48
+ def initialize(load_result_source, dump_result_source, use_mass_assignment_constructor)
49
+ self.use_mass_assignment = use_mass_assignment_constructor
50
+ super(load_result_source, dump_result_source)
51
+ end
52
+
46
53
  alias_method :extend_mapping, :add_mapping
47
54
 
48
55
  def attributes_for_default_mapping
@@ -56,10 +63,20 @@ module ActiverecordToPoro
56
63
  end
57
64
 
58
65
  def load_result_source=(new_load_result)
59
- @load_result_source = new_load_result.tap do |source|
60
- unless source.instance_methods.include?(:_metadata)
61
- source.send(:include, MetadataEnabled)
62
- end
66
+ unless new_load_result.instance_methods.include?(:_metadata)
67
+ new_load_result.send(:include, MetadataEnabled)
68
+ end
69
+
70
+ if use_mass_assignment
71
+ @load_result_source = new_load_result
72
+ else
73
+ @load_result_source = ->(attrs){
74
+ new_load_result.new.tap do |entity|
75
+ attrs.each_pair do |key, value|
76
+ entity.public_send "#{key}=", value
77
+ end
78
+ end
79
+ }
63
80
  end
64
81
  end
65
82
 
@@ -1,3 +1,3 @@
1
1
  module ActiverecordToPoro
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -17,6 +17,24 @@ describe ActiverecordToPoro::ObjectMapper do
17
17
  expect(object.attributes_for_default_mapping).to eq [:id]
18
18
  end
19
19
 
20
+ it 'wraps the poro constructor if no massassignment is wanted' do
21
+
22
+ object = subject.create(User, only: :id, use_mass_assignment_constructor: false)
23
+ expect(object.load_result_source).to be_kind_of Proc
24
+ end
25
+
26
+ it 'wraps the poro constructor if no massassignment is wanted' do
27
+ result_class = Struct.new(:id)
28
+ object = subject.create(User, load_source: result_class, only: :id, use_mass_assignment_constructor: false)
29
+ expect(object.load_result_source).to be_kind_of Proc
30
+ end
31
+
32
+ it 'does not wrap the poro constructor if massassignment is wanted' do
33
+ result_class = Struct.new(:id)
34
+ object = subject.create(User, load_source: result_class, only: :id, use_mass_assignment_constructor: true)
35
+ expect(object.load_result_source).to be result_class
36
+ end
37
+
20
38
  end
21
39
 
22
40
  context 'instance methods' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord_to_poro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dieter Späth
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-03 00:00:00.000000000 Z
11
+ date: 2014-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: abstract_type