evt-reflect 0.1.1.0 → 0.1.2.0

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
  SHA256:
3
- metadata.gz: 2cb7354176aa20ae6ac1b80dac6373d786aaf3e38934093fdbc732f844af0e8e
4
- data.tar.gz: 6fec96989b2f5d08ba6115c4db77379aec0b019d77f53d4c9e0296de90a4d872
3
+ metadata.gz: a677b93e4d91b91241106755f0d2657b365f591c22c357fc21210ea66139bcd1
4
+ data.tar.gz: 25ba5a63c2120ee8ed3393c83b0a19eeffe577ec15fd88d8233cf6ae6270e1bb
5
5
  SHA512:
6
- metadata.gz: c31835237d4b0d55ba9ef9bc2fb102dad19990814e94ed8ea0b4f38865e75a8850137120389bc376ab029a537172fce4b003a175ffd686a68c087fc6f5da167e
7
- data.tar.gz: cb26d37deea43d8761f81beb5ac5a8e088f59a978d8d68de17a3023f7f7d1458e309ca14f15e2b4484921e346ca302326e922890558503937e0e4e9c49145dc3
6
+ metadata.gz: e9a20f4f5a1b398f8562304ae67c67f8070b8c9f41bac984554079b02aedc13fde2e2c64bf6fda0454bef97cbf358b8e2b5c2df81d68fe731205f1dade0c8afc
7
+ data.tar.gz: ddce9b61efa62d27a12a041aa445e8cc4db25e617fc542a626759e6cfc98a4e7183a4b8b4ff063d9c277a87522378d2710efb4d486fd55a7cd2bc9556ca9ea51
@@ -2,3 +2,4 @@ require 'securerandom'
2
2
 
3
3
  require 'reflect/controls/namespace'
4
4
  require 'reflect/controls/subject'
5
+ require 'reflect/controls/ancestor'
@@ -0,0 +1,17 @@
1
+ module Reflect
2
+ module Controls
3
+ module Ancestor
4
+ def self.example
5
+ Example.new
6
+ end
7
+
8
+ class Example
9
+ module SomeConstant
10
+ end
11
+
12
+ class Descendant < Example
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,21 +1,22 @@
1
1
  module Reflect
2
2
  Error = Class.new(RuntimeError)
3
3
 
4
- def self.call(subject, constant_name, strict: nil)
5
- Reflection.build(subject, constant_name, strict: strict)
4
+ def self.call(subject, constant_name, strict: nil, ancestors: nil)
5
+ Reflection.build(subject, constant_name, strict: strict, ancestors: ancestors)
6
6
  end
7
7
 
8
8
  def self.subject_constant(subject)
9
9
  [Module, Class].include?(subject.class) ? subject : subject.class
10
10
  end
11
11
 
12
- def self.get_constant(subject_constant, constant_name, strict: nil)
12
+ def self.get_constant(subject_constant, constant_name, strict: nil, ancestors: nil)
13
13
  strict = Reflection::Default.strict if strict.nil?
14
+ ancestors = Reflection::Default.ancestors if ancestors.nil?
14
15
 
15
16
  constant = nil
16
17
 
17
- if constant?(subject_constant, constant_name)
18
- constant = get_constant!(subject_constant, constant_name)
18
+ if constant?(subject_constant, constant_name, ancestors: ancestors)
19
+ constant = get_constant!(subject_constant, constant_name, ancestors: ancestors)
19
20
  end
20
21
 
21
22
  if constant.nil? && strict
@@ -25,11 +26,13 @@ module Reflect
25
26
  constant
26
27
  end
27
28
 
28
- def self.get_constant!(subject_constant, constant_name)
29
- subject_constant.const_get(constant_name, false)
29
+ def self.get_constant!(subject_constant, constant_name, ancestors: nil)
30
+ ancestors = Reflection::Default.ancestors if ancestors.nil?
31
+ subject_constant.const_get(constant_name, ancestors)
30
32
  end
31
33
 
32
- def self.constant?(subject_constant, constant_name)
33
- subject_constant.const_defined?(constant_name, false)
34
+ def self.constant?(subject_constant, constant_name, ancestors: nil)
35
+ ancestors = Reflection::Default.ancestors if ancestors.nil?
36
+ subject_constant.const_defined?(constant_name, ancestors)
34
37
  end
35
38
  end
@@ -14,6 +14,18 @@ module Reflect
14
14
  @strict = strict
15
15
  end
16
16
 
17
+ def self.build(subject, constant_name, strict: nil, ancestors: nil)
18
+ strict = Default.strict if strict.nil?
19
+ ancestors = Default.ancestors if ancestors.nil?
20
+
21
+ subject_constant = Reflect.subject_constant(subject)
22
+
23
+ constant = Reflect.get_constant(subject_constant, constant_name, strict: strict, ancestors: ancestors)
24
+ return nil if constant.nil?
25
+
26
+ instance = new(subject, constant, strict)
27
+ end
28
+
17
29
  def call(method_name, arg=nil)
18
30
  unless constant.respond_to?(method_name)
19
31
  raise Reflect::Error, "Constant #{constant.name} does not define method #{method_name}"
@@ -24,17 +36,6 @@ module Reflect
24
36
  constant.send(method_name, arg)
25
37
  end
26
38
 
27
- def self.build(subject, constant_name, strict: nil)
28
- strict = Default.strict if strict.nil?
29
-
30
- subject_constant = Reflect.subject_constant(subject)
31
-
32
- constant = Reflect.get_constant(subject_constant, constant_name, strict: strict)
33
- return nil if constant.nil?
34
-
35
- instance = new(subject, constant, strict)
36
- end
37
-
38
39
  def constant_accessor?(name)
39
40
  constant.respond_to?(name)
40
41
  end
@@ -67,6 +68,10 @@ module Reflect
67
68
  def self.strict
68
69
  true
69
70
  end
71
+
72
+ def self.ancestors
73
+ false
74
+ end
70
75
  end
71
76
  end
72
77
  end
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.1.0
4
+ version: 0.1.2.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-06 00:00:00.000000000 Z
11
+ date: 2018-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test_bench
@@ -32,6 +32,7 @@ extra_rdoc_files: []
32
32
  files:
33
33
  - lib/reflect.rb
34
34
  - lib/reflect/controls.rb
35
+ - lib/reflect/controls/ancestor.rb
35
36
  - lib/reflect/controls/namespace.rb
36
37
  - lib/reflect/controls/subject.rb
37
38
  - lib/reflect/reflect.rb