dir_model 0.6.1 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/lib/dir_model/import.rb +8 -2
- data/lib/dir_model/model/relations.rb +6 -5
- data/lib/dir_model/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7378de9f6c47b4b77eb94586bf020f0fd63936f4
|
4
|
+
data.tar.gz: f0658de2bead2696f7b2c0f42acc3a47657bfd76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76622ae1c4b1d7c548147f0f51ed28efc80dc97be1d4008b23c93c689e687674caac34828ecc68e424da6e96f2bbab199f57d435308c423260917534b0c55ab4
|
7
|
+
data.tar.gz: de928cf63446966eb56948c029f742f97d5ede9058d94698e2cbe4336e963ccba6baca339851811e8b0a281575ab7b5f94879228e0f65818e8bf1b1c207b9f76
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
### VERSION 0.6.2
|
2
|
+
|
3
|
+
* Removing escaping from the code, so now `foreign_key` should be escaped on the caller, basically user `Regexp.quote` :
|
4
|
+
|
5
|
+
```
|
6
|
+
class ParentImportDirModel < BasicImportDirModel
|
7
|
+
has_one :dependency, ChildImportDirModel, foreign_key: :sector_name
|
8
|
+
|
9
|
+
def sector_name
|
10
|
+
"sector_#{Regexp.quote(sector_id)}"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
```
|
14
|
+
|
1
15
|
### VERSION 0.6.1
|
2
16
|
|
3
17
|
* escape special characters on foreign key values. Due of this relations weren't be found.
|
data/lib/dir_model/import.rb
CHANGED
@@ -41,14 +41,20 @@ module DirModel
|
|
41
41
|
if dir_model.has_relations?
|
42
42
|
if dir_model.has_one?
|
43
43
|
child = search(path, context) do |_path, _context|
|
44
|
-
|
44
|
+
related_dir_model = nil
|
45
|
+
dir_model.has_one.each do |name, options|
|
46
|
+
related_dir_model = dir_model.append_dir_model(_path.current_path, index: _path.index, context: _context, relation_name: name, relation_options: options)
|
47
|
+
end
|
48
|
+
related_dir_model
|
45
49
|
end.first
|
50
|
+
# Recursive call on children
|
46
51
|
find_relations(child, path, context) if child
|
47
52
|
end
|
48
53
|
if dir_model.has_many?
|
49
54
|
children = search(path, context) do |_path, _context|
|
50
55
|
dir_model.append_dir_models(_path.current_path, index: _path.index, context: _context)
|
51
56
|
end
|
57
|
+
# Recursive call on children
|
52
58
|
children.each { |_child| find_relations(_child, path, context) }
|
53
59
|
end
|
54
60
|
end
|
@@ -85,7 +91,7 @@ module DirModel
|
|
85
91
|
|
86
92
|
def get_regexp
|
87
93
|
if foreign_value
|
88
|
-
Regexp.new(self.class.options[:regex].call(
|
94
|
+
Regexp.new(self.class.options[:regex].call(foreign_value), Regexp::IGNORECASE)
|
89
95
|
else
|
90
96
|
self.class.options[:regex].call
|
91
97
|
end
|
@@ -20,8 +20,8 @@ module DirModel
|
|
20
20
|
#
|
21
21
|
# @return [Model] return the child if it is valid, otherwise returns nil
|
22
22
|
def append_dir_model(source_path, options={})
|
23
|
-
relation_name =
|
24
|
-
_options =
|
23
|
+
relation_name = options[:relation_name]
|
24
|
+
_options = options[:relation_options]
|
25
25
|
related_class = _options[:dir_model_class]
|
26
26
|
foreign_key = _options[:foreign_key]
|
27
27
|
foreign_value = self.send(foreign_key)
|
@@ -79,8 +79,6 @@ module DirModel
|
|
79
79
|
# @param [Symbol] relation_name the name of the relation
|
80
80
|
# @param [DirModel::Import] dir_model_class class of the relation
|
81
81
|
def has_one(relation_name, dir_model_class, options)
|
82
|
-
raise "for now, DirModel's has_one may only be called once" if @_has_one_relationship.present?
|
83
|
-
|
84
82
|
relation_name = relation_name.to_sym
|
85
83
|
|
86
84
|
merge_has_one_relationship(relation_name => { dir_model_class: dir_model_class }.merge(options))
|
@@ -89,6 +87,10 @@ module DirModel
|
|
89
87
|
true
|
90
88
|
end
|
91
89
|
|
90
|
+
define_method(:has_one) do
|
91
|
+
self.class.has_one_relationship
|
92
|
+
end
|
93
|
+
|
92
94
|
define_method("#{relation_name}=") do |value|
|
93
95
|
instance_variable_set("@#{relation_name}", value)
|
94
96
|
end
|
@@ -109,7 +111,6 @@ module DirModel
|
|
109
111
|
# @param [Hash] basically for set :foreign_key
|
110
112
|
def has_many(relation_name, dir_model_class, options)
|
111
113
|
raise "for now, DirModel's has_many may only be called once" if @_has_many_relationship.present?
|
112
|
-
|
113
114
|
relation_name = relation_name.to_sym
|
114
115
|
|
115
116
|
merge_has_many_relationship(relation_name => { dir_model_class: dir_model_class }.merge(options))
|
data/lib/dir_model/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dir_model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Chung
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|