hexx-storage 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +2 -0
- data/.gitignore +9 -0
- data/.metrics +9 -0
- data/.rspec +2 -0
- data/.rubocop.yml +2 -0
- data/.travis.yml +12 -0
- data/.yardopts +3 -0
- data/Gemfile +12 -0
- data/Guardfile +14 -0
- data/LICENSE +21 -0
- data/README.md +351 -0
- data/Rakefile +22 -0
- data/config/metrics/STYLEGUIDE +230 -0
- data/config/metrics/cane.yml +5 -0
- data/config/metrics/churn.yml +6 -0
- data/config/metrics/flay.yml +2 -0
- data/config/metrics/metric_fu.yml +13 -0
- data/config/metrics/reek.yml +1 -0
- data/config/metrics/roodi.yml +24 -0
- data/config/metrics/rubocop.yml +73 -0
- data/config/metrics/saikuro.yml +3 -0
- data/config/metrics/simplecov.yml +8 -0
- data/config/metrics/yardstick.yml +37 -0
- data/hexx-storage.gemspec +28 -0
- data/lib/hexx-storage.rb +20 -0
- data/lib/hexx/storage.rb +17 -0
- data/lib/hexx/storage/base.rb +108 -0
- data/lib/hexx/storage/patches.rb +135 -0
- data/lib/hexx/storage/repositories.rb +40 -0
- data/lib/hexx/storage/repositories/base.rb +70 -0
- data/lib/hexx/storage/repositories/memory.rb +33 -0
- data/lib/hexx/storage/repositories/sql.rb +78 -0
- data/lib/hexx/storage/version.rb +13 -0
- data/spec/integration/storage.yml +9 -0
- data/spec/integration/storage_spec.rb +56 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/tests/storage/base_spec.rb +178 -0
- data/spec/tests/storage/patches_spec.rb +202 -0
- data/spec/tests/storage/repositories/base_spec.rb +120 -0
- data/spec/tests/storage/repositories/memory_spec.rb +32 -0
- data/spec/tests/storage/repositories/sql_spec.rb +180 -0
- data/spec/tests/storage/repositories_spec.rb +66 -0
- data/spec/tests/storage_spec.rb +24 -0
- metadata +168 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d74c167834036021a713089804dad4d1ee5fb26a
|
4
|
+
data.tar.gz: 3c6a2ea6a487df2ce141c48358868e446cfc0dd8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b7297c164f8a7596015313b3ead43c89043814732e29126c585f4ad8e45089d447d87a799fcb05e6321b9bfb9d03959719d2eceb650a7c02b4f781536f64bed0
|
7
|
+
data.tar.gz: 892e9681876e62f70f87678fcf1859b44a8fa4180bb5145d6f65927e9b4b98d4cee09d3c3875eb72503d19d685e8d7e5f790997c2f950fcfeb9aeceeec2b393d
|
data/.coveralls.yml
ADDED
data/.gitignore
ADDED
data/.metrics
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
# Settings for metric_fu and its packages are collected in the `config/metrics`
|
2
|
+
# and loaded by the Hexx::Suit::Metrics::MetricFu.
|
3
|
+
|
4
|
+
begin
|
5
|
+
require "hexx-suit"
|
6
|
+
Hexx::Suit::Metrics::MetricFu.load
|
7
|
+
rescue LoadError
|
8
|
+
puts "The 'hexx-suit' gem is not installed"
|
9
|
+
end
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
---
|
2
|
+
language: ruby
|
3
|
+
before_script:
|
4
|
+
- psql -c 'create database rom;' -U postgres -w
|
5
|
+
bundler_args: --without metrics
|
6
|
+
script: rake test:coverage:run
|
7
|
+
rvm:
|
8
|
+
# - '2.0' # doesn't support "def foo(bar:); end"
|
9
|
+
- '2.1'
|
10
|
+
- '2.2'
|
11
|
+
# - rbx-2 # doesn't support refinements
|
12
|
+
# - jruby-9.0.0.0.pre1 # doesn't support refinements
|
data/.yardopts
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
guard :rspec, cmd: "bundle exec rspec" do
|
4
|
+
|
5
|
+
watch(%r{^lib/hexx/(.+)\.rb$}) do |m|
|
6
|
+
"spec/tests/#{ m[1] }_spec.rb"
|
7
|
+
end
|
8
|
+
|
9
|
+
watch(%r{^spec/.+_spec\.rb$})
|
10
|
+
|
11
|
+
watch("lib/hexx-storage.rb") { "spec" }
|
12
|
+
watch("spec/spec_helper.rb") { "spec" }
|
13
|
+
|
14
|
+
end # guard :rspec
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2015 Andrew Kozin (nepalez), andrew.kozin@gmail.com
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,351 @@
|
|
1
|
+
Hexx::Storage
|
2
|
+
=============
|
3
|
+
|
4
|
+
[![Gem Version](https://img.shields.io/gem/v/hexx-storage.svg?style=flat)][gem]
|
5
|
+
[![Build Status](https://img.shields.io/travis/nepalez/hexx-storage/master.svg?style=flat)][travis]
|
6
|
+
[![Dependency Status](https://img.shields.io/gemnasium/nepalez/hexx-storage.svg?style=flat)][gemnasium]
|
7
|
+
[![Code Climate](https://img.shields.io/codeclimate/github/nepalez/hexx-storage.svg?style=flat)][codeclimate]
|
8
|
+
[![Coverage](https://img.shields.io/coveralls/nepalez/hexx-storage.svg?style=flat)][coveralls]
|
9
|
+
[![Inline docs](http://inch-ci.org/github/nepalez/hexx-storage.svg)][inch]
|
10
|
+
|
11
|
+
[codeclimate]: https://codeclimate.com/github/nepalez/hexx-storage
|
12
|
+
[coveralls]: https://coveralls.io/r/nepalez/hexx-storage
|
13
|
+
[gem]: https://rubygems.org/gems/hexx-storage
|
14
|
+
[gemnasium]: https://gemnasium.com/nepalez/hexx-storage
|
15
|
+
[travis]: https://travis-ci.org/nepalez/hexx-storage
|
16
|
+
[inch]: https://inch-ci.org/github/nepalez/hexx-storage
|
17
|
+
|
18
|
+
The module provides additional sugar for setting [sweety ROM] from yml.
|
19
|
+
|
20
|
+
* [Synopsis](#synopsis)
|
21
|
+
* [Extended example](#extended-example)
|
22
|
+
* [Installation](#installation)
|
23
|
+
* [Compatibility](#compatibility)
|
24
|
+
* [MIT LICENSE](LICENSE)
|
25
|
+
|
26
|
+
[sweety ROM]: http://rom-rb.org
|
27
|
+
|
28
|
+
Synopsis
|
29
|
+
--------
|
30
|
+
|
31
|
+
Providing some settings exist:
|
32
|
+
|
33
|
+
```yaml
|
34
|
+
# application_path/config/rom/my_gem.yml
|
35
|
+
---
|
36
|
+
test: # required environment level
|
37
|
+
foo: # required repository name level
|
38
|
+
adapter: :memory
|
39
|
+
bar:
|
40
|
+
adapter: :memory
|
41
|
+
log: "tmp/logs/my_gem/test/bar.log"
|
42
|
+
production:
|
43
|
+
foo:
|
44
|
+
adapter: :memory
|
45
|
+
bar:
|
46
|
+
adapter: :sql
|
47
|
+
uri: "postgres://localhost/rom"
|
48
|
+
user: "foo"
|
49
|
+
password: "bar"
|
50
|
+
log: "tmp/logs/my_gem/bar.log"
|
51
|
+
```
|
52
|
+
|
53
|
+
Load them to the storage:
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
require "hexx-storage"
|
57
|
+
|
58
|
+
storage = Hexx::Storage.setup
|
59
|
+
|
60
|
+
# root path of the application than carries settings
|
61
|
+
storage.root = "application_path"
|
62
|
+
# load settings from file, relative to that root
|
63
|
+
storage.load "config/rom/my_gem.yml", env: :production
|
64
|
+
# add migrations paths to some repositories
|
65
|
+
storage[:bar].migrations = "my_gem/db/migrations/bar"
|
66
|
+
```
|
67
|
+
|
68
|
+
And check the results:
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
# final settings for the ROM.setup
|
72
|
+
storage.settings
|
73
|
+
# => {
|
74
|
+
# foo: [:memory, "foo"],
|
75
|
+
# bar: [
|
76
|
+
# :sql,
|
77
|
+
# [
|
78
|
+
# #<Sequel::PG::Database: ...>,
|
79
|
+
# migrator: #<ROM::SQL::Migration::Migrator ...>
|
80
|
+
# ]
|
81
|
+
# ]
|
82
|
+
# }
|
83
|
+
```
|
84
|
+
|
85
|
+
Some more details:
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
# names of repositories:
|
89
|
+
storage.keys # => [:foo, :bar]
|
90
|
+
|
91
|
+
# uri-s
|
92
|
+
storage.values.map(&:uri)
|
93
|
+
# => [nil, "postgres://localhost/rom"]
|
94
|
+
|
95
|
+
# additional options (except for adapter, uri and log)
|
96
|
+
storage[:bar].options
|
97
|
+
# => { user: "foo", password: "bar" }
|
98
|
+
|
99
|
+
# loggers (from established root and log)
|
100
|
+
storage[:foo].logger
|
101
|
+
# => nil (no logger is set)
|
102
|
+
storage[:bar].logger
|
103
|
+
# => #<Logger
|
104
|
+
# @logdev= <Logger::LogDevice
|
105
|
+
# @filename="application_path/tmp/logs/my_gem/bar.log"
|
106
|
+
# >
|
107
|
+
# >
|
108
|
+
```
|
109
|
+
|
110
|
+
Settings specific for `:sql` adapter:
|
111
|
+
|
112
|
+
```ruby
|
113
|
+
# established Sequel connections
|
114
|
+
storage[:foo].conn
|
115
|
+
# => nil (adapter is not the :sql)
|
116
|
+
storage[:bar].conn
|
117
|
+
# => #<Sequel::PG::Database: "postgres://localhost/rom">
|
118
|
+
|
119
|
+
# if the logger is set, it is authomatically added to the connection
|
120
|
+
storage[:bar].conn.loggers
|
121
|
+
# => [#<Logger ...>]
|
122
|
+
|
123
|
+
# migrators
|
124
|
+
storage[:foo].migrator
|
125
|
+
# => nil (adapter is not the :sql)
|
126
|
+
storage[:bar].migrator
|
127
|
+
# => #<ROM::SQL::Migration::Migrator
|
128
|
+
# @connection=#<Sequel::PG::Database: "postgres://localhost/rom">
|
129
|
+
# @path="my_gem/db/migrations/bar"
|
130
|
+
# >
|
131
|
+
```
|
132
|
+
|
133
|
+
Extended Example
|
134
|
+
----------------
|
135
|
+
|
136
|
+
Below is example of setings for the `my_gem` gem used inside the application.
|
137
|
+
|
138
|
+
The example consists of 3 parts:
|
139
|
+
* [MyGem](#mygem) the ROM is set up for
|
140
|
+
* [Application](#application) the ROM is set up from
|
141
|
+
* [Dummy App](#dummy-app) for testing the gem
|
142
|
+
|
143
|
+
### MyGem
|
144
|
+
|
145
|
+
The loader:
|
146
|
+
|
147
|
+
```ruby
|
148
|
+
# my_gem_path/lib/my_gem.rb
|
149
|
+
module MyGem
|
150
|
+
# loads patches (refinements) to external classes (Ruby core, stdlib etc.)
|
151
|
+
require_relative "my_gem/patches"
|
152
|
+
# loads and initializes the gem's settings
|
153
|
+
require_relative "my_gem/settings"
|
154
|
+
# loads the core part of the domain (value objects, entities, policies etc.),
|
155
|
+
# that don't use the persistency layer
|
156
|
+
require_relative "my_gem/core"
|
157
|
+
# loads the ROM-based persistency layer
|
158
|
+
# (sets ROM up with relations, mappers, and commands)
|
159
|
+
require_relative "my_gem/storage"
|
160
|
+
# loads the domain API (service objects that backs on both the domain core,
|
161
|
+
# and the persistency layer)
|
162
|
+
require_relative "my_gem/api"
|
163
|
+
end
|
164
|
+
```
|
165
|
+
|
166
|
+
The `Settings` provides a singleton object to collect all module settings, including the storage and other external dependencies.
|
167
|
+
|
168
|
+
After definition it loads the initializer, provided by an [application](#application).
|
169
|
+
|
170
|
+
```ruby
|
171
|
+
# my_gem_path/lib/my_gem/settings.rb
|
172
|
+
require "hexx-storage"
|
173
|
+
|
174
|
+
module MyGem
|
175
|
+
module Settings
|
176
|
+
include Singleton
|
177
|
+
|
178
|
+
def self.configure
|
179
|
+
yield self if block_given?
|
180
|
+
end
|
181
|
+
|
182
|
+
def self.[](name)
|
183
|
+
send_public name
|
184
|
+
end
|
185
|
+
|
186
|
+
def storage
|
187
|
+
@storage ||= Hexx::Storage.setup
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
# Initializes the dependencies from the initializer, provided by application.
|
192
|
+
require File.join ENV["PATH_TO_INITIALIZERS"], "my_gem.rb"
|
193
|
+
end
|
194
|
+
```
|
195
|
+
|
196
|
+
The persistency layer backs on the `ROM` module, whose settings has been initialized before.
|
197
|
+
|
198
|
+
```ruby
|
199
|
+
# my_gem_path/lib/my_gem/storage.rb
|
200
|
+
|
201
|
+
require "rom"
|
202
|
+
|
203
|
+
module MyGem
|
204
|
+
# Takes storage from the initialized settings
|
205
|
+
storage = Settings[:storage]
|
206
|
+
|
207
|
+
# Sets path to local migrations (that's why they are assigned separately)
|
208
|
+
# (no need to copy migrations to the application, like Rails does)
|
209
|
+
storage[:default].migrations = File.join "storage/migrations"
|
210
|
+
|
211
|
+
# Sets ROM up with the initialized storage settings
|
212
|
+
ROM.setup(storage.settings)
|
213
|
+
|
214
|
+
# Loads ROM relations, commands and mappers, that depends from
|
215
|
+
# value objects and entities, that are loaded as parts of the
|
216
|
+
# core part of the module (see the loading sequence in the loader).
|
217
|
+
|
218
|
+
# ...
|
219
|
+
|
220
|
+
# Finalizes the ROM and sets established loggers to its repositories
|
221
|
+
ROM.finalize
|
222
|
+
ROM.env.repositories[:default].use_logger storage[:default].logger
|
223
|
+
|
224
|
+
# Memoizes the ROM environment that can be reset by the application
|
225
|
+
STORAGE = ROM.env
|
226
|
+
end
|
227
|
+
```
|
228
|
+
|
229
|
+
The `RSpec` helper loads `my_gem` inside the
|
230
|
+
[dummy application](#the-dummy-app-for-the-mygem):
|
231
|
+
|
232
|
+
```ruby
|
233
|
+
# my_gem_path/spec/spec_helper.rb
|
234
|
+
require "dummy/lib/dummy"
|
235
|
+
```
|
236
|
+
|
237
|
+
### Application
|
238
|
+
|
239
|
+
The loader:
|
240
|
+
|
241
|
+
```ruby
|
242
|
+
# application_path/lib/application.rb
|
243
|
+
|
244
|
+
# The application knows the :sql adapter will be used
|
245
|
+
require "rom-sql"
|
246
|
+
|
247
|
+
# Sets path to initializers
|
248
|
+
ENV["PATH_TO_INITIALIZERS"] = File.expand_path "../config/initializers"
|
249
|
+
|
250
|
+
# Gives control to the gem loader
|
251
|
+
require "my_gem"
|
252
|
+
```
|
253
|
+
|
254
|
+
The `my_gem` initializer inside the application:
|
255
|
+
|
256
|
+
```ruby
|
257
|
+
# application_path/config/initializers/my_gem.rb
|
258
|
+
MyGem::Settings.configure do |config|
|
259
|
+
config.storage.root = File.join ".."
|
260
|
+
config.storage.load "config/rom/my_gem.yml", env: ENV["CURRENT_ENV"]
|
261
|
+
end
|
262
|
+
```
|
263
|
+
|
264
|
+
The `my_gem` storage's settings inside the application:
|
265
|
+
|
266
|
+
```yaml
|
267
|
+
# application_path/config/rom/my_gem.yml
|
268
|
+
---
|
269
|
+
test:
|
270
|
+
default:
|
271
|
+
adapter: :memory
|
272
|
+
uri: "my_gem"
|
273
|
+
log: "tmp/logs/test/my_gem.test.log" # relative to application root
|
274
|
+
production:
|
275
|
+
default:
|
276
|
+
adapter: :sql
|
277
|
+
uri: "postgres://localhost/rom" # whatever
|
278
|
+
log: "tmp/logs/production/my_gem.log" # relative to application root
|
279
|
+
```
|
280
|
+
|
281
|
+
### Dummy App
|
282
|
+
|
283
|
+
The loader:
|
284
|
+
|
285
|
+
```ruby
|
286
|
+
# my_gem_path/spec/dummy/lib/dummy.rb
|
287
|
+
|
288
|
+
# Sets initializers folder relative to the Dummy
|
289
|
+
ENV["PATH_TO_INITIALIZERS"] = File
|
290
|
+
.expand_path "../spec/dummy/config/initializers"
|
291
|
+
|
292
|
+
require "my_gem"
|
293
|
+
```
|
294
|
+
|
295
|
+
The `MyGem` initializer:
|
296
|
+
|
297
|
+
```ruby
|
298
|
+
# my_gem_path/spec/dummy/config/initializers/my_module.rb
|
299
|
+
MyGem::Settings.configure do |config|
|
300
|
+
config.storage.root = File.join "../spec/dummy"
|
301
|
+
config.storage.load "config/rom/my_gem.yml", env: :test
|
302
|
+
end
|
303
|
+
```
|
304
|
+
|
305
|
+
The `ROM` storage settings for `MyGem`:
|
306
|
+
|
307
|
+
```yaml
|
308
|
+
# my_gem_path/spec/dummy/config/rom/my_gem.yml
|
309
|
+
---
|
310
|
+
test:
|
311
|
+
default:
|
312
|
+
adapter: :memory
|
313
|
+
log: "../../tmp/logs/test.log" # relative to the Dummy root
|
314
|
+
```
|
315
|
+
|
316
|
+
Installation
|
317
|
+
------------
|
318
|
+
|
319
|
+
Add this line to your application's Gemfile:
|
320
|
+
|
321
|
+
```ruby
|
322
|
+
# Gemfile
|
323
|
+
gem "hexx-storage", git: "https://github.com/nepalez/hexx-storage"
|
324
|
+
```
|
325
|
+
|
326
|
+
Then execute:
|
327
|
+
|
328
|
+
```
|
329
|
+
bundle
|
330
|
+
```
|
331
|
+
|
332
|
+
Compatibility
|
333
|
+
-------------
|
334
|
+
|
335
|
+
Tested under MRI 2.1+
|
336
|
+
|
337
|
+
Limitations:
|
338
|
+
|
339
|
+
* MRI 2.0 doesn't support syntax `def foo(bar:)`
|
340
|
+
* both JRuby and Rubinius don't support [refinements]
|
341
|
+
|
342
|
+
Uses [RSpec] 3.0+ for testing and [hexx-suit] for dev/test tools collection.
|
343
|
+
|
344
|
+
[refinements]: http://ruby-doc.org/core-2.1.1/doc/syntax/refinements_rdoc.html
|
345
|
+
[RSpec]: http://rspec.info/
|
346
|
+
[hexx-suit]: http://github.com/nepalez/hexx-suit
|
347
|
+
|
348
|
+
License
|
349
|
+
-------
|
350
|
+
|
351
|
+
See the [MIT LICENSE](LICENSE).
|