display_case 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +15 -2
- data/lib/display_case.rb +1 -0
- data/lib/display_case/configuration.rb +44 -0
- data/lib/display_case/exhibit.rb +6 -1
- data/lib/display_case/find_definitions.rb +1 -9
- metadata +4 -3
data/README.md
CHANGED
@@ -7,7 +7,7 @@ Description
|
|
7
7
|
-----------
|
8
8
|
If the Model is concerned with storing and manipulating business data, and the View is concerned with displaying it, you can think of the Exhibit as standing between them deciding which data to show, and in what order. It may also provide some extra presentation-specific information (such as the specific URLs for related resources) which the business model has no knowledge of by itself.
|
9
9
|
|
10
|
-
The Exhibit object is so named because it is like a museum display case for an artifact or a work of art. It does not obscure any of the features of the object being presented. Rather, it tries showcase the object in the best light to a human audience, while also presenting meta-information about the object and cross-references to other objects in the museum's collection.
|
10
|
+
The Exhibit object is so named because it is like a museum display case for an artifact or a work of art. It does not obscure any of the features of the object being presented. Rather, it tries to showcase the object in the best light to a human audience, while also presenting meta-information about the object and cross-references to other objects in the museum's collection.
|
11
11
|
|
12
12
|
Technically, exhibit objects are a type of Decorator specialized for presenting models to an end user.
|
13
13
|
|
@@ -71,4 +71,17 @@ Finally, in your view, you can use your Exhibit:
|
|
71
71
|
|
72
72
|
Configuration
|
73
73
|
-------------
|
74
|
-
|
74
|
+
Several configuration options can be set via an initializer:
|
75
|
+
|
76
|
+
1. `definition_file_paths` Because Rails lazily-loads files, in development mode DisplayCase will search /app/exhibits to load the Exhibits found there. If your Exhibits are elsewhere, you can set `config.definition_file_paths = ['list/of/directories', 'to/find/exhibits']` in your initializers/display_case.rb.
|
77
|
+
1. `explicit` By default this option is false and Exhibits will be dynamically added via the inherited callback.
|
78
|
+
1. `exhibits` If `explicit` is true you must explicitly set the Exhibits you wish to use in the order you want them evaluated. You can set `config.exhibits = [AnExhibit,AnotherExhibit]` in your initializers/display_case.rb.
|
79
|
+
|
80
|
+
An example `initializers/display_case.rb`
|
81
|
+
```
|
82
|
+
DisplayCase.configure do |config|
|
83
|
+
config.definition_file_paths = ['app/exhibits','some/other/path']
|
84
|
+
config.explicit = true
|
85
|
+
config.exhibits = [MyFirstExhibit,MySecondExhibit]
|
86
|
+
end
|
87
|
+
```
|
data/lib/display_case.rb
CHANGED
@@ -0,0 +1,44 @@
|
|
1
|
+
require_relative 'enumerable_exhibit'
|
2
|
+
|
3
|
+
module DisplayCase
|
4
|
+
class << self
|
5
|
+
attr_accessor :configuration
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.configure
|
9
|
+
self.configuration ||= Configuration.new
|
10
|
+
yield(configuration)
|
11
|
+
end
|
12
|
+
|
13
|
+
class Configuration
|
14
|
+
# A boolean indicating whether the Exhibits will be explicitly listed in order or
|
15
|
+
# dynamically collected with the inherited callback. By default, this is false
|
16
|
+
# and the list will be generated via the inherited callback.
|
17
|
+
attr_accessor :explicit
|
18
|
+
|
19
|
+
# An Array of strings specifying locations that should be searched for
|
20
|
+
# exhibit classes and definitions. By default, "/app/exhibits" will be searched and
|
21
|
+
# existing file will be loaded.
|
22
|
+
attr_accessor :definition_file_paths
|
23
|
+
|
24
|
+
def initialize
|
25
|
+
@definition_file_paths = %w(app/exhibits)
|
26
|
+
@explicit = false
|
27
|
+
@exhibits = []
|
28
|
+
end
|
29
|
+
|
30
|
+
def explicit?
|
31
|
+
explicit
|
32
|
+
end
|
33
|
+
|
34
|
+
def exhibits
|
35
|
+
[DisplayCase::Exhibit::Exhibited,DisplayCase::EnumerableExhibit] + @exhibits
|
36
|
+
end
|
37
|
+
|
38
|
+
def exhibits=(val)
|
39
|
+
@exhibits = Array(val)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
configure {}
|
44
|
+
end
|
data/lib/display_case/exhibit.rb
CHANGED
@@ -1,13 +1,18 @@
|
|
1
1
|
require 'delegate'
|
2
2
|
require 'active_support/core_ext'
|
3
3
|
require 'display_case/railtie' if defined?(Rails)
|
4
|
+
require_relative 'configuration'
|
4
5
|
|
5
6
|
module DisplayCase
|
6
7
|
class Exhibit < SimpleDelegator
|
7
8
|
@@exhibits = []
|
8
9
|
|
9
10
|
def self.exhibits
|
10
|
-
|
11
|
+
if DisplayCase.configuration.explicit?
|
12
|
+
DisplayCase.configuration.exhibits
|
13
|
+
else
|
14
|
+
@@exhibits
|
15
|
+
end
|
11
16
|
end
|
12
17
|
|
13
18
|
def self.inherited(child)
|
@@ -1,15 +1,7 @@
|
|
1
1
|
module DisplayCase
|
2
|
-
class << self
|
3
|
-
# An Array of strings specifying locations that should be searched for
|
4
|
-
# exhibit classes and definitions. By default, "/app/exhibits" will be searched and
|
5
|
-
# existing file will be loaded.
|
6
|
-
attr_accessor :definition_file_paths
|
7
|
-
end
|
8
|
-
|
9
|
-
self.definition_file_paths = %w(app/exhibits)
|
10
2
|
|
11
3
|
def self.find_definitions
|
12
|
-
absolute_definition_file_paths = definition_file_paths.map {|path| File.expand_path(path) }
|
4
|
+
absolute_definition_file_paths = configuration.definition_file_paths.map {|path| File.expand_path(path) }
|
13
5
|
|
14
6
|
absolute_definition_file_paths.uniq.each do |path|
|
15
7
|
load("#{path}.rb") if File.exists?("#{path}.rb")
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: display_case
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-06-06 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
14
|
description: An implementation of the Exhibit pattern, as described in Objects on
|
15
15
|
Rails
|
@@ -19,6 +19,7 @@ executables: []
|
|
19
19
|
extensions: []
|
20
20
|
extra_rdoc_files: []
|
21
21
|
files:
|
22
|
+
- lib/display_case/configuration.rb
|
22
23
|
- lib/display_case/enumerable_exhibit.rb
|
23
24
|
- lib/display_case/exhibit.rb
|
24
25
|
- lib/display_case/exhibits_helper.rb
|
@@ -47,7 +48,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
47
48
|
version: '0'
|
48
49
|
requirements: []
|
49
50
|
rubyforge_project:
|
50
|
-
rubygems_version: 1.8.
|
51
|
+
rubygems_version: 1.8.8
|
51
52
|
signing_key:
|
52
53
|
specification_version: 3
|
53
54
|
summary: An implementation of the Exhibit pattern, as described in Objects on Rails
|