lucarecord 0.2.17 → 0.2.18
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/CHANGELOG.md +8 -0
- data/lib/luca_record/io.rb +54 -36
- data/lib/luca_record/version.rb +1 -1
- data/lib/luca_support/code.rb +5 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63ac71426bdf4eb871884b8b28c5aa363db9d51ef3ca0d84ab92a3fcf127ecde
|
4
|
+
data.tar.gz: 2bc0d6ecde974a2f9ca9c901af5ac714c909f40dd84986746948065a4efb4ed7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f9cf84bfb09080f6f3e8cf15c8fb3cea0d6eca9d69acc10c23cd9b6a681daae9ab641181a928f438c870a438a0c4525c61bfad6a1832a2d148b7a3d37b3d6d3
|
7
|
+
data.tar.gz: be35bd6b0a993b5fde415ba5e1a7b59228106c443594b164fa5df26f1eb284ae0556277b99b25f7697283ac194f6c25ffa7d7d8d3e1bfe2e22b128130f3f9cec
|
data/CHANGELOG.md
CHANGED
@@ -0,0 +1,8 @@
|
|
1
|
+
## LucaRecord 0.2.18
|
2
|
+
|
3
|
+
* `find()`, `create()`, `save()` now supports both of uuid / historical records. If specified `date:` keyword option to `create()`, then generate historical record. `find()`, `save()` identifies with 'id' attribute.
|
4
|
+
|
5
|
+
## LucaRecord 0.2.17
|
6
|
+
|
7
|
+
* Change internal number format to BigDecimal.
|
8
|
+
* Number of Decimal is configurable through `decimal_number` in config.yml(default = 2). `country` setting can also affect.
|
data/lib/luca_record/io.rb
CHANGED
@@ -36,9 +36,9 @@ module LucaRecord # :nodoc:
|
|
36
36
|
open_hashed(basedir, id) do |f|
|
37
37
|
yield load_data(f)
|
38
38
|
end
|
39
|
-
elsif id.length >=
|
40
|
-
|
41
|
-
open_records(basedir,
|
39
|
+
elsif id.length >= 7
|
40
|
+
parts = id.split('/')
|
41
|
+
open_records(basedir, parts[0], parts[1]) do |f, path|
|
42
42
|
yield load_data(f, path)
|
43
43
|
end
|
44
44
|
else
|
@@ -90,26 +90,23 @@ module LucaRecord # :nodoc:
|
|
90
90
|
# of each concrete class.
|
91
91
|
# ----------------------------------------------------------------
|
92
92
|
|
93
|
-
# create
|
94
|
-
|
93
|
+
# create record both of uuid/date identified.
|
94
|
+
#
|
95
|
+
def create(obj, date: nil, codes: nil, basedir: @dirname)
|
95
96
|
validate_keys(obj)
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
# define new transaction ID & write data at once
|
105
|
-
def create_record!(obj, date_obj, codes = nil, basedir = @dirname)
|
106
|
-
gen_record_file!(basedir, date_obj, codes) do |f|
|
107
|
-
f.write(YAML.dump(LucaSupport::Code.readable(obj.sort.to_h)))
|
97
|
+
if date
|
98
|
+
create_record(obj, date, codes, basedir)
|
99
|
+
else
|
100
|
+
obj['id'] = LucaSupport::Code.issue_random_id
|
101
|
+
open_hashed(basedir, obj['id'], 'w') do |f|
|
102
|
+
f.write(YAML.dump(LucaSupport::Code.readable(obj.sort.to_h)))
|
103
|
+
end
|
104
|
+
obj['id']
|
108
105
|
end
|
109
106
|
end
|
110
107
|
|
111
108
|
def prepare_dir!(basedir, date_obj)
|
112
|
-
dir_name = (Pathname(basedir) + encode_dirname(date_obj)).to_s
|
109
|
+
dir_name = (Pathname(basedir) + LucaSupport::Code.encode_dirname(date_obj)).to_s
|
113
110
|
FileUtils.mkdir_p(dir_name) unless Dir.exist?(dir_name)
|
114
111
|
dir_name
|
115
112
|
end
|
@@ -129,8 +126,17 @@ module LucaRecord # :nodoc:
|
|
129
126
|
create(obj, basedir)
|
130
127
|
else
|
131
128
|
validate_keys(obj)
|
132
|
-
|
133
|
-
|
129
|
+
if obj['id'].length < 40
|
130
|
+
parts = obj['id'].split('/')
|
131
|
+
raise 'invalid ID' if parts.length != 2
|
132
|
+
|
133
|
+
open_records(basedir, parts[0], parts[1], nil, 'w') do |f, path|
|
134
|
+
f.write(YAML.dump(LucaSupport::Code.readable(obj.sort.to_h)))
|
135
|
+
end
|
136
|
+
else
|
137
|
+
open_hashed(basedir, obj['id'], 'w') do |f|
|
138
|
+
f.write(YAML.dump(LucaSupport::Code.readable(obj.sort.to_h)))
|
139
|
+
end
|
134
140
|
end
|
135
141
|
end
|
136
142
|
obj['id']
|
@@ -182,10 +188,6 @@ module LucaRecord # :nodoc:
|
|
182
188
|
end
|
183
189
|
end
|
184
190
|
|
185
|
-
def encode_dirname(date_obj)
|
186
|
-
date_obj.year.to_s + LucaSupport::Code.encode_month(date_obj)
|
187
|
-
end
|
188
|
-
|
189
191
|
# test if having required dirs/files under exec path
|
190
192
|
def valid_project?(path = LucaSupport::Config::Pjdir)
|
191
193
|
project_dir = Pathname(path)
|
@@ -198,6 +200,29 @@ module LucaRecord # :nodoc:
|
|
198
200
|
|
199
201
|
private
|
200
202
|
|
203
|
+
# define new transaction ID & write data at once
|
204
|
+
# ID format is like '2020H/A001', which means record no.1 of 2020/10/10.
|
205
|
+
# Any data format can be written with block.
|
206
|
+
#
|
207
|
+
def create_record(obj, date_obj, codes = nil, basedir = @dirname)
|
208
|
+
FileUtils.mkdir_p(abs_path(basedir)) unless Dir.exist?(abs_path(basedir))
|
209
|
+
subdir = "#{date_obj.year}#{LucaSupport::Code.encode_month(date_obj)}"
|
210
|
+
filename = LucaSupport::Code.encode_date(date_obj) + new_record_id(basedir, date_obj)
|
211
|
+
obj['id'] = "#{subdir}/#{filename}" if obj.is_a? Hash
|
212
|
+
filename += '-' + codes.join('-') if codes
|
213
|
+
Dir.chdir(abs_path(basedir)) do
|
214
|
+
FileUtils.mkdir_p(subdir) unless Dir.exist?(subdir)
|
215
|
+
File.open(Pathname(subdir) / filename, 'w') do |f|
|
216
|
+
if block_given?
|
217
|
+
yield(f)
|
218
|
+
else
|
219
|
+
f.write(YAML.dump(LucaSupport::Code.readable(obj.sort.to_h)))
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
223
|
+
"#{subdir}/#{filename}"
|
224
|
+
end
|
225
|
+
|
201
226
|
# open records with 'basedir/month/date-code' path structure.
|
202
227
|
# Glob pattern can be specified like folloing examples.
|
203
228
|
#
|
@@ -213,6 +238,7 @@ module LucaRecord # :nodoc:
|
|
213
238
|
|
214
239
|
file_pattern = filename.nil? ? '*' : "#{filename}*"
|
215
240
|
Dir.chdir(abs_path(basedir)) do
|
241
|
+
FileUtils.mkdir_p(subdir) if mode == 'w' && !Dir.exist?(subdir)
|
216
242
|
Dir.glob("#{subdir}*/#{file_pattern}").sort.each do |subpath|
|
217
243
|
next if skip_on_unmatch_code(subpath, code)
|
218
244
|
|
@@ -270,16 +296,6 @@ module LucaRecord # :nodoc:
|
|
270
296
|
end
|
271
297
|
end
|
272
298
|
|
273
|
-
def gen_record_file!(basedir, date_obj, codes = nil)
|
274
|
-
d = prepare_dir!(abs_path(basedir), date_obj)
|
275
|
-
filename = LucaSupport::Code.encode_date(date_obj) + new_record_id(abs_path(basedir), date_obj)
|
276
|
-
if codes
|
277
|
-
filename += codes.inject('') { |fragment, code| "#{fragment}-#{code}" }
|
278
|
-
end
|
279
|
-
path = Pathname(d) + filename
|
280
|
-
File.open(path.to_s, 'w') { |f| yield(f) }
|
281
|
-
end
|
282
|
-
|
283
299
|
# TODO: replace with data_dir method
|
284
300
|
def abs_path(base_dir)
|
285
301
|
Pathname(LucaSupport::Config::Pjdir) / 'data' / base_dir
|
@@ -297,8 +313,10 @@ module LucaRecord # :nodoc:
|
|
297
313
|
|
298
314
|
# AUTO INCREMENT
|
299
315
|
def new_record_no(basedir, date_obj)
|
300
|
-
|
301
|
-
|
316
|
+
raise 'No target dir exists.' unless Dir.exist?(abs_path(basedir))
|
317
|
+
|
318
|
+
dir_name = (Pathname(abs_path(basedir)) / LucaSupport::Code.encode_dirname(date_obj)).to_s
|
319
|
+
return 1 unless Dir.exist?(dir_name)
|
302
320
|
|
303
321
|
Dir.chdir(dir_name) do
|
304
322
|
last_file = Dir.glob("#{LucaSupport::Code.encode_date(date_obj)}*").max
|
data/lib/luca_record/version.rb
CHANGED
data/lib/luca_support/code.rb
CHANGED
@@ -45,7 +45,12 @@ module LucaSupport
|
|
45
45
|
num.to_s.reverse.gsub!(/(\d{3})(?=\d)/, '\1,').reverse!
|
46
46
|
end
|
47
47
|
|
48
|
+
# encode directory name from year and month.
|
48
49
|
#
|
50
|
+
def encode_dirname(date_obj)
|
51
|
+
date_obj.year.to_s + encode_month(date_obj)
|
52
|
+
end
|
53
|
+
|
49
54
|
# Month to code conversion.
|
50
55
|
# Date, DateTime, String, Integer is valid input. If nil, returns empty String for consistency.
|
51
56
|
#
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lucarecord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.18
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chuma Takahiro
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-11-
|
11
|
+
date: 2020-11-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mail
|