lazy_record 0.1.0 → 0.1.1

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: ad81a7b0c3eb8a909fd99ba5cec96b772c649fae
4
- data.tar.gz: d6da780999fd6cef493cc0192dd9f9a8ab1fac77
3
+ metadata.gz: 2a600da5b0f7578c40fca42e349acfdd8ead86f6
4
+ data.tar.gz: 39fdf3dd67b33c91235b7d18a067a55ecac89370
5
5
  SHA512:
6
- metadata.gz: b33fd97c406b27bd2150500b329039b0420078fdd5d8fa8958d8f359061f6919bfc351c35b7f2df4e977fd7ad1d23345c24bc752929cbec5bdcafde4f986412f
7
- data.tar.gz: 28d25026ef52d74f4837be47400f686e996e6de1374e78319db65fc8faeffc352cb1ef7b7fd500011b1de251d4b150985ec5d0bc3d58826ab489404c9e4cc1ac
6
+ metadata.gz: cb2bbded1a40899dcdeedb83369810d4a7724fcd1b8debe0ace25549d5afb1a5927f5fcbe8c85877bfa17373afcf96db3cb144f036ec35032db677155a13d0d8
7
+ data.tar.gz: 02b008aa58f14d93b5d5e0f4e28c064826f795b6e47403918bff4f62a7bf827440de54a4035e9e4ec2a0fda3bc9aa6674576c1e2a7d2a8ac9a01336defd431ca
@@ -14,21 +14,28 @@ class LazyRecord
14
14
  end
15
15
  end
16
16
 
17
- def lr_method(method_name, *args, method)
18
- mod = get_or_set_and_include_mod(METHODS_MODULE_NAME)
19
-
20
- args = args.map(&:to_s).join(', ')
21
-
17
+ def lr_method(method_name, *method_args, method)
18
+ mod = get_or_set_and_include_mod(METHODS_MODULE_NAME)
19
+ method_args = method_args.map(&:to_s).join(', ')
20
+
22
21
  if method.respond_to?(:call)
23
- mod.module_eval do
24
- send(:define_method, method_name, &method)
25
- end
22
+ make_method_from_proc(mod, method_name, method)
26
23
  else
27
- mod.module_eval do
28
- define_method(method_name) do |*params|
29
- block = eval("lambda { |#{args}| #{method} }")
30
- block.call(*params)
31
- end
24
+ make_method_from_string(mod, method_name, method_args, method)
25
+ end
26
+ end
27
+
28
+ def make_method_from_proc(mod, method_name, proc)
29
+ mod.module_eval do
30
+ send(:define_method, method_name, &proc)
31
+ end
32
+ end
33
+
34
+ def make_method_from_string(mod, method_name, method_args, method)
35
+ mod.module_eval do
36
+ define_method(method_name) do |*params|
37
+ block = eval("lambda { |#{method_args}| #{method} }")
38
+ block.call(*params)
32
39
  end
33
40
  end
34
41
  end
@@ -18,7 +18,7 @@ class LazyRecord
18
18
  begin
19
19
  raise ArgumentError if send(param.to_sym).nil?
20
20
  rescue => e
21
- puts e, "#{arg} must be given", inspect
21
+ puts e, "#{param} must be given", inspect
22
22
  return false
23
23
  end
24
24
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  class LazyRecord
3
- VERSION = '0.1.0'
3
+ VERSION = '0.1.1'
4
4
  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.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - M. Simon Borg