activerecord_to_poro 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/activerecord_to_poro.gemspec +3 -1
- data/lib/activerecord_to_poro/mapper_extension.rb +8 -5
- data/lib/activerecord_to_poro/metadata_enabled_ar.rb +2 -3
- data/lib/activerecord_to_poro/version.rb +1 -1
- data/spec/ar_spec_helper.rb +20 -10
- data/spec/ar_support/db/migrate/20140127093447_create_my_ar_class.rb +5 -5
- data/spec/ar_support/models/address.rb +1 -1
- data/spec/ar_support/models/permission.rb +1 -1
- data/spec/ar_support/models/role.rb +1 -1
- data/spec/ar_support/models/user.rb +1 -1
- metadata +19 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d07a91d246c4e9b3d0f758d871c6cdc9390f7f1
|
4
|
+
data.tar.gz: 848dda5dad35ff0b94775f4467580dcbe5a57f1b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74e9b3544bde6cf80cc394ba30e4fc13d5c1481e9943201b01d95df4c60e1c7e6c052b9e4d5236c37bc02f32d6999c1678b1a80dfa3fd062650597dc11543702
|
7
|
+
data.tar.gz: 1b80a95b618aed044e31c71b8093afef9472238383b4df2f1ffd383239e7fb4a35f782acb850fc78e95fe7eb1d35da8cc3943b01e476812c3c751d161489eec9
|
data/CHANGELOG.md
ADDED
@@ -26,7 +26,9 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.add_development_dependency "bundler", "~> 1.5"
|
27
27
|
spec.add_development_dependency "rake"
|
28
28
|
spec.add_development_dependency 'sqlite3'
|
29
|
-
spec.add_development_dependency '
|
29
|
+
spec.add_development_dependency 'pg'
|
30
|
+
# spec.add_development_dependency 'activerecord', '4.0.2'
|
31
|
+
spec.add_development_dependency 'activerecord', '4.2.0'
|
30
32
|
spec.add_development_dependency 'database_cleaner'
|
31
33
|
|
32
34
|
|
@@ -44,14 +44,17 @@ module ActiverecordToPoro
|
|
44
44
|
module_function
|
45
45
|
|
46
46
|
def is_an_ar_collection?(ar_class, association_name)
|
47
|
-
(ar_class
|
48
|
-
|
47
|
+
ref = reflection_for_association(ar_class, association_name)
|
48
|
+
(ref && ref.collection?)
|
49
49
|
end
|
50
50
|
|
51
51
|
def is_an_has_many_through(ar_class, association_name)
|
52
|
-
ar_class
|
53
|
-
|
54
|
-
|
52
|
+
ref = reflection_for_association(ar_class, association_name)
|
53
|
+
ref && ref.macro == :has_many && ref.options.has_key?(:through)
|
54
|
+
end
|
55
|
+
|
56
|
+
def reflection_for_association(ar_class, association_name)
|
57
|
+
ar_class.reflections[association_name.to_sym] || ar_class.reflections[association_name.to_s]
|
55
58
|
end
|
56
59
|
|
57
60
|
end
|
@@ -14,7 +14,6 @@ module ActiverecordToPoro
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def _update_poro_metadata
|
17
|
-
|
18
17
|
_referenced_poros.each do |entity|
|
19
18
|
entity._set_metadata_from_ar = self if entity.respond_to? :_set_metadata_from_ar=
|
20
19
|
|
@@ -39,7 +38,7 @@ module ActiverecordToPoro
|
|
39
38
|
|
40
39
|
record.tap do |new_obj|
|
41
40
|
|
42
|
-
new_obj.attributes = attrs
|
41
|
+
new_obj.attributes = attrs || {}
|
43
42
|
|
44
43
|
_patch_has_many_members(attrs, new_obj) unless new_obj.new_record?
|
45
44
|
end
|
@@ -77,7 +76,7 @@ module ActiverecordToPoro
|
|
77
76
|
end
|
78
77
|
|
79
78
|
def _extract_metadata!(attrs)
|
80
|
-
metadata = (attrs || {}).delete(:_set_metadata_to_ar)
|
79
|
+
metadata = (attrs || {}).delete(:_set_metadata_to_ar){ |*| Metadata.new }
|
81
80
|
metadata.for_ar_class(self.name)
|
82
81
|
end
|
83
82
|
|
data/spec/ar_spec_helper.rb
CHANGED
@@ -1,18 +1,28 @@
|
|
1
1
|
require 'active_record'
|
2
|
-
require 'database_cleaner'
|
3
2
|
|
4
3
|
db_dir = File.join(File.expand_path(__dir__ ), "ar_support/db/")
|
5
4
|
# ENV['DATABASE_URL']="sqlite3://localhost/:memory:?pool=5&timeout=5000"
|
6
5
|
|
6
|
+
con_settings = {
|
7
|
+
pool: 5,
|
8
|
+
timeout: 5000,
|
9
|
+
database: ":memory:",
|
10
|
+
adapter: "sqlite3"
|
11
|
+
}
|
12
|
+
|
13
|
+
# con_settings = {
|
14
|
+
# adapter: 'postgresql',
|
15
|
+
# encoding: 'utf8',
|
16
|
+
# pool: 5,
|
17
|
+
# host: 'localhost',
|
18
|
+
# port: 5000,
|
19
|
+
# database: 'poro_test'
|
20
|
+
# }
|
7
21
|
|
22
|
+
require 'database_cleaner'
|
8
23
|
|
9
|
-
ActiveRecord::Base.
|
10
|
-
|
11
|
-
timeout: 5000,
|
12
|
-
database: ":memory:",
|
13
|
-
adapter: "sqlite3"
|
14
|
-
})
|
15
|
-
|
24
|
+
ActiveRecord::Base.logger = Logger.new(STDOUT)
|
25
|
+
ActiveRecord::Base.establish_connection(con_settings)
|
16
26
|
ActiveRecord::Migrator.migrate "#{db_dir}/migrate"
|
17
27
|
|
18
28
|
Dir[File.join(File.expand_path(__dir__ ), "ar_support/models/**/*.rb")].each { |f| require f }
|
@@ -20,8 +30,8 @@ Dir[File.join(File.expand_path(__dir__ ), "ar_support/models/**/*.rb")].each { |
|
|
20
30
|
RSpec.configure do |config|
|
21
31
|
|
22
32
|
config.before(:suite) do
|
23
|
-
DatabaseCleaner.strategy = :
|
24
|
-
DatabaseCleaner.clean_with(:truncation)
|
33
|
+
DatabaseCleaner.strategy = :truncation, {:except => %w[schema_migrations public.schema_migrations]}
|
34
|
+
DatabaseCleaner.clean_with(:truncation, {:except => %w[schema_migrations public.schema_migrations]})
|
25
35
|
end
|
26
36
|
|
27
37
|
config.before(:each) do
|
@@ -4,30 +4,30 @@ class CreateMyArClass < ActiveRecord::Migration
|
|
4
4
|
t.string :name
|
5
5
|
t.string :email
|
6
6
|
t.integer :salutation_id
|
7
|
-
t.integer :lock_version
|
7
|
+
t.integer :lock_version, default: 0
|
8
8
|
end
|
9
9
|
|
10
10
|
create_table :roles do |t|
|
11
11
|
t.string :name
|
12
12
|
t.integer :user_id
|
13
|
-
t.integer :lock_version
|
13
|
+
t.integer :lock_version, default: 0
|
14
14
|
end
|
15
15
|
|
16
16
|
create_table :permissions do |t|
|
17
17
|
t.string :name
|
18
18
|
t.integer :role_id
|
19
|
-
t.integer :lock_version
|
19
|
+
t.integer :lock_version, default: 0
|
20
20
|
end
|
21
21
|
|
22
22
|
create_table :salutations do |t|
|
23
23
|
t.string :name
|
24
|
-
t.integer :lock_version
|
24
|
+
t.integer :lock_version, default: 0
|
25
25
|
end
|
26
26
|
|
27
27
|
create_table :addresses do |t|
|
28
28
|
t.string :street
|
29
29
|
t.integer :user_id
|
30
|
-
t.integer :lock_version
|
30
|
+
t.integer :lock_version, default: 0
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
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.
|
4
|
+
version: 0.0.9
|
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:
|
11
|
+
date: 2015-01-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: abstract_type
|
@@ -80,20 +80,34 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pg
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: activerecord
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
86
100
|
requirements:
|
87
101
|
- - '='
|
88
102
|
- !ruby/object:Gem::Version
|
89
|
-
version: 4.0
|
103
|
+
version: 4.2.0
|
90
104
|
type: :development
|
91
105
|
prerelease: false
|
92
106
|
version_requirements: !ruby/object:Gem::Requirement
|
93
107
|
requirements:
|
94
108
|
- - '='
|
95
109
|
- !ruby/object:Gem::Version
|
96
|
-
version: 4.0
|
110
|
+
version: 4.2.0
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: database_cleaner
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -271,6 +285,7 @@ extra_rdoc_files: []
|
|
271
285
|
files:
|
272
286
|
- ".gitignore"
|
273
287
|
- ".travis.yml"
|
288
|
+
- CHANGELOG.md
|
274
289
|
- Gemfile
|
275
290
|
- Guardfile
|
276
291
|
- LICENSE.txt
|