display_case 0.2.1 → 0.3.1

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
- SHA1:
3
- metadata.gz: 7b797b22fdea67cccee304457cc19e01ef3aa1a6
4
- data.tar.gz: 336a9351dd99f147cf98adc0f8873032e0797864
2
+ SHA256:
3
+ metadata.gz: 945dfe570fe0c95e52b65e0f673ebd6226e2c82eaef75d9233af833cf2565ef4
4
+ data.tar.gz: bf0a1fe16e46ba68aeb290352fe2cd75831d1e6ba517011bd61896d7b9ec7e18
5
5
  SHA512:
6
- metadata.gz: 639ea3ea3d110ca299a96df5f2a939399114e4705647b259857327bd9ce22a4b1f14a2f169b5d1b20dacc007ceef3fde412e4bea21a4080b12186b2417b29b72
7
- data.tar.gz: 46b2059c482299fca753cd5599d2dc3f562ee4c5cb224b8f0a9222765b809f95f86ceacb03ff6332b4472318aa56381bb01b68f070037cd214ee1d2ad82084ac
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
 
@@ -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
- @@exhibits = []
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
- if DisplayCase.configuration.explicit?
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 << child
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.exists?(file) && (@file_changes[file].to_i < (mtime = File.mtime(file).to_i))
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 = $!.message.gsub("superclass mismatch for class ", "").constantize
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
- Object.send(:remove_const, klass.name.to_sym)
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.2.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: 2015-04-23 00:00:00.000000000 Z
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
- rubyforge_project:
52
- rubygems_version: 2.4.6
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: []