paneron-register 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.irbrc +1 -0
- data/.pryrc +1 -0
- data/README.adoc +163 -19
- data/docs/examples.adoc +91 -0
- data/lib/paneron/register/hierarchical.rb +24 -0
- data/lib/paneron/register/raw/data_set.rb +349 -34
- data/lib/paneron/register/raw/item.rb +147 -23
- data/lib/paneron/register/raw/item_class.rb +140 -23
- data/lib/paneron/register/raw/register.rb +452 -63
- data/lib/paneron/register/register.rb +0 -2
- data/lib/paneron/register/root_finder.rb +24 -0
- data/lib/paneron/register/validatable.rb +40 -0
- data/lib/paneron/register/version.rb +1 -1
- data/lib/paneron/register/writeable.rb +96 -0
- data/lib/paneron/register.rb +5 -0
- data/paneron-register.gemspec +1 -0
- metadata +21 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 560320c2a03e90f346dafccc8a2088c4637ce9d80bf789a01b79d6711409b812
|
4
|
+
data.tar.gz: 6a2996fe23f059d525a1ecb8b2d71384a22ba67adcfba27814855c5a2a18fc37
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9885fa28ebdcf9c5dfc8899b125480e88d4876cba6473cff144e0f2dc5178d5478a8478b92eb44fd31e638d1a94a68362dd0bef9e324f51919189da601d904eb
|
7
|
+
data.tar.gz: ef8c656a0d9c76bd1e38b43befc4689045e00e4cc88a966b9734ef4e2dd473139a037eeabc0f2e784743878748d572c5ac56290b3c8e9be56cfcecf1f23b2352
|
data/.irbrc
CHANGED
data/.pryrc
CHANGED
data/README.adoc
CHANGED
@@ -15,75 +15,219 @@ gem install paneron-register
|
|
15
15
|
|
16
16
|
== Usage
|
17
17
|
|
18
|
-
|
18
|
+
[source,ruby]
|
19
|
+
----
|
19
20
|
require "paneron/register"
|
21
|
+
include Paneron::Register
|
20
22
|
|
21
23
|
# Initialize a new data set
|
22
24
|
# This example uses a working copy of Paneron's data set.
|
23
|
-
# =>
|
24
|
-
raw_data_set =
|
25
|
+
# => Raw::DataSet
|
26
|
+
raw_data_set = Raw::DataSet.new(
|
25
27
|
"/Users/username/Library/Application Support/Electron/working_copies/00000000-0001-0000-0000-000000000001",
|
26
28
|
"data_set_name-1"
|
27
29
|
)
|
28
30
|
|
29
|
-
# =>
|
31
|
+
# => DataSet < Lutaml::Model::Serializable
|
30
32
|
data_set = raw_data_set.to_lutaml
|
31
33
|
|
32
34
|
# Alternatively, initialize a new register:
|
33
35
|
# => Paneron::Register::Raw::Register
|
34
|
-
raw_register =
|
36
|
+
raw_register = Raw::Register.new(
|
35
37
|
"/Users/username/Library/Application Support/Electron/working_copies/00000000-0001-0000-0000-000000000001",
|
36
38
|
)
|
37
39
|
|
38
40
|
# This example uses a Git URL
|
39
|
-
# =>
|
40
|
-
raw_register =
|
41
|
+
# => Raw::Register
|
42
|
+
raw_register = Raw::Register.from_git(
|
41
43
|
"https://github.com/isogr/registry",
|
42
44
|
|
43
45
|
# optional. For previously cloned repos, pulls from repo iff true.
|
44
46
|
# update: true,
|
45
47
|
)
|
46
48
|
|
47
|
-
# =>
|
49
|
+
# => Raw::DataSet
|
48
50
|
raw_data_set = raw_register.data_sets("data_set_name-1")
|
49
51
|
|
50
|
-
# =>
|
52
|
+
# => DataSet < Lutaml::Model::Serializable
|
51
53
|
data_set = raw_data_set.to_lutaml
|
52
54
|
|
53
55
|
# Get all item class objects
|
54
|
-
# => { item-class-name:
|
56
|
+
# => { item-class-name: Raw::ItemClass }
|
55
57
|
raw_data_set.item_classes
|
56
58
|
|
57
|
-
# => [
|
59
|
+
# => [ ItemClass ]
|
58
60
|
data_set.item_classes
|
59
61
|
|
60
62
|
# Get a specific item class object
|
61
|
-
# =>
|
63
|
+
# => Raw::ItemClass
|
62
64
|
raw_item_class = raw_data_set.item_classes("item-class-1")
|
63
65
|
|
64
|
-
# =>
|
66
|
+
# => ItemClass < Lutaml::Model::Serializable
|
65
67
|
item_class = raw_item_class.to_lutaml
|
66
68
|
|
67
69
|
# Get all item objects in Ruby Hash format
|
68
|
-
# => { item-uuid:
|
70
|
+
# => { item-uuid: Raw::Item }
|
69
71
|
raw_item_class.items
|
70
72
|
|
71
|
-
# => [
|
73
|
+
# => [ Item ]
|
72
74
|
item_class.items
|
73
75
|
|
74
76
|
# Get a specific item property, using normal Ruby Hash methods
|
75
|
-
# =>
|
77
|
+
# => Raw::Item
|
76
78
|
raw_item = raw_item_class.items["00000000-0000-0000-0000-000000000001"]
|
77
79
|
id = raw_item["id"]
|
78
80
|
blob1 = raw_item["data"]["blob1"]
|
79
81
|
|
80
82
|
# Get a specific item property, from a Lutaml object
|
81
|
-
# =>
|
83
|
+
# => Item < Lutaml::Model::Serializable
|
82
84
|
item = raw_item.to_lutaml
|
83
85
|
id = item.to_h["id"]
|
84
86
|
blob1 = item.to_h["data"]["blob1"]
|
85
|
-
|
87
|
+
----
|
88
|
+
|
89
|
+
For more usage examples, see link:docs/examples.adoc[`Examples`^]
|
90
|
+
and related link:spec/worked_examples_spec.rb[`spec/worked_examples_spec.rb`^].
|
91
|
+
|
92
|
+
|
93
|
+
== Development
|
94
|
+
|
95
|
+
Git clone this repository, then install dependencies.
|
96
|
+
|
97
|
+
[source,shell]
|
98
|
+
----
|
99
|
+
git clone https://github.com/paneron/ruby-paneron-register
|
100
|
+
cd ruby-paneron-register
|
101
|
+
bundle install
|
102
|
+
----
|
103
|
+
|
104
|
+
=== Without Nix
|
105
|
+
|
106
|
+
Open development shell (`irb`) with:
|
107
|
+
|
108
|
+
[source,shell]
|
109
|
+
----
|
110
|
+
bundle exec irb
|
111
|
+
----
|
112
|
+
|
113
|
+
Open development shell (`pry`) with:
|
114
|
+
|
115
|
+
[source,shell]
|
116
|
+
----
|
117
|
+
bundle exec pry
|
118
|
+
----
|
119
|
+
|
120
|
+
Run tests with:
|
121
|
+
|
122
|
+
[source,shell]
|
123
|
+
----
|
124
|
+
bundle exec rspec
|
125
|
+
# or
|
126
|
+
bundle exec rake spec
|
127
|
+
----
|
128
|
+
|
129
|
+
Run lint with:
|
130
|
+
|
131
|
+
[source,shell]
|
132
|
+
----
|
133
|
+
bundle exec rubocop
|
134
|
+
----
|
135
|
+
|
136
|
+
Run lint with autocorrect with:
|
137
|
+
|
138
|
+
[source,shell]
|
139
|
+
----
|
140
|
+
bundle exec rubocop -a
|
141
|
+
----
|
142
|
+
|
143
|
+
Release to Rubygem (adds a Git tag, pushes to GitHub and releases to Rubygem) with:
|
144
|
+
|
145
|
+
[source,shell]
|
146
|
+
----
|
147
|
+
bundle exec rake release
|
148
|
+
----
|
149
|
+
|
150
|
+
=== With Nix
|
151
|
+
|
152
|
+
If your system is using Nix, run the following to gain access to shell aliases:
|
153
|
+
|
154
|
+
[source,shell]
|
155
|
+
----
|
156
|
+
nix develop
|
157
|
+
----
|
158
|
+
|
159
|
+
Open development shell (`irb`) with:
|
160
|
+
|
161
|
+
[source,shell]
|
162
|
+
----
|
163
|
+
irb
|
164
|
+
# or
|
165
|
+
console
|
166
|
+
----
|
167
|
+
|
168
|
+
Open development shell (`pry`) with:
|
169
|
+
|
170
|
+
[source,shell]
|
171
|
+
----
|
172
|
+
pry
|
173
|
+
----
|
174
|
+
|
175
|
+
Run tests with:
|
176
|
+
|
177
|
+
[source,shell]
|
178
|
+
----
|
179
|
+
rspec
|
180
|
+
----
|
181
|
+
|
182
|
+
Run lint with:
|
183
|
+
|
184
|
+
[source,shell]
|
185
|
+
----
|
186
|
+
lint
|
187
|
+
# or
|
188
|
+
rubocop
|
189
|
+
----
|
190
|
+
|
191
|
+
Run lint with autocorrect with:
|
192
|
+
|
193
|
+
[source,shell]
|
194
|
+
----
|
195
|
+
lint -a
|
196
|
+
# or
|
197
|
+
rubocop -a
|
198
|
+
----
|
199
|
+
|
200
|
+
Release to Rubygem (adds a Git tag, pushes to GitHub and releases to Rubygem) with:
|
201
|
+
|
202
|
+
[source,shell]
|
203
|
+
----
|
204
|
+
release
|
205
|
+
----
|
206
|
+
|
207
|
+
Update Nix flakes with:
|
208
|
+
|
209
|
+
[source,shell]
|
210
|
+
----
|
211
|
+
update-flakes
|
212
|
+
----
|
213
|
+
|
214
|
+
== Release workflow
|
215
|
+
|
216
|
+
When actually creating a new version for release, do the following:
|
217
|
+
|
218
|
+
. Update the `VERSION` in file link:lib/paneron/register/version.rb[`lib/paneron/register/version.rb`^].
|
219
|
+
. [[:space:]]
|
220
|
+
+
|
221
|
+
[source,shell]
|
222
|
+
----
|
223
|
+
git add lib/paneron/register/version.rb
|
224
|
+
git commit -m 'chore: Release vX.Y.Z' # change X.Y.Z to actual version
|
225
|
+
git push
|
226
|
+
|
227
|
+
# Run rake release
|
228
|
+
bundle exec rake release
|
229
|
+
----
|
86
230
|
|
87
231
|
== License
|
88
232
|
|
89
|
-
See LICENSE.txt
|
233
|
+
See link:LICENSE.txt[`LICENSE.txt`]
|
data/docs/examples.adoc
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
= Examples
|
2
|
+
|
3
|
+
NOTE: Follow link:../spec/worked_examples_spec.rb[`spec/worked_examples_spec.rb`] for continuously integrated examples.
|
4
|
+
|
5
|
+
In this document, you'll find examples of how to use the library.
|
6
|
+
|
7
|
+
The following examples assume this preamble:
|
8
|
+
|
9
|
+
[source,ruby]
|
10
|
+
----
|
11
|
+
require "paneron/register"
|
12
|
+
include Paneron::Register
|
13
|
+
----
|
14
|
+
|
15
|
+
|
16
|
+
== Create a register
|
17
|
+
|
18
|
+
=== From scratch
|
19
|
+
|
20
|
+
[source,ruby]
|
21
|
+
----
|
22
|
+
register = Raw::Register.generate(
|
23
|
+
"/local/path/to/directory/can/be/empty",
|
24
|
+
git_url: "git URL",
|
25
|
+
)
|
26
|
+
|
27
|
+
# Create a data set
|
28
|
+
ds =
|
29
|
+
register.spawn_data_set("data_set_name")
|
30
|
+
|
31
|
+
# Register#save commits the data to git.
|
32
|
+
register.save
|
33
|
+
|
34
|
+
# Register#sync pushes the commits to git remote.
|
35
|
+
register.sync
|
36
|
+
----
|
37
|
+
|
38
|
+
|
39
|
+
=== From an existing Git repository
|
40
|
+
|
41
|
+
[source,ruby]
|
42
|
+
----
|
43
|
+
register = Raw::Register.from_git("git URL")
|
44
|
+
----
|
45
|
+
|
46
|
+
|
47
|
+
== Register an item class
|
48
|
+
|
49
|
+
[source,ruby]
|
50
|
+
----
|
51
|
+
data_set = register.spawn_data_set("data_set_name").save
|
52
|
+
item_class = data_set.spawn_item_class("item_class_name").save
|
53
|
+
----
|
54
|
+
|
55
|
+
== Store a file in the item
|
56
|
+
|
57
|
+
[source,ruby]
|
58
|
+
----
|
59
|
+
item = item_class.spawn_item
|
60
|
+
item.data = "file contents"
|
61
|
+
item.save
|
62
|
+
|
63
|
+
# Take a note of its UUID for future retrieval
|
64
|
+
item_uuid = item.uuid
|
65
|
+
----
|
66
|
+
|
67
|
+
== Write the item to register (sync local to remote)
|
68
|
+
|
69
|
+
[source,ruby]
|
70
|
+
----
|
71
|
+
# Register#sync
|
72
|
+
# Register#sync pushes the commits to git remote.
|
73
|
+
register.sync
|
74
|
+
----
|
75
|
+
|
76
|
+
== Fetch the item for use
|
77
|
+
|
78
|
+
[source,ruby]
|
79
|
+
----
|
80
|
+
# Register.from_git clones the repo to local cache.
|
81
|
+
# It automatically calls `git pull --rebase` to sync with remote.
|
82
|
+
register = Raw::Register.from_git("git URL")
|
83
|
+
item = register.items(item_uuid)
|
84
|
+
----
|
85
|
+
|
86
|
+
== Obtain the file from the item
|
87
|
+
|
88
|
+
[source,ruby]
|
89
|
+
----
|
90
|
+
file = item.data
|
91
|
+
----
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Paneron
|
4
|
+
module Register
|
5
|
+
module Hierarchical
|
6
|
+
# def self.included(base)
|
7
|
+
# base.class_eval do
|
8
|
+
# end
|
9
|
+
# end
|
10
|
+
# Split into parent path and base name
|
11
|
+
|
12
|
+
def self.split_path(full_path)
|
13
|
+
# {
|
14
|
+
# parent_path: File.dirname(full_path),
|
15
|
+
# basename: File.basename(full_path),
|
16
|
+
# }
|
17
|
+
[
|
18
|
+
File.dirname(full_path),
|
19
|
+
File.basename(full_path),
|
20
|
+
]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|