lazy_record 0.7.1 → 0.7.2

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: 96f4035ed9553066def5485883f2134475f18812
4
- data.tar.gz: c7ef20837f4f9e8bce74d38f6b71a22c8e03dcb0
3
+ metadata.gz: 210e518e34f2cb7c600f99b7ec2b2158c0b36def
4
+ data.tar.gz: 71a6808fc5e63546a686556cfa349b1e2549fd67
5
5
  SHA512:
6
- metadata.gz: cd311bb1ad1d8e87eadcadbc65c458682826a0b689e65d85a009c4b8f96d3cf63f1324382b4e7aebf70d956248f81e04bf145caa966245e1660747ec9207876f
7
- data.tar.gz: c890f9790a3e25b079663f1c6cbb9945a2c82f2616a9ce1fa0cf161932b360518d0e99624a4ab02edccc5b549127e48b8d6e01d760e82d3a68cef1538829a5c4
6
+ metadata.gz: 0b9ce7da8a84075361166153b02c0a277845497f030126758a644e36594316b393f02a363befc2ded3cd04e2becee3184cd310828ba47e227c24335364edb8dd
7
+ data.tar.gz: aef1072706aeac6fb52def4cbc84efc8820448423733afa449f23fe20d88752535e2f72c9386cf75b97ea2ce4792c99c1c6cbec4641d725dac731263dc39ee1f
@@ -40,7 +40,7 @@ module LazyRecord
40
40
  end
41
41
 
42
42
  def define_association_setter(assoc)
43
- klass = lazily_get_class(assoc.to_s.camelize).call
43
+ klass = lazy_const_get_one_level_back(assoc.to_s.camelize).call
44
44
  define_method("#{assoc}=") do |val|
45
45
  return instance_variable_set("@#{assoc}", val) if val.is_a? klass
46
46
  raise ArgumentError, "Argument must be a #{klass}"
@@ -11,7 +11,7 @@ module LazyRecord
11
11
  NESTED_ATTRS_MODULE_NAME = :NestedAttributes
12
12
 
13
13
  def _define_collection_getter(collection, options)
14
- klass = lazily_get_class(options[:class_name]).call
14
+ klass = lazy_const_get_one_level_back(options[:class_name]).call
15
15
  module_eval <<-RUBY, __FILE__, __LINE__ + 1
16
16
  def #{collection}
17
17
  @#{collection} ||= Relation.new(klass: #{klass})
@@ -20,7 +20,7 @@ module LazyRecord
20
20
  end
21
21
 
22
22
  def _define_collection_setter(collection, options)
23
- klass = lazily_get_class(options[:class_name]).call
23
+ klass = lazy_const_get_one_level_back(options[:class_name]).call
24
24
  module_eval <<-RUBY, __FILE__, __LINE__ + 1
25
25
  def #{collection}=(coll)
26
26
  @#{collection} = Relation.new(klass: #{klass}, collection: coll)
@@ -80,7 +80,9 @@ module LazyRecord
80
80
  end
81
81
 
82
82
  def define_collection_attributes_setter(collection, options)
83
- class_name = lazily_get_class(options.fetch(:class_name)).call
83
+ class_name = lazy_const_get_one_level_back(
84
+ options.fetch(:class_name)
85
+ ).call
84
86
  module_eval <<-RUBY, __FILE__, __LINE__ + 1
85
87
  def #{collection}_attributes=(collection_attributes)
86
88
  collection_attributes.values.each do |attributes|
@@ -7,7 +7,11 @@ module LazyRecord
7
7
  "#{to_s.split('::')[0..-2].join('::')}::#{class_name}"
8
8
  end
9
9
 
10
- def lazily_get_class(class_name)
10
+ def apply_nesting_one_level_back(class_name)
11
+ "#{to_s.split('::')[0..-3].join('::')}::#{class_name}"
12
+ end
13
+
14
+ def lazy_const_get(class_name)
11
15
  lambda do
12
16
  begin
13
17
  const_get(class_name)
@@ -16,5 +20,15 @@ module LazyRecord
16
20
  end
17
21
  end
18
22
  end
23
+
24
+ def lazy_const_get_one_level_back(class_name)
25
+ lambda do
26
+ begin
27
+ const_get(class_name)
28
+ rescue NameError
29
+ const_get apply_nesting_one_level_back(class_name)
30
+ end
31
+ end
32
+ end
19
33
  end
20
34
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LazyRecord
4
- VERSION = '0.7.1'
4
+ VERSION = '0.7.2'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lazy_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - M. Simon Borg