jet_set 0.3.1 → 0.3.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
  SHA1:
3
- metadata.gz: fe8110ac9241efcdd8c84d85b8668cbeb48e022a
4
- data.tar.gz: 479ef832c344f4dbc3fd45494d23b3fa19a33a1b
3
+ metadata.gz: 9d9c31fea3ab85535b7334a1bcfea9f5a15577f6
4
+ data.tar.gz: 9dff8880d96dc20c7674a64e66553ac104da18be
5
5
  SHA512:
6
- metadata.gz: 98f1d9bf5214c2a271ba7e72d73878ebc21673bc8251355163a9d3647c5c135c11f08603eb6dae68835a3d5de780d499d5bcc47bead8d0a56e7586ec3bbdba86
7
- data.tar.gz: 6df0496c18992fdd35f1ac8da910c936d3e3a6ea156ed49802cbc59a161294a82a28c55aed6757dba581c92901c9061a73132cd78514edf1ecdd596e6d0238a8
6
+ metadata.gz: 23b7ed643ec6ad827879e7d6f2e1e9d0f038a78cd7051483de3c85f6ea1f32d02361d098ecbeab6648375b5d206367028bdd16310ca8a11bd76962ece12b0258
7
+ data.tar.gz: c59832f80bbf2996665384963be940e81ae9bc26a68a28f6d5bb212e28c1899710c544cfb5eeff48564e5a9a7458453eddaa475708d5ad11809a765111bb8964
@@ -10,7 +10,7 @@ module JetSet
10
10
 
11
11
  mapping.entity_mappings.keys.each do |key|
12
12
  entity = mapping.entity_mappings[key]
13
- @matrix[entity.type.name] = entity.dependencies.map{|d| d.name}
13
+ @matrix[entity.type.name] = entity.relations.map{|d| d.name}
14
14
  end
15
15
  end
16
16
 
@@ -5,7 +5,7 @@ module JetSet
5
5
  # Entity mapping is an element of JetSet mapping definition, see +JetSet::Mapping+.
6
6
  # Should be instantiated by method +entity+ of +JetSet::Mapping+ instance.
7
7
  class EntityMapping
8
- attr_reader :references, :collections, :fields, :type, :dependencies
8
+ attr_reader :references, :collections, :fields, :type, :dependencies, :relations
9
9
 
10
10
  # Initializes the mapping using Ruby block.
11
11
  # Parameters:
@@ -15,7 +15,8 @@ module JetSet
15
15
  @type = type
16
16
  @references = {}
17
17
  @collections = {}
18
- @dependencies = []
18
+ @dependencies = [] # stores only strong dependencies
19
+ @relations = [] # stores all dependencies
19
20
  @fields = ['id']
20
21
 
21
22
  if block_given?
@@ -42,8 +43,9 @@ module JetSet
42
43
  raise MapperError, "Reference \"#{name}\" should have a type. Example:\n reference '#{name}', type: User\n"
43
44
  end
44
45
 
45
- @references[name] = Reference.new(name, params[:type])
46
+ @references[name] = Reference.new(name, params[:type], params[:weak])
46
47
  @dependencies << params[:type] unless params[:weak]
48
+ @relations << params[:type]
47
49
  end
48
50
 
49
51
  # Defines an attribute-collection of a complex type - another entity defined in the mapping.
@@ -37,8 +37,11 @@ module JetSet
37
37
 
38
38
  row.reference_names.each do |reference_name|
39
39
  if entity_mapping.references.key? reference_name.to_sym
40
- type = entity_mapping.references[reference_name.to_sym].type
41
- entity.set_reference! reference_name, map(type, row_hash, session, reference_name)
40
+ reference_id_name = reference_name + '__id'
41
+ unless row_hash[reference_id_name.to_sym].nil?
42
+ type = entity_mapping.references[reference_name.to_sym].type
43
+ entity.set_reference! reference_name, map(type, row_hash, session, reference_name)
44
+ end
42
45
  end
43
46
  end
44
47
 
@@ -97,12 +97,16 @@ module JetSet
97
97
 
98
98
  entity.references.keys.each do |key|
99
99
  value = instance_variable_get("@#{key}")
100
+ reference = entity.references[key]
101
+
100
102
  if value
101
103
  reference_id = value.instance_variable_get('@id')
102
- if reference_id.nil?
104
+
105
+ if reference_id.nil? && !reference.weak?
103
106
  @__factory.create(value)
104
107
  value.flush(sequel)
105
108
  end
109
+
106
110
  set_reference!(key, value)
107
111
  fields << "#{key}_id"
108
112
 
@@ -7,9 +7,15 @@ module JetSet
7
7
  # Parameters:
8
8
  # +name+:: name of the attribute
9
9
  # +type+:: class of an entity
10
- def initialize(name, type)
10
+ # +weak+:: is it weak reference?
11
+ def initialize(name, type, weak)
11
12
  @name = name
12
13
  @type = type
14
+ @weak = weak
15
+ end
16
+
17
+ def weak?
18
+ @weak
13
19
  end
14
20
  end
15
21
  end
@@ -1,3 +1,3 @@
1
1
  module JetSet
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jet_set
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Kalinkin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-02 00:00:00.000000000 Z
11
+ date: 2018-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel