vedeu 0.6.10 → 0.6.11

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