lazy_record 0.1.8 → 0.1.9
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 +4 -4
- data/example/dog.rb +1 -1
- data/example/person.rb +10 -10
- data/lib/lazy_record/attributes.rb +0 -12
- data/lib/lazy_record/base_module.rb +4 -1
- data/lib/lazy_record/callbacks.rb +2 -2
- 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: 98460eb0778d6a59b63f876bb77db1eb5459b050
|
4
|
+
data.tar.gz: de124a0a25a87792a7d8b993a39d3b9c193d35e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 51f6e7ca2e8bbd54aa2b7a2526a85aa28b1cd6fa64fe1595f0a70cf9453ec2b85edef0d30c4cf39af0d50e5e1af36a720b4eacc3ddbc0a7b5ff38c216e53f832
|
7
|
+
data.tar.gz: bb8d95aa73395c01ead3ad6285e3c86f9ef416e5b84fd77c4166e8a78f1a082daddf6b7d699929d267ef00cf99a3bd17d0f4406702ad00abd5f086804388b454
|
data/example/dog.rb
CHANGED
@@ -4,7 +4,7 @@ class Dog < LazyRecord::Base
|
|
4
4
|
lr_attr_accessor :name, :breed, :weight
|
5
5
|
lr_has_many :friends
|
6
6
|
|
7
|
-
def initialize(opts = {}
|
7
|
+
def initialize(opts = {})
|
8
8
|
super
|
9
9
|
friends << Friend.new(opts) if opts[:friend] == true
|
10
10
|
self.name = name + 'y' if opts[:cute] == true
|
data/example/person.rb
CHANGED
@@ -19,16 +19,16 @@ class Person < LazyRecord::Base
|
|
19
19
|
|
20
20
|
lr_validates :name, :age, presence: true
|
21
21
|
|
22
|
-
def self.new(opts = {}
|
22
|
+
def self.new(opts = {})
|
23
23
|
puts 'hi'
|
24
|
-
super
|
24
|
+
super
|
25
25
|
end
|
26
26
|
|
27
|
-
def self.make_people(*args
|
27
|
+
def self.make_people(*args)
|
28
28
|
opts = args.extract_options!
|
29
29
|
|
30
30
|
people = args.map do |arg|
|
31
|
-
Person.new { |p| p.name = arg }
|
31
|
+
Person.new { |p| p.name = arg; p.age = 30 }
|
32
32
|
end
|
33
33
|
|
34
34
|
if opts[:count] == true
|
@@ -43,16 +43,16 @@ class Person < LazyRecord::Base
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
-
people.each { |person|
|
46
|
+
people.each { |person| yield person } if block_given?
|
47
47
|
|
48
48
|
people
|
49
49
|
end
|
50
50
|
|
51
|
-
def times(num
|
52
|
-
if
|
51
|
+
def times(num)
|
52
|
+
if block_given?
|
53
53
|
i = 0
|
54
54
|
while i < num
|
55
|
-
|
55
|
+
yield
|
56
56
|
i += 1
|
57
57
|
end
|
58
58
|
i
|
@@ -61,9 +61,9 @@ class Person < LazyRecord::Base
|
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
-
def adopt_a_dog(opts = {}
|
64
|
+
def adopt_a_dog(opts = {})
|
65
65
|
dog = Dog.new(opts)
|
66
|
-
|
66
|
+
yield dog if block_given?
|
67
67
|
self.dogs << dog
|
68
68
|
dog
|
69
69
|
end
|
@@ -19,17 +19,6 @@ module LazyRecord
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
def define_initialize
|
23
|
-
define_method(:initialize) do |opts = {}, &block|
|
24
|
-
opts.each do |k, v|
|
25
|
-
send("#{k}=", v) if respond_to?("#{k}=")
|
26
|
-
end
|
27
|
-
|
28
|
-
block&.call self
|
29
|
-
self
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
22
|
def define_instance_attrs_to_s
|
34
23
|
define_method(:instance_attrs_to_s) do
|
35
24
|
instance_attr_accessors.map do |attr|
|
@@ -53,7 +42,6 @@ module LazyRecord
|
|
53
42
|
mod.module_eval do
|
54
43
|
names.each { |name| define_setters_and_getters(name) }
|
55
44
|
define_instance_attr_accessors(*names)
|
56
|
-
define_initialize
|
57
45
|
define_instance_attrs_to_s
|
58
46
|
end
|
59
47
|
end
|
@@ -5,9 +5,9 @@ require 'lazy_record/dynamic_modules'
|
|
5
5
|
module LazyRecord
|
6
6
|
# After #initialize callbacks for validations and setting object id.
|
7
7
|
module Callbacks
|
8
|
-
def new(opts = {}
|
8
|
+
def new(opts = {})
|
9
9
|
@all ||= Relation.new(model: self)
|
10
|
-
instance = super(opts
|
10
|
+
instance = super(opts)
|
11
11
|
if instance.respond_to?(:validation)
|
12
12
|
instance = instance.validation(*@validations)
|
13
13
|
end
|
data/lib/lazy_record/version.rb
CHANGED