vedeu 0.6.10 → 0.6.11
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 +4 -4
- data/lib/vedeu/all.rb +17 -103
- data/lib/vedeu/api/all.rb +15 -0
- data/lib/vedeu/api/internal.rb +4 -0
- data/lib/vedeu/application/all.rb +6 -0
- data/lib/vedeu/bindings/all.rb +32 -0
- data/lib/vedeu/bindings/bindings.rb +0 -14
- data/lib/vedeu/bindings/refresh.rb +8 -2
- data/lib/vedeu/bindings/system.rb +1 -0
- data/lib/vedeu/borders/border.rb +1 -1
- data/lib/vedeu/borders/repository.rb +1 -1
- data/lib/vedeu/buffers/buffer.rb +2 -4
- data/lib/vedeu/buffers/repository.rb +1 -1
- data/lib/vedeu/colours/background.rb +1 -1
- data/lib/vedeu/colours/backgrounds.rb +1 -1
- data/lib/vedeu/colours/foreground.rb +1 -1
- data/lib/vedeu/colours/foregrounds.rb +1 -1
- data/lib/vedeu/colours/translator.rb +4 -3
- data/lib/vedeu/configuration/api.rb +2 -1
- data/lib/vedeu/configuration/cli.rb +1 -1
- data/lib/vedeu/cursors/cursor.rb +26 -26
- data/lib/vedeu/cursors/repository.rb +1 -1
- data/lib/vedeu/distributed/all.rb +16 -0
- data/lib/vedeu/distributed/test_application.rb +3 -3
- data/lib/vedeu/dsl/all.rb +22 -0
- data/lib/vedeu/dsl/composition.rb +43 -40
- data/lib/vedeu/dsl/dsl.rb +6 -3
- data/lib/vedeu/dsl/group.rb +23 -16
- data/lib/vedeu/dsl/interface.rb +48 -38
- data/lib/vedeu/dsl/keymap.rb +6 -7
- data/lib/vedeu/dsl/line.rb +6 -3
- data/lib/vedeu/dsl/stream.rb +2 -1
- data/lib/vedeu/editor/cursor.rb +1 -3
- data/lib/vedeu/editor/document.rb +4 -5
- data/lib/vedeu/editor/documents.rb +1 -1
- data/lib/vedeu/editor/line.rb +2 -3
- data/lib/vedeu/editor/lines.rb +2 -3
- data/lib/vedeu/esc/all.rb +14 -0
- data/lib/vedeu/esc/colours.rb +8 -4
- data/lib/vedeu/esc/esc.rb +89 -84
- data/lib/vedeu/events/aliases.rb +1 -2
- data/lib/vedeu/events/collection.rb +1 -1
- data/lib/vedeu/events/event.rb +1 -1
- data/lib/vedeu/events/repository.rb +1 -1
- data/lib/vedeu/events/trigger.rb +11 -9
- data/lib/vedeu/geometry/dimension.rb +1 -3
- data/lib/vedeu/geometry/generic_coordinate.rb +1 -3
- data/lib/vedeu/geometry/geometry.rb +1 -1
- data/lib/vedeu/geometry/repository.rb +3 -3
- data/lib/vedeu/input/all.rb +3 -0
- data/lib/vedeu/input/keymap.rb +10 -11
- data/lib/vedeu/input/keymaps.rb +1 -1
- data/lib/vedeu/input/keys.rb +1 -1
- data/lib/vedeu/input/mapper.rb +14 -12
- data/lib/vedeu/logging/all.rb +3 -0
- data/lib/vedeu/logging/log.rb +4 -2
- data/lib/vedeu/menus/menu.rb +2 -4
- data/lib/vedeu/menus/repository.rb +1 -1
- data/lib/vedeu/models/all.rb +15 -0
- data/lib/vedeu/models/cell.rb +1 -1
- data/lib/vedeu/models/escape.rb +1 -1
- data/lib/vedeu/models/group.rb +4 -3
- data/lib/vedeu/models/groups.rb +1 -1
- data/lib/vedeu/models/interface.rb +1 -1
- data/lib/vedeu/models/interfaces.rb +1 -1
- data/lib/vedeu/models/views/char.rb +1 -1
- data/lib/vedeu/models/views/collections/chars.rb +1 -1
- data/lib/vedeu/models/views/collections/lines.rb +1 -1
- data/lib/vedeu/models/views/collections/streams.rb +1 -1
- data/lib/vedeu/models/views/collections/view_collection.rb +1 -1
- data/lib/vedeu/models/views/composition.rb +1 -1
- data/lib/vedeu/models/views/line.rb +8 -6
- data/lib/vedeu/models/views/stream.rb +1 -1
- data/lib/vedeu/models/views/view.rb +1 -1
- data/lib/vedeu/null/all.rb +12 -0
- data/lib/vedeu/output/clear/named_group.rb +2 -1
- data/lib/vedeu/output/clear/named_interface.rb +5 -4
- data/lib/vedeu/output/compressor.rb +1 -0
- data/lib/vedeu/output/output.rb +3 -0
- data/lib/vedeu/output/presentation/colour.rb +10 -10
- data/lib/vedeu/output/presentation/presentation.rb +9 -9
- data/lib/vedeu/output/presentation/style.rb +2 -2
- data/lib/vedeu/output/refresh/refresh.rb +35 -0
- data/lib/vedeu/output/refresh/refresh_group.rb +66 -0
- data/lib/vedeu/output/renderers/all.rb +17 -0
- data/lib/vedeu/output/renderers/escape_sequence.rb +4 -2
- data/lib/vedeu/output/renderers/file.rb +7 -6
- data/lib/vedeu/output/renderers/html.rb +9 -7
- data/lib/vedeu/output/renderers/null.rb +1 -1
- data/lib/vedeu/output/renderers/renderer_options.rb +24 -20
- data/lib/vedeu/output/renderers/terminal.rb +1 -1
- data/lib/vedeu/output/renderers/text.rb +1 -1
- data/lib/vedeu/output/wordwrap.rb +7 -4
- data/lib/vedeu/plugins/all.rb +2 -0
- data/lib/vedeu/repositories/all.rb +16 -0
- data/lib/vedeu/repositories/collection.rb +93 -89
- data/lib/vedeu/repositories/model.rb +113 -102
- data/lib/vedeu/repositories/registerable.rb +60 -56
- data/lib/vedeu/repositories/repository.rb +161 -156
- data/lib/vedeu/repositories/store.rb +70 -66
- data/lib/vedeu/runtime/all.rb +15 -0
- data/lib/vedeu/runtime/launcher.rb +19 -16
- data/lib/vedeu/templating/all.rb +6 -0
- data/lib/vedeu/terminal/all.rb +14 -0
- data/lib/vedeu/terminal/buffer.rb +8 -7
- data/lib/vedeu/terminal/mode.rb +11 -10
- data/lib/vedeu/terminal/terminal.rb +50 -45
- data/lib/vedeu/version.rb +1 -1
- data/test/lib/vedeu/cursors/cursor_test.rb +4 -2
- data/test/lib/vedeu/editor/cursor_test.rb +0 -3
- data/test/lib/vedeu/esc/esc_test.rb +58 -54
- data/test/lib/vedeu/events/collection_test.rb +1 -1
- data/test/lib/vedeu/input/keys_test.rb +1 -1
- data/test/lib/vedeu/input/mapper_test.rb +1 -1
- data/test/lib/vedeu/models/views/collections/chars_test.rb +1 -1
- data/test/lib/vedeu/models/views/collections/lines_test.rb +1 -1
- data/test/lib/vedeu/models/views/collections/streams_test.rb +1 -1
- data/test/lib/vedeu/models/views/collections/view_collection_test.rb +1 -1
- data/test/lib/vedeu/output/refresh/refresh_group_test.rb +43 -0
- data/test/lib/vedeu/output/refresh/refresh_test.rb +50 -0
- data/test/lib/vedeu/output/renderers/renderer_options_test.rb +8 -4
- data/test/lib/vedeu/output/renderers_test.rb +2 -1
- data/test/lib/vedeu/repositories/collection_test.rb +105 -101
- data/test/lib/vedeu/repositories/model_test.rb +56 -52
- data/test/lib/vedeu/repositories/registerable_test.rb +36 -32
- data/test/lib/vedeu/repositories/repository_test.rb +178 -174
- data/test/lib/vedeu/repositories/store_test.rb +109 -105
- data/test/support/examples/material_colours_app.rb +0 -1
- data/test/support/helpers/model_test_class.rb +50 -46
- data/test/test_helper.rb +2 -2
- metadata +21 -9
- data/lib/vedeu/refresh/refresh.rb +0 -31
- data/lib/vedeu/refresh/refresh_group.rb +0 -59
- data/out_ +0 -50
- data/test/lib/vedeu/refresh/refresh_group_test.rb +0 -39
- data/test/lib/vedeu/refresh/refresh_test.rb +0 -46
@@ -1,107 +1,111 @@
|
|
1
1
|
module Vedeu
|
2
2
|
|
3
|
-
|
4
|
-
# context it is being used.
|
5
|
-
#
|
6
|
-
class Collection
|
3
|
+
module Repositories
|
7
4
|
|
8
|
-
|
5
|
+
# Convert an Array into an object which has some meaning in the
|
6
|
+
# context it is being used.
|
7
|
+
#
|
8
|
+
class Collection
|
9
|
+
|
10
|
+
include Enumerable
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
# @!attribute [r] collection
|
13
|
+
# @return [Array|Vedeu::Repositories::Collection]
|
14
|
+
attr_reader :collection
|
15
|
+
alias_method :all, :collection
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
-
|
17
|
+
# @!attribute [rw] parent
|
18
|
+
# @return [Fixnum]
|
19
|
+
attr_accessor :parent
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
-
|
21
|
+
# @!attribute [rw] name
|
22
|
+
# @return [String]
|
23
|
+
attr_accessor :name
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
25
|
+
# @param collection [Array|Vedeu::Repositories::Collection]
|
26
|
+
# @param parent [void]
|
27
|
+
# @param name [String|NilClass]
|
28
|
+
# @return [Vedeu::Repositories::Collection]
|
29
|
+
def self.coerce(collection = [], parent = nil, name = nil)
|
30
|
+
if collection.is_a?(Vedeu::Repositories::Collection)
|
31
|
+
collection
|
30
32
|
|
31
|
-
|
32
|
-
|
33
|
+
else
|
34
|
+
new(Array(collection), parent, name)
|
33
35
|
|
36
|
+
end
|
34
37
|
end
|
35
|
-
end
|
36
38
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
# Fetch an entry from the collection via index.
|
50
|
-
#
|
51
|
-
# @param value [Fixnum]
|
52
|
-
# @return [void]
|
53
|
-
def [](value)
|
54
|
-
collection[value]
|
55
|
-
end
|
39
|
+
# Returns a new instance of Vedeu::Repositories::Collection.
|
40
|
+
#
|
41
|
+
# @param collection [void]
|
42
|
+
# @param parent [void]
|
43
|
+
# @param name [String|NilClass]
|
44
|
+
# @return [Vedeu::Repositories::Collection]
|
45
|
+
def initialize(collection = [], parent = nil, name = nil)
|
46
|
+
@collection = collection
|
47
|
+
@parent = parent
|
48
|
+
@name = name
|
49
|
+
end
|
56
50
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
alias_method :<<, :add
|
65
|
-
|
66
|
-
# Provides iteration over the collection.
|
67
|
-
#
|
68
|
-
# @param block [Proc]
|
69
|
-
# @return [Enumerator]
|
70
|
-
def each(&block)
|
71
|
-
collection.each(&block)
|
72
|
-
end
|
51
|
+
# Fetch an entry from the collection via index.
|
52
|
+
#
|
53
|
+
# @param value [Fixnum]
|
54
|
+
# @return [void]
|
55
|
+
def [](value)
|
56
|
+
collection[value]
|
57
|
+
end
|
73
58
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
59
|
+
# Adds an entry to the collection.
|
60
|
+
#
|
61
|
+
# @param other [Vedeu::Repositories::Collection]
|
62
|
+
# @return [Vedeu::Repositories::Collection]
|
63
|
+
def add(*other)
|
64
|
+
self.class.new(@collection += other, parent, name)
|
65
|
+
end
|
66
|
+
alias_method :<<, :add
|
67
|
+
|
68
|
+
# Provides iteration over the collection.
|
69
|
+
#
|
70
|
+
# @param block [Proc]
|
71
|
+
# @return [Enumerator]
|
72
|
+
def each(&block)
|
73
|
+
collection.each(&block)
|
74
|
+
end
|
80
75
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
end
|
88
|
-
alias_method :==, :eql?
|
89
|
-
|
90
|
-
# Returns the size of the collection.
|
91
|
-
#
|
92
|
-
# @return [Fixnum]
|
93
|
-
def size
|
94
|
-
collection.size
|
95
|
-
end
|
76
|
+
# Returns a boolean indicating whether the collection is empty.
|
77
|
+
#
|
78
|
+
# @return [Boolean]
|
79
|
+
def empty?
|
80
|
+
collection.empty?
|
81
|
+
end
|
96
82
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
83
|
+
# An object is equal when its values are the same.
|
84
|
+
#
|
85
|
+
# @param other [Vedeu::Repositories::Collection]
|
86
|
+
# @return [Boolean]
|
87
|
+
def eql?(other)
|
88
|
+
self.class == other.class && collection == other.collection
|
89
|
+
end
|
90
|
+
alias_method :==, :eql?
|
91
|
+
|
92
|
+
# Returns the size of the collection.
|
93
|
+
#
|
94
|
+
# @return [Fixnum]
|
95
|
+
def size
|
96
|
+
collection.size
|
97
|
+
end
|
98
|
+
|
99
|
+
# Returns the collection as a String.
|
100
|
+
#
|
101
|
+
# @return [String]
|
102
|
+
def to_s
|
103
|
+
collection.map(&:to_s).join
|
104
|
+
end
|
105
|
+
alias_method :to_str, :to_s
|
106
|
+
|
107
|
+
end # Collection
|
104
108
|
|
105
|
-
end #
|
109
|
+
end # Repositories
|
106
110
|
|
107
111
|
end # Vedeu
|
@@ -1,126 +1,137 @@
|
|
1
1
|
module Vedeu
|
2
2
|
|
3
|
-
|
4
|
-
# class in a repository for later retrieval.
|
5
|
-
#
|
6
|
-
module Model
|
3
|
+
module Repositories
|
7
4
|
|
8
|
-
|
9
|
-
|
10
|
-
# @!attribute [rw] repository
|
11
|
-
# @return [Vedeu::Repository]
|
12
|
-
attr_accessor :repository
|
13
|
-
|
14
|
-
# When {Vedeu::Model} is included in a class, the methods within
|
15
|
-
# this module are included as class methods on that class.
|
5
|
+
# When included into a class, provides the mechanism to store the
|
6
|
+
# class in a repository for later retrieval.
|
16
7
|
#
|
17
|
-
module
|
8
|
+
module Model
|
18
9
|
|
19
|
-
|
20
|
-
# @return [Vedeu::Repository]
|
21
|
-
attr_reader :repository
|
10
|
+
include Vedeu::Common
|
22
11
|
|
23
|
-
#
|
24
|
-
#
|
25
|
-
|
26
|
-
#
|
27
|
-
# @param attributes [Hash] A collection of attributes specific
|
28
|
-
# to the model.
|
29
|
-
# @param block [Proc] The block passed to the build method.
|
30
|
-
# @return [Object] An instance of the model.
|
31
|
-
def build(attributes = {}, &block)
|
32
|
-
attributes = defaults.merge!(attributes)
|
33
|
-
|
34
|
-
model = new(attributes)
|
35
|
-
model.deputy(attributes[:client]).instance_eval(&block) if block_given?
|
36
|
-
model
|
37
|
-
end
|
12
|
+
# @!attribute [rw] repository
|
13
|
+
# @return [Vedeu::Repositories::Repository]
|
14
|
+
attr_accessor :repository
|
38
15
|
|
39
|
-
#
|
16
|
+
# When {Vedeu::Repositories::Model} is included in a class, the
|
17
|
+
# methods within this module are included as class methods on
|
18
|
+
# that class.
|
40
19
|
#
|
41
|
-
|
20
|
+
module ClassMethods
|
21
|
+
|
22
|
+
# @!attribute [r] repository
|
23
|
+
# @return [Vedeu::Repositories::Repository]
|
24
|
+
attr_reader :repository
|
25
|
+
|
26
|
+
# Build models using a simple DSL when a block is given,
|
27
|
+
# otherwise returns a new instance of the class including this
|
28
|
+
# module.
|
29
|
+
#
|
30
|
+
# @param attributes [Hash] A collection of attributes specific
|
31
|
+
# to the model.
|
32
|
+
# @param block [Proc] The block passed to the build method.
|
33
|
+
# @return [Object] An instance of the model.
|
34
|
+
def build(attributes = {}, &block)
|
35
|
+
attributes = defaults.merge!(attributes)
|
36
|
+
|
37
|
+
model = new(attributes)
|
38
|
+
|
39
|
+
if block_given?
|
40
|
+
model.deputy(attributes[:client]).instance_eval(&block)
|
41
|
+
end
|
42
|
+
|
43
|
+
model
|
44
|
+
end
|
45
|
+
|
46
|
+
# Fetch an instance of a repository's model by name.
|
47
|
+
#
|
48
|
+
# @param name [String]
|
49
|
+
# @return [void]
|
50
|
+
def by_name(name)
|
51
|
+
repository.by_name(name) if repository
|
52
|
+
end
|
53
|
+
|
54
|
+
# Provide a convenient way to define the child or children of
|
55
|
+
# a model.
|
56
|
+
#
|
57
|
+
# @param klass [Class] The member (singular) or collection
|
58
|
+
# (multiple) class name for the respective model.
|
59
|
+
# @return [void]
|
60
|
+
def child(klass)
|
61
|
+
send(:define_method, __callee__) { klass }
|
62
|
+
end
|
63
|
+
alias_method :member, :child
|
64
|
+
alias_method :collection, :child
|
65
|
+
|
66
|
+
# Allow models to specify their repository using a class
|
67
|
+
# method.
|
68
|
+
#
|
69
|
+
# @param klass [void]
|
70
|
+
# @return [void]
|
71
|
+
def repo(klass)
|
72
|
+
@repository = klass
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
# The default values for a new instance of this class.
|
78
|
+
#
|
79
|
+
# @return [Hash<Symbol => NilClass, String>]
|
80
|
+
def defaults
|
81
|
+
{
|
82
|
+
client: nil,
|
83
|
+
name: '',
|
84
|
+
}
|
85
|
+
end
|
86
|
+
|
87
|
+
end # ClassMethods
|
88
|
+
|
89
|
+
# When this module is included in a class, provide ClassMethods
|
90
|
+
# as class methods for the class.
|
91
|
+
#
|
92
|
+
# @param klass [Class]
|
42
93
|
# @return [void]
|
43
|
-
def
|
44
|
-
|
94
|
+
def self.included(klass)
|
95
|
+
klass.send(:extend, ClassMethods)
|
45
96
|
end
|
46
97
|
|
47
|
-
#
|
48
|
-
# model.
|
98
|
+
# Returns a DSL instance responsible for defining the DSL
|
99
|
+
# methods of this model.
|
49
100
|
#
|
50
|
-
# @param
|
51
|
-
#
|
52
|
-
#
|
53
|
-
|
54
|
-
|
101
|
+
# @param client [Object|NilClass] The client binding represents
|
102
|
+
# the client application object that is currently invoking a
|
103
|
+
# DSL method. It is required so that we can send messages to
|
104
|
+
# the client application object should we need to.
|
105
|
+
# @return [void] The DSL instance for this model.
|
106
|
+
def deputy(client = nil)
|
107
|
+
Object.const_get(dsl_class).new(self, client)
|
55
108
|
end
|
56
|
-
alias_method :member, :child
|
57
|
-
alias_method :collection, :child
|
58
109
|
|
59
|
-
#
|
60
|
-
#
|
61
|
-
|
62
|
-
|
63
|
-
def repo(klass)
|
64
|
-
@repository = klass
|
110
|
+
# @todo Perhaps some validation could be added here?
|
111
|
+
# @return [void] The model instance stored in the repository.
|
112
|
+
def store
|
113
|
+
repository.store(self) # if valid?
|
65
114
|
end
|
66
115
|
|
67
116
|
private
|
68
117
|
|
69
|
-
#
|
118
|
+
# Returns the DSL class name responsible for this model.
|
70
119
|
#
|
71
|
-
# @return [
|
72
|
-
def
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
120
|
+
# @return [String]
|
121
|
+
def dsl_class
|
122
|
+
case demodulize(self.class.name)
|
123
|
+
when 'Border' then 'Vedeu::Borders::DSL'
|
124
|
+
when 'Buffer' then 'Vedeu::Buffers::DSL'
|
125
|
+
when 'Geometry' then 'Vedeu::Geometry::DSL'
|
126
|
+
when 'Menu' then 'Vedeu::Menus::DSL'
|
127
|
+
# when 'ModelTestClass' then 'Vedeu::Repositories::ModelTestClass::DSL'
|
128
|
+
else
|
129
|
+
'Vedeu::DSL::' + demodulize(self.class.name)
|
130
|
+
end
|
77
131
|
end
|
78
132
|
|
79
|
-
end #
|
80
|
-
|
81
|
-
# When this module is included in a class, provide ClassMethods as
|
82
|
-
# class methods for the class.
|
83
|
-
#
|
84
|
-
# @param klass [Class]
|
85
|
-
# @return [void]
|
86
|
-
def self.included(klass)
|
87
|
-
klass.send(:extend, ClassMethods)
|
88
|
-
end
|
89
|
-
|
90
|
-
# Returns a DSL instance responsible for defining the DSL methods
|
91
|
-
# of this model.
|
92
|
-
#
|
93
|
-
# @param client [Object|NilClass] The client binding represents
|
94
|
-
# the client application object that is currently invoking a DSL
|
95
|
-
# method. It is required so that we can send messages to the
|
96
|
-
# client application object should we need to.
|
97
|
-
# @return [void] The DSL instance for this model.
|
98
|
-
def deputy(client = nil)
|
99
|
-
Object.const_get(dsl_class).new(self, client)
|
100
|
-
end
|
101
|
-
|
102
|
-
# @todo Perhaps some validation could be added here?
|
103
|
-
# @return [void] The model instance stored in the repository.
|
104
|
-
def store
|
105
|
-
repository.store(self) # if valid?
|
106
|
-
end
|
107
|
-
|
108
|
-
private
|
109
|
-
|
110
|
-
# Returns the DSL class name responsible for this model.
|
111
|
-
#
|
112
|
-
# @return [String]
|
113
|
-
def dsl_class
|
114
|
-
case demodulize(self.class.name)
|
115
|
-
when 'Border' then 'Vedeu::Borders::DSL'
|
116
|
-
when 'Buffer' then 'Vedeu::Buffers::DSL'
|
117
|
-
when 'Geometry' then 'Vedeu::Geometry::DSL'
|
118
|
-
when 'Menu' then 'Vedeu::Menus::DSL'
|
119
|
-
else
|
120
|
-
'Vedeu::DSL::' + demodulize(self.class.name)
|
121
|
-
end
|
122
|
-
end
|
133
|
+
end # Model
|
123
134
|
|
124
|
-
end #
|
135
|
+
end # Repositories
|
125
136
|
|
126
137
|
end # Vedeu
|
@@ -1,72 +1,76 @@
|
|
1
1
|
module Vedeu
|
2
2
|
|
3
|
-
|
4
|
-
# convenience methods for them.
|
5
|
-
#
|
6
|
-
module Registerable
|
3
|
+
module Repositories
|
7
4
|
|
8
|
-
#
|
9
|
-
|
5
|
+
# Repositories contain registerables, this module provides
|
6
|
+
# convenience methods for them.
|
7
|
+
#
|
8
|
+
module Registerable
|
10
9
|
|
11
|
-
#
|
12
|
-
|
13
|
-
# @param klass [Class]
|
14
|
-
# @return [Symbol]
|
15
|
-
def null(klass)
|
16
|
-
define_method(:null_model) { klass }
|
17
|
-
end
|
10
|
+
# These class methods are mixed into the repository.
|
11
|
+
module ClassMethods
|
18
12
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
13
|
+
# The null model is used when the repository cannot be found.
|
14
|
+
#
|
15
|
+
# @param klass [Class]
|
16
|
+
# @return [Symbol]
|
17
|
+
def null(klass)
|
18
|
+
define_method(:null_model) { klass }
|
19
|
+
end
|
27
20
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
Vedeu::Repositories.register(klass.repository)
|
21
|
+
# The real model is the usual model to use for a given
|
22
|
+
# repository.
|
23
|
+
#
|
24
|
+
# @param klass [Class]
|
25
|
+
# @return [Symbol]
|
26
|
+
def real(klass)
|
27
|
+
define_method(:model) { instance_variable_set('@model', klass) }
|
36
28
|
end
|
37
|
-
end
|
38
29
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
end
|
30
|
+
# Register a repository for storing models.
|
31
|
+
#
|
32
|
+
# @param model [Class]
|
33
|
+
# @param storage [Class|Hash]
|
34
|
+
# @return [Vedeu::Repositories::Repository]
|
35
|
+
def register(model = nil, storage = {})
|
36
|
+
new(model, storage).tap do |klass|
|
37
|
+
Vedeu::Repositories.register(klass.repository)
|
38
|
+
end
|
39
|
+
end
|
50
40
|
|
51
|
-
|
41
|
+
# Returns the repositories registered.
|
42
|
+
#
|
43
|
+
# @note
|
44
|
+
# If the repository is 'Geometries', for example, then
|
45
|
+
# @models will be either an empty Geometries repository or
|
46
|
+
# the collection of stored models.
|
47
|
+
#
|
48
|
+
# @return [void]
|
49
|
+
def repository
|
50
|
+
@models ||= reset!
|
51
|
+
end
|
52
|
+
|
53
|
+
# Remove all stored models from the repository.
|
54
|
+
#
|
55
|
+
# @return [void]
|
56
|
+
def reset!
|
57
|
+
@models = register
|
58
|
+
end
|
59
|
+
alias_method :reset, :reset!
|
60
|
+
|
61
|
+
end # ClassMethods
|
62
|
+
|
63
|
+
# When this module is included in a class, provide ClassMethods
|
64
|
+
# as class methods for the class.
|
52
65
|
#
|
66
|
+
# @param klass [Class]
|
53
67
|
# @return [void]
|
54
|
-
def
|
55
|
-
|
68
|
+
def self.included(klass)
|
69
|
+
klass.send(:extend, ClassMethods)
|
56
70
|
end
|
57
|
-
alias_method :reset, :reset!
|
58
71
|
|
59
|
-
end #
|
60
|
-
|
61
|
-
# When this module is included in a class, provide ClassMethods as
|
62
|
-
# class methods for the class.
|
63
|
-
#
|
64
|
-
# @param klass [Class]
|
65
|
-
# @return [void]
|
66
|
-
def self.included(klass)
|
67
|
-
klass.send(:extend, ClassMethods)
|
68
|
-
end
|
72
|
+
end # Registerable
|
69
73
|
|
70
|
-
end #
|
74
|
+
end # Repositories
|
71
75
|
|
72
76
|
end # Vedeu
|