textrepo 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +52 -4
- data/Gemfile.lock +1 -1
- data/Rakefile +9 -0
- data/lib/textrepo/file_system_repository.rb +66 -13
- data/lib/textrepo/timestamp.rb +18 -16
- data/lib/textrepo/version.rb +1 -1
- data/textrepo.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2806e2488be378495f29ed25dd9d04937d50706a5d7772b5d93fd4d242a675d
|
4
|
+
data.tar.gz: a031757c1eb5fa5ec644b7c6674d030f93aebf07c93ad061ea96711532ab8b79
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bcf5e7162744e0d0ba1e0e1745c37b7718749d3aae2ac83c6c8af8f9c032d8b85af38abbbf61d3f19ec49e640060362bcc55085bb7e930868294068314f5da21
|
7
|
+
data.tar.gz: d2074f1b5a09a8741e8172d51d90c31f7c17552473d834e866cb3f7f1d43d2f2633a7daa2aa50a12d2a17202aa58f43466c151793a9368eb7b3fb39977a0379b
|
data/.gitignore
CHANGED
@@ -1,8 +1,56 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
4
|
/coverage/
|
5
|
-
/
|
5
|
+
/InstalledFiles
|
6
6
|
/pkg/
|
7
7
|
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
8
11
|
/tmp/
|
12
|
+
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
16
|
+
# Ignore Byebug command history file.
|
17
|
+
.byebug_history
|
18
|
+
|
19
|
+
## Specific to RubyMotion:
|
20
|
+
.dat*
|
21
|
+
.repl_history
|
22
|
+
build/
|
23
|
+
*.bridgesupport
|
24
|
+
build-iPhoneOS/
|
25
|
+
build-iPhoneSimulator/
|
26
|
+
|
27
|
+
## Specific to RubyMotion (use of CocoaPods):
|
28
|
+
#
|
29
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
30
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
31
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
32
|
+
#
|
33
|
+
# vendor/Pods/
|
34
|
+
|
35
|
+
## Documentation cache and generated files:
|
36
|
+
/.yardoc/
|
37
|
+
/_yardoc/
|
38
|
+
/doc/
|
39
|
+
/rdoc/
|
40
|
+
|
41
|
+
## Environment normalization:
|
42
|
+
/.bundle/
|
43
|
+
/vendor/bundle
|
44
|
+
/lib/bundler/man/
|
45
|
+
|
46
|
+
# for a library or gem, you might want to ignore these files since the code is
|
47
|
+
# intended to run in multiple environments; otherwise, check them in:
|
48
|
+
# Gemfile.lock
|
49
|
+
# .ruby-version
|
50
|
+
# .ruby-gemset
|
51
|
+
|
52
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
53
|
+
.rvmrc
|
54
|
+
|
55
|
+
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
|
56
|
+
# .rubocop-https?--*
|
data/Gemfile.lock
CHANGED
data/Rakefile
CHANGED
@@ -35,3 +35,12 @@ end
|
|
35
35
|
task :clobber => :clean_sandbox
|
36
36
|
CLOBBER << 'test/fixtures/notes'
|
37
37
|
CLOBBER << 'test/fixtures/test_repo'
|
38
|
+
|
39
|
+
require "rdoc/task"
|
40
|
+
|
41
|
+
RDoc::Task.new do |rdoc|
|
42
|
+
rdoc.generator = "ri"
|
43
|
+
rdoc.rdoc_dir = "doc"
|
44
|
+
rdoc.rdoc_files.include("lib/**/*.rb")
|
45
|
+
rdoc.markup = "markdown"
|
46
|
+
end
|
@@ -1,26 +1,46 @@
|
|
1
1
|
require 'fileutils'
|
2
2
|
|
3
3
|
module Textrepo
|
4
|
-
|
4
|
+
##
|
5
|
+
# A concrete class which implements Repository interfaces. This
|
6
|
+
# repository uses the default file system of the operating system as
|
7
|
+
# a text storage.
|
5
8
|
class FileSystemRepository < Repository
|
6
|
-
|
9
|
+
##
|
10
|
+
# Repository root.
|
11
|
+
attr_reader :path
|
7
12
|
|
13
|
+
##
|
14
|
+
# Extension of notes sotres in the repository.
|
15
|
+
attr_reader :extname
|
16
|
+
|
17
|
+
##
|
18
|
+
# Default name for the repository which uses when no name is
|
19
|
+
# specified in the configuration settings.
|
8
20
|
FAVORITE_REPOSITORY_NAME = 'notes'
|
21
|
+
|
22
|
+
##
|
23
|
+
# Default extension of notes which uses when no extname is
|
24
|
+
# specified in the configuration settings.
|
9
25
|
FAVORITE_EXTNAME = 'md'
|
10
26
|
|
11
|
-
|
12
|
-
#
|
27
|
+
##
|
28
|
+
# Creates a new repository object. The argument, `conf` must be a
|
29
|
+
# Hash object. It should hold the follwoing values:
|
13
30
|
#
|
14
|
-
# - :
|
15
|
-
#
|
16
|
-
#
|
17
|
-
# - :
|
31
|
+
# - MANDATORY:
|
32
|
+
# - :repository_type => `:file_system`
|
33
|
+
# - :repository_base => the parent directory path for the repository
|
34
|
+
# - OPTIONAL: (if not specified, default values are used)
|
35
|
+
# - :repository_name => basename of the root path for the repository
|
36
|
+
# - :default_extname => extname for a file stored into in the repository
|
18
37
|
#
|
19
38
|
# The root path of the repository looks like the following:
|
20
39
|
# - conf[:repository_base]/conf[:repository_name]
|
21
40
|
#
|
22
41
|
# Default values are set when `repository_name` and `default_extname`
|
23
42
|
# were not defined in `conf`.
|
43
|
+
#
|
24
44
|
def initialize(conf)
|
25
45
|
super
|
26
46
|
base = conf[:repository_base]
|
@@ -30,12 +50,13 @@ module Textrepo
|
|
30
50
|
@extname = conf[:default_extname] || FAVORITE_EXTNAME
|
31
51
|
end
|
32
52
|
|
33
|
-
|
34
|
-
# repository operations
|
35
|
-
#
|
36
|
-
|
53
|
+
##
|
37
54
|
# Creates a file into the repository, which contains the specified
|
38
55
|
# text and is associated to the timestamp.
|
56
|
+
#
|
57
|
+
# :call-seq:
|
58
|
+
# create(Timestamp, Array) => Timestamp
|
59
|
+
#
|
39
60
|
def create(timestamp, text)
|
40
61
|
abs = abspath(timestamp)
|
41
62
|
raise DuplicateTimestampError, timestamp if FileTest.exist?(abs)
|
@@ -45,8 +66,13 @@ module Textrepo
|
|
45
66
|
timestamp
|
46
67
|
end
|
47
68
|
|
69
|
+
##
|
48
70
|
# Reads the file content in the repository. Then, returns its
|
49
71
|
# content.
|
72
|
+
#
|
73
|
+
# :call-seq:
|
74
|
+
# read(Timestamp) => Array
|
75
|
+
#
|
50
76
|
def read(timestamp)
|
51
77
|
abs = abspath(timestamp)
|
52
78
|
raise MissingTimestampError, timestamp unless FileTest.exist?(abs)
|
@@ -57,8 +83,13 @@ module Textrepo
|
|
57
83
|
content
|
58
84
|
end
|
59
85
|
|
86
|
+
##
|
60
87
|
# Updates the file content in the repository. A new timestamp
|
61
88
|
# will be attached to the text.
|
89
|
+
#
|
90
|
+
# :call-seq:
|
91
|
+
# update(Timestamp, Array) => Timestamp
|
92
|
+
#
|
62
93
|
def update(timestamp, text)
|
63
94
|
raise EmptyTextError if text.empty?
|
64
95
|
org_abs = abspath(timestamp)
|
@@ -75,7 +106,12 @@ module Textrepo
|
|
75
106
|
new_stamp
|
76
107
|
end
|
77
108
|
|
109
|
+
##
|
78
110
|
# Deletes the file in the repository.
|
111
|
+
#
|
112
|
+
# :call-seq:
|
113
|
+
# delete(Timestamp) => Array
|
114
|
+
#
|
79
115
|
def delete(timestamp)
|
80
116
|
abs = abspath(timestamp)
|
81
117
|
raise MissingTimestampError, timestamp unless FileTest.exist?(abs)
|
@@ -86,7 +122,12 @@ module Textrepo
|
|
86
122
|
content
|
87
123
|
end
|
88
124
|
|
125
|
+
##
|
89
126
|
# Finds entries of text those timestamp matches the specified pattern.
|
127
|
+
#
|
128
|
+
# :call-seq:
|
129
|
+
# entries(String = nil) => Array
|
130
|
+
#
|
90
131
|
def entries(stamp_pattern = nil)
|
91
132
|
results = []
|
92
133
|
|
@@ -117,12 +158,24 @@ module Textrepo
|
|
117
158
|
results
|
118
159
|
end
|
119
160
|
|
161
|
+
# :stopdoc:
|
120
162
|
private
|
121
163
|
def abspath(timestamp)
|
122
|
-
filename = timestamp
|
164
|
+
filename = timestamp_to_pathname(timestamp) + ".#{@extname}"
|
123
165
|
File.expand_path(filename, @path)
|
124
166
|
end
|
125
167
|
|
168
|
+
##
|
169
|
+
# ```
|
170
|
+
# %Y %m %d %H %M %S suffix %Y/%m/ %Y%m%d%H%M%S %L
|
171
|
+
# "2020-12-30 12:34:56 (0 | nil)" => "2020/12/20201230123456"
|
172
|
+
# "2020-12-30 12:34:56 (7)" => "2020/12/20201230123456_007"
|
173
|
+
# ```
|
174
|
+
def timestamp_to_pathname(timestamp)
|
175
|
+
yyyy, mo = Timestamp.split_stamp(timestamp.to_s)[0..1]
|
176
|
+
File.join(yyyy, mo, timestamp.to_s)
|
177
|
+
end
|
178
|
+
|
126
179
|
def write_text(abs, text)
|
127
180
|
FileUtils.mkdir_p(File.dirname(abs))
|
128
181
|
File.open(abs, 'w') { |f|
|
data/lib/textrepo/timestamp.rb
CHANGED
@@ -1,11 +1,17 @@
|
|
1
1
|
module Textrepo
|
2
|
+
##
|
3
|
+
# Timstamp is generated from a Time object. It converts a time to
|
4
|
+
# string in the obvious format, such "20201023122400".
|
5
|
+
#
|
2
6
|
class Timestamp
|
3
7
|
include Comparable
|
4
8
|
|
5
9
|
attr_reader :time, :suffix
|
6
10
|
|
7
|
-
|
8
|
-
#
|
11
|
+
##
|
12
|
+
# :call-seq:
|
13
|
+
# new(Time, Integer = nil)
|
14
|
+
#
|
9
15
|
def initialize(time, suffix = nil)
|
10
16
|
@time = time
|
11
17
|
@suffix = suffix
|
@@ -20,26 +26,29 @@ module Textrepo
|
|
20
26
|
result == 0 ? (sfx <=> osfx) : result
|
21
27
|
end
|
22
28
|
|
29
|
+
##
|
30
|
+
# Generate an obvious time string.
|
31
|
+
#
|
32
|
+
# ```
|
23
33
|
# %Y %m %d %H %M %S suffix
|
24
34
|
# "2020-12-30 12:34:56 (0 | nil)" => "20201230123456"
|
25
35
|
# "2020-12-30 12:34:56 (7)" => "20201230123456_007"
|
36
|
+
# ```
|
37
|
+
#
|
26
38
|
def to_s
|
27
39
|
s = @time.strftime("%Y%m%d%H%M%S")
|
28
40
|
s += "_#{"%03u" % @suffix}" unless @suffix.nil? || @suffix == 0
|
29
41
|
s
|
30
42
|
end
|
31
43
|
|
32
|
-
# %Y %m %d %H %M %S suffix %Y/%m/ %Y%m%d%H%M%S %L
|
33
|
-
# "2020-12-30 12:34:56 (0 | nil)" => "2020/12/20201230123456"
|
34
|
-
# "2020-12-30 12:34:56 (7)" => "2020/12/20201230123456_007"
|
35
|
-
def to_pathname
|
36
|
-
@time.strftime("%Y/%m/") + self.to_s
|
37
|
-
end
|
38
|
-
|
39
44
|
class << self
|
45
|
+
##
|
46
|
+
# ```
|
40
47
|
# yyyymoddhhmiss sfx yyyy mo dd hh mi ss sfx
|
41
48
|
# "20201230123456" => "2020", "12", "30", "12", "34", "56"
|
42
49
|
# "20201230123456_789" => "2020", "12", "30", "12", "34", "56", "789"
|
50
|
+
# ```
|
51
|
+
#
|
43
52
|
def split_stamp(stamp_str)
|
44
53
|
# yyyy mo dd hh mi ss sfx
|
45
54
|
a = [0..3, 4..5, 6..7, 8..9, 10..11, 12..13, 15..17].map {|r| stamp_str[r]}
|
@@ -51,13 +60,6 @@ module Textrepo
|
|
51
60
|
Timestamp.new(Time.new(year, mon, day, hour, min, sec), sfx)
|
52
61
|
end
|
53
62
|
|
54
|
-
# (-2)
|
55
|
-
# 0 8 |(-1)
|
56
|
-
# V V VV
|
57
|
-
# "2020/12/20201230123456" => "2020-12-30 12:34:56"
|
58
|
-
def parse_pathname(pathname)
|
59
|
-
parse_s(pathname[8..-1])
|
60
|
-
end
|
61
63
|
end
|
62
64
|
end
|
63
65
|
end
|
data/lib/textrepo/version.rb
CHANGED
data/textrepo.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
|
|
7
7
|
spec.email = ["mnbi@users.noreply.github.com"]
|
8
8
|
|
9
9
|
spec.summary = %q{A repository to store text with timestamp.}
|
10
|
-
spec.description = %q{Textrepo is a repository to store text with timestamp. It can manage text with the attached timestamp (read/update/
|
10
|
+
spec.description = %q{Textrepo is a repository to store text with timestamp. It can manage text with the attached timestamp (create/read/update/delete).}
|
11
11
|
spec.homepage = "https://github.com/mnbi/textrepo"
|
12
12
|
spec.license = "MIT"
|
13
13
|
spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: textrepo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mnbi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-10-
|
11
|
+
date: 2020-10-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2.1'
|
27
27
|
description: Textrepo is a repository to store text with timestamp. It can manage
|
28
|
-
text with the attached timestamp (read/update/
|
28
|
+
text with the attached timestamp (create/read/update/delete).
|
29
29
|
email:
|
30
30
|
- mnbi@users.noreply.github.com
|
31
31
|
executables: []
|