lazy_record 0.7.1 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lazy_record/associations.rb +1 -1
- data/lib/lazy_record/collections.rb +5 -3
- data/lib/lazy_record/nesting.rb +15 -1
- data/lib/lazy_record/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 210e518e34f2cb7c600f99b7ec2b2158c0b36def
|
4
|
+
data.tar.gz: 71a6808fc5e63546a686556cfa349b1e2549fd67
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 =
|
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 =
|
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 =
|
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 =
|
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|
|
data/lib/lazy_record/nesting.rb
CHANGED
@@ -7,7 +7,11 @@ module LazyRecord
|
|
7
7
|
"#{to_s.split('::')[0..-2].join('::')}::#{class_name}"
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
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
|
data/lib/lazy_record/version.rb
CHANGED