evt-reflect 0.1.2.0 → 0.2.0.0

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
  SHA256:
3
- metadata.gz: a677b93e4d91b91241106755f0d2657b365f591c22c357fc21210ea66139bcd1
4
- data.tar.gz: 25ba5a63c2120ee8ed3393c83b0a19eeffe577ec15fd88d8233cf6ae6270e1bb
3
+ metadata.gz: 123bd228ca91520f866f3bc1e14b4a0393faa1ab9ed42e13ec10e2eb489fd753
4
+ data.tar.gz: 1f835ab7273697e2a5449a438b163f0d2fa54332dc565bbead69533b3ae9084c
5
5
  SHA512:
6
- metadata.gz: e9a20f4f5a1b398f8562304ae67c67f8070b8c9f41bac984554079b02aedc13fde2e2c64bf6fda0454bef97cbf358b8e2b5c2df81d68fe731205f1dade0c8afc
7
- data.tar.gz: ddce9b61efa62d27a12a041aa445e8cc4db25e617fc542a626759e6cfc98a4e7183a4b8b4ff063d9c277a87522378d2710efb4d486fd55a7cd2bc9556ca9ea51
6
+ metadata.gz: e04997ea94f314b8d25933445474b72cca7a63efc73f9c0d81cc885bc75bc558e2a0fbbe4b7eadb4f86e452d3d9e01535c12cdcdc0dce70e5ddafc33c9985acb
7
+ data.tar.gz: 6d2291e4f14037d41433fcd15ea64b3d419d785e542f1fd658395714090393d36ebba39dc4938e28c52d4b4cce66494f0681a2b74a926b6b3abfa464b30d7c8b
@@ -5,7 +5,7 @@ module Reflect
5
5
  Reflection.build(subject, constant_name, strict: strict, ancestors: ancestors)
6
6
  end
7
7
 
8
- def self.subject_constant(subject)
8
+ def self.constant(subject)
9
9
  [Module, Class].include?(subject.class) ? subject : subject.class
10
10
  end
11
11
 
@@ -1,16 +1,17 @@
1
1
  module Reflect
2
2
  class Reflection
3
3
  attr_reader :subject
4
- attr_reader :constant
4
+ attr_reader :target
5
+ alias :constant :target
5
6
  attr_reader :strict
6
7
 
7
8
  def subject_constant
8
- @subject_constant ||= Reflect.subject_constant(subject)
9
+ @subject_constant ||= Reflect.constant(subject)
9
10
  end
10
11
 
11
- def initialize(subject, constant, strict)
12
+ def initialize(subject, target, strict)
12
13
  @subject = subject
13
- @constant = constant
14
+ @target = target
14
15
  @strict = strict
15
16
  end
16
17
 
@@ -18,50 +19,57 @@ module Reflect
18
19
  strict = Default.strict if strict.nil?
19
20
  ancestors = Default.ancestors if ancestors.nil?
20
21
 
21
- subject_constant = Reflect.subject_constant(subject)
22
+ subject_constant = Reflect.constant(subject)
22
23
 
23
- constant = Reflect.get_constant(subject_constant, constant_name, strict: strict, ancestors: ancestors)
24
- return nil if constant.nil?
24
+ target = Reflect.get_constant(subject_constant, constant_name, strict: strict, ancestors: ancestors)
25
+ return nil if target.nil?
25
26
 
26
- instance = new(subject, constant, strict)
27
+ instance = new(subject, target, strict)
27
28
  end
28
29
 
29
30
  def call(method_name, arg=nil)
30
- unless constant.respond_to?(method_name)
31
- raise Reflect::Error, "Constant #{constant.name} does not define method #{method_name}"
31
+ unless target.respond_to?(method_name)
32
+ target_name = Reflect.constant(target).name
33
+ raise Reflect::Error, "#{target_name} does not define method #{method_name}"
32
34
  end
33
35
 
34
36
  arg ||= subject
35
37
 
36
- constant.send(method_name, arg)
38
+ target.send(method_name, arg)
37
39
  end
38
40
 
39
- def constant_accessor?(name)
40
- constant.respond_to?(name)
41
+ def target_accessor?(name, subject=nil)
42
+ subject ||= constant
43
+ subject.respond_to?(name)
41
44
  end
42
45
 
43
- def get(accessor_name, strict: nil)
46
+ def get(accessor_name, strict: nil, coerce_constant: nil)
44
47
  strict = self.strict if strict.nil?
48
+ coerce_constant = true if coerce_constant.nil?
45
49
 
46
- result = get_constant(accessor_name, strict: strict)
47
- return nil if result.nil?
50
+ target = get_target(accessor_name, strict: strict)
51
+ return nil if target.nil?
48
52
 
49
- constant = Reflect.subject_constant(result)
50
- self.class.new(subject, constant, strict)
53
+ if coerce_constant
54
+ target = Reflect.constant(target)
55
+ end
56
+
57
+ self.class.new(subject, target, strict)
51
58
  end
52
59
 
53
- def get_constant(accessor_name, strict: nil)
60
+ def get_target(accessor_name, strict: nil)
54
61
  strict = self.strict if strict.nil?
55
62
 
56
- if !constant_accessor?(accessor_name)
63
+ if !target_accessor?(accessor_name)
57
64
  if strict
58
- raise Reflect::Error, "Constant #{constant.name} does not have accessor #{accessor_name}"
65
+ target_name = Reflect.constant(target).name
66
+ raise Reflect::Error, "#{target_name} does not have accessor #{accessor_name}"
59
67
  else
60
68
  return nil
61
69
  end
62
70
  end
63
71
 
64
- constant.send(accessor_name)
72
+ target.send(accessor_name)
65
73
  end
66
74
 
67
75
  module Default
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evt-reflect
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2.0
4
+ version: 0.2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - The Eventide Project
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-11 00:00:00.000000000 Z
11
+ date: 2018-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test_bench