lazy_record 0.1.8 → 0.1.9

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: 9fcd565fc270b0c3ecb5278894e3f6eb1c3287d4
4
- data.tar.gz: b647814ace73eda6f34300868e852cdbe5eb6724
3
+ metadata.gz: 98460eb0778d6a59b63f876bb77db1eb5459b050
4
+ data.tar.gz: de124a0a25a87792a7d8b993a39d3b9c193d35e8
5
5
  SHA512:
6
- metadata.gz: 0ccfaad3e66cd2c7c516f1a791d12dd0d5fab7c5ff0dd5b9c5f1ed01bd09ecde2c584aa78ed1a47e76421fd4a682a55d4c19ca70cab25dc1efe7c5612e80db09
7
- data.tar.gz: cc8e35116bb835526f000f498e71f79e3d7a3d6d3101b0d9921cf5a789c1020f4b0bdf38f39b8e7395ef39f30afcd541360d814b6a0f6f059929d2b783c29d39
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 = {}, &block)
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 = {}, &block)
22
+ def self.new(opts = {})
23
23
  puts 'hi'
24
- super opts, &block
24
+ super
25
25
  end
26
26
 
27
- def self.make_people(*args, &block)
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| block.call(person) } if block
46
+ people.each { |person| yield person } if block_given?
47
47
 
48
48
  people
49
49
  end
50
50
 
51
- def times(num, &block)
52
- if block
51
+ def times(num)
52
+ if block_given?
53
53
  i = 0
54
54
  while i < num
55
- block.call
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 = {}, &block)
64
+ def adopt_a_dog(opts = {})
65
65
  dog = Dog.new(opts)
66
- block.call(dog) if block
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
@@ -19,7 +19,10 @@ module LazyRecord
19
19
 
20
20
  attr_writer :id
21
21
 
22
- def initialize(_opts = {})
22
+ def initialize(opts = {})
23
+ opts.each do |k, v|
24
+ send("#{k}=", v) if respond_to?("#{k}=")
25
+ end
23
26
  yield self if block_given?
24
27
  end
25
28
 
@@ -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 = {}, &block)
8
+ def new(opts = {})
9
9
  @all ||= Relation.new(model: self)
10
- instance = super(opts, &block)
10
+ instance = super(opts)
11
11
  if instance.respond_to?(:validation)
12
12
  instance = instance.validation(*@validations)
13
13
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LazyRecord
4
- VERSION = '0.1.8'
4
+ VERSION = '0.1.9'
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.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - M. Simon Borg