display_case 0.2.1 → 0.3.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 +5 -5
- data/lib/display_case/configuration.rb +4 -4
- data/lib/display_case/exhibit.rb +12 -7
- data/lib/display_case/find_definitions.rb +22 -6
- metadata +6 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 945dfe570fe0c95e52b65e0f673ebd6226e2c82eaef75d9233af833cf2565ef4
|
4
|
+
data.tar.gz: bf0a1fe16e46ba68aeb290352fe2cd75831d1e6ba517011bd61896d7b9ec7e18
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d93788b405a1273e46e59d341ca74f7b8570b5861c65f59d42056de0bb3d5cce2ad1cdd62dc5ab4fdfefa77befb60a2b890b5ac453afd76111dae9d403f6919
|
7
|
+
data.tar.gz: d59cf587424e12bb5572f6662572dc7236f2f2cd3a559136c52cea842e62ebd3aa8cdaebc759bf9274a1f7af51602e9f50a6ce4cfd9f9d4bcce7fc1fc3b0d2d4
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require_relative 'enumerable_exhibit'
|
2
|
-
|
3
1
|
module DisplayCase
|
4
2
|
class << self
|
5
3
|
attr_accessor :configuration
|
@@ -30,7 +28,7 @@ module DisplayCase
|
|
30
28
|
# A boolean indicating whether Exhibits with names that are similar to
|
31
29
|
# context should be favored over other exhibits. By default, this is true
|
32
30
|
attr_accessor :smart_matching
|
33
|
-
|
31
|
+
|
34
32
|
# A boolean indicating whether DisplayCase will swallow superclass mismatch
|
35
33
|
# errors (see README for more info). By default, this is false.
|
36
34
|
attr_accessor :swallow_superclass_mismatch_for_exhibits
|
@@ -52,7 +50,7 @@ module DisplayCase
|
|
52
50
|
def smart_matching?
|
53
51
|
smart_matching
|
54
52
|
end
|
55
|
-
|
53
|
+
|
56
54
|
def swallow_superclass_mismatch_for_exhibits?
|
57
55
|
swallow_superclass_mismatch_for_exhibits
|
58
56
|
end
|
@@ -67,6 +65,8 @@ module DisplayCase
|
|
67
65
|
|
68
66
|
def exhibits=(val)
|
69
67
|
@exhibits = Array(val)
|
68
|
+
DisplayCase::Exhibit.initialize_exhibits
|
69
|
+
@exhibits
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
data/lib/display_case/exhibit.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'delegate'
|
2
|
+
require 'active_support'
|
2
3
|
require 'active_support/core_ext'
|
3
4
|
require 'display_case/railtie' if defined?(::Rails)
|
4
5
|
require_relative 'configuration'
|
@@ -7,18 +8,22 @@ require_relative 'name_class_comparator'
|
|
7
8
|
|
8
9
|
module DisplayCase
|
9
10
|
class Exhibit < SimpleDelegator
|
10
|
-
|
11
|
+
def self.initialize_exhibits
|
12
|
+
@@exhibits = []
|
13
|
+
@@exhibits = DisplayCase.configuration.exhibits.dup if DisplayCase.configuration.explicit?
|
14
|
+
end
|
15
|
+
initialize_exhibits
|
11
16
|
|
12
17
|
def self.exhibits
|
13
|
-
|
14
|
-
DisplayCase.configuration.exhibits
|
15
|
-
else
|
16
|
-
@@exhibits
|
17
|
-
end
|
18
|
+
@@exhibits
|
18
19
|
end
|
19
20
|
|
20
21
|
def self.inherited(child)
|
21
|
-
@@exhibits
|
22
|
+
if idx = @@exhibits.map(&:name).index(child.name)
|
23
|
+
@@exhibits[idx] = child
|
24
|
+
elsif !DisplayCase.configuration.explicit?
|
25
|
+
@@exhibits << child
|
26
|
+
end
|
22
27
|
end
|
23
28
|
|
24
29
|
def self.exhibit(object, context=nil)
|
@@ -1,5 +1,4 @@
|
|
1
1
|
module DisplayCase
|
2
|
-
|
3
2
|
def self.find_definitions
|
4
3
|
absolute_definition_file_paths = configuration.definition_file_paths.map {|path| File.expand_path(path) }
|
5
4
|
|
@@ -18,19 +17,36 @@ module DisplayCase
|
|
18
17
|
private
|
19
18
|
def self.display_case_load(file)
|
20
19
|
@file_changes ||= {}
|
21
|
-
if File.
|
20
|
+
if File.exist?(file) && (@file_changes[file].to_i < (mtime = File.mtime(file).to_i))
|
22
21
|
begin
|
23
22
|
load file
|
24
23
|
@file_changes[file] = mtime
|
25
|
-
rescue TypeError
|
26
|
-
klass =
|
24
|
+
rescue TypeError => error
|
25
|
+
klass = find_class_candidates(error.message).first # TODO: Is there a way to make this work correctly if there are multiple candidates?
|
27
26
|
if klass.ancestors.include?(DisplayCase::Exhibit) && configuration.swallow_superclass_mismatch_for_exhibits?
|
28
|
-
|
27
|
+
delimiter = '::'
|
28
|
+
namespace, klass_name =
|
29
|
+
if klass.name.index(delimiter)
|
30
|
+
klass_names = klass.name.split(delimiter)
|
31
|
+
namespace_name = klass_names[0..-2].join(delimiter).constantize
|
32
|
+
klass_name = klass_names.last
|
33
|
+
[namespace_name, klass_name]
|
34
|
+
else
|
35
|
+
[Object, klass.name]
|
36
|
+
end
|
37
|
+
namespace.send(:remove_const, klass_name.to_sym)
|
29
38
|
retry
|
30
39
|
else
|
31
|
-
raise
|
40
|
+
raise error
|
32
41
|
end
|
33
42
|
end
|
34
43
|
end
|
35
44
|
end
|
45
|
+
|
46
|
+
def self.find_class_candidates(error_message)
|
47
|
+
klass_name = error_message.gsub("superclass mismatch for class ", "")
|
48
|
+
[klass_name.constantize]
|
49
|
+
rescue NameError
|
50
|
+
ObjectSpace.each_object(Class).select{|c| c.to_s.split('::').last == klass_name}
|
51
|
+
end
|
36
52
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: display_case
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Avdi Grimm
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: An implementation of the Exhibit pattern, as described in Objects on
|
14
14
|
Rails
|
@@ -33,7 +33,7 @@ files:
|
|
33
33
|
homepage: https://github.com/objects-on-rails/display-case
|
34
34
|
licenses: []
|
35
35
|
metadata: {}
|
36
|
-
post_install_message:
|
36
|
+
post_install_message:
|
37
37
|
rdoc_options: []
|
38
38
|
require_paths:
|
39
39
|
- lib
|
@@ -48,9 +48,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
48
48
|
- !ruby/object:Gem::Version
|
49
49
|
version: '0'
|
50
50
|
requirements: []
|
51
|
-
|
52
|
-
|
53
|
-
signing_key:
|
51
|
+
rubygems_version: 3.0.3
|
52
|
+
signing_key:
|
54
53
|
specification_version: 4
|
55
54
|
summary: An implementation of the Exhibit pattern, as described in Objects on Rails
|
56
55
|
test_files: []
|