display_case 0.1.2 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +22 -0
- data/lib/display_case/configuration.rb +11 -2
- data/lib/display_case/enumerable_exhibit.rb +2 -2
- data/lib/display_case/exhibit.rb +12 -7
- data/lib/display_case/find_definitions.rb +30 -4
- metadata +6 -8
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
|
data/README.md
CHANGED
@@ -133,3 +133,25 @@ how to choose good keys.
|
|
133
133
|
Wrong url with extra parameters using an exhibited model?
|
134
134
|
------------------
|
135
135
|
See this issue for the reason: https://github.com/objects-on-rails/display-case/issues/8
|
136
|
+
|
137
|
+
|
138
|
+
TypeError: superclass mismatch for class MyExhibit
|
139
|
+
------------------
|
140
|
+
This error is common in development mode in code bases which `ExhibitB` inherits from `ExhibitA`, which inherits from `DisplayCase::Exhibit`.
|
141
|
+
DisplayCase is doing a lot of messing around with your exhibits to make them respond appropriately as if they were the object you're exhibiting,
|
142
|
+
and that is _normally_ the cause of this error if you're using inheritance among exhibits.
|
143
|
+
|
144
|
+
However, since it's possible you could actually be inadvertently having a superclass mismatch, the recommended way around this error is to avoid
|
145
|
+
the situation.
|
146
|
+
|
147
|
+
In case you're having this error, and you're confident that is _not_ happening, we do provide a configuration option to catch this
|
148
|
+
error and reload the class anyway. :warning: But be warned, if it is a legitimate superclass mismatch, you won't catch it with
|
149
|
+
this option turned on! :warning:
|
150
|
+
|
151
|
+
To turn on this option, in your DisplayCase initializer:
|
152
|
+
|
153
|
+
```ruby
|
154
|
+
DisplayCase.configure do |config|
|
155
|
+
config.swallow_superclass_mismatch_for_exhibits = true
|
156
|
+
end
|
157
|
+
```
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require_relative 'enumerable_exhibit'
|
2
|
-
|
3
1
|
module DisplayCase
|
4
2
|
class << self
|
5
3
|
attr_accessor :configuration
|
@@ -31,6 +29,10 @@ module DisplayCase
|
|
31
29
|
# context should be favored over other exhibits. By default, this is true
|
32
30
|
attr_accessor :smart_matching
|
33
31
|
|
32
|
+
# A boolean indicating whether DisplayCase will swallow superclass mismatch
|
33
|
+
# errors (see README for more info). By default, this is false.
|
34
|
+
attr_accessor :swallow_superclass_mismatch_for_exhibits
|
35
|
+
|
34
36
|
def initialize
|
35
37
|
@definition_file_paths = %w(app/exhibits)
|
36
38
|
@explicit = false
|
@@ -38,6 +40,7 @@ module DisplayCase
|
|
38
40
|
@cache_store = nil
|
39
41
|
@logging_enabled = false
|
40
42
|
@smart_matching = true
|
43
|
+
@swallow_superclass_mismatch_for_exhibits = false
|
41
44
|
end
|
42
45
|
|
43
46
|
def explicit?
|
@@ -48,6 +51,10 @@ module DisplayCase
|
|
48
51
|
smart_matching
|
49
52
|
end
|
50
53
|
|
54
|
+
def swallow_superclass_mismatch_for_exhibits?
|
55
|
+
swallow_superclass_mismatch_for_exhibits
|
56
|
+
end
|
57
|
+
|
51
58
|
def logging_enabled?
|
52
59
|
defined? ::Rails and logging_enabled
|
53
60
|
end
|
@@ -58,6 +65,8 @@ module DisplayCase
|
|
58
65
|
|
59
66
|
def exhibits=(val)
|
60
67
|
@exhibits = Array(val)
|
68
|
+
DisplayCase::Exhibit.initialize_exhibits
|
69
|
+
@exhibits
|
61
70
|
end
|
62
71
|
end
|
63
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,9 +17,36 @@ module DisplayCase
|
|
18
17
|
private
|
19
18
|
def self.display_case_load(file)
|
20
19
|
@file_changes ||= {}
|
21
|
-
if File.
|
22
|
-
|
23
|
-
|
20
|
+
if File.exist?(file) && (@file_changes[file].to_i < (mtime = File.mtime(file).to_i))
|
21
|
+
begin
|
22
|
+
load file
|
23
|
+
@file_changes[file] = mtime
|
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?
|
26
|
+
if klass.ancestors.include?(DisplayCase::Exhibit) && configuration.swallow_superclass_mismatch_for_exhibits?
|
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)
|
38
|
+
retry
|
39
|
+
else
|
40
|
+
raise error
|
41
|
+
end
|
42
|
+
end
|
24
43
|
end
|
25
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
|
26
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.1
|
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,10 +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: []
|
57
|
-
has_rdoc:
|