textrepo 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c2806e2488be378495f29ed25dd9d04937d50706a5d7772b5d93fd4d242a675d
4
- data.tar.gz: a031757c1eb5fa5ec644b7c6674d030f93aebf07c93ad061ea96711532ab8b79
3
+ metadata.gz: 9af29cfb5945798beea4d787abc9ec472607841d6daea7dc8e62bf62a3ecc4b2
4
+ data.tar.gz: 31f97fb8586b206b95f85feaaf653aa0e75a08379677e2019e067c5df03f0b3d
5
5
  SHA512:
6
- metadata.gz: bcf5e7162744e0d0ba1e0e1745c37b7718749d3aae2ac83c6c8af8f9c032d8b85af38abbbf61d3f19ec49e640060362bcc55085bb7e930868294068314f5da21
7
- data.tar.gz: d2074f1b5a09a8741e8172d51d90c31f7c17552473d834e866cb3f7f1d43d2f2633a7daa2aa50a12d2a17202aa58f43466c151793a9368eb7b3fb39977a0379b
6
+ metadata.gz: 934d63e39badb3ffa660b26e363a1caba78bd3dd906c8c7b24c79374659780def778e7f00b6902a1f80950055d885a954561a74b2301253a086195f48d05a79e
7
+ data.tar.gz: d25676f649ba6308403f3a8e4e4d2f1d851b9d6026ebe8ee5668d7a8d37a4edc8135f13ead288a963afc81571cc1b0378499630c314334f5b3c223bf8e7dc3f4
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ Gemfile.lock
1
2
  *.gem
2
3
  *.rbc
3
4
  /.config
@@ -1,27 +1,34 @@
1
1
  require 'fileutils'
2
2
 
3
3
  module Textrepo
4
+
4
5
  ##
5
6
  # A concrete class which implements Repository interfaces. This
6
7
  # repository uses the default file system of the operating system as
7
8
  # a text storage.
9
+
8
10
  class FileSystemRepository < Repository
11
+
9
12
  ##
10
13
  # Repository root.
14
+
11
15
  attr_reader :path
12
16
 
13
17
  ##
14
18
  # Extension of notes sotres in the repository.
19
+
15
20
  attr_reader :extname
16
21
 
17
22
  ##
18
23
  # Default name for the repository which uses when no name is
19
24
  # specified in the configuration settings.
25
+
20
26
  FAVORITE_REPOSITORY_NAME = 'notes'
21
27
 
22
28
  ##
23
29
  # Default extension of notes which uses when no extname is
24
30
  # specified in the configuration settings.
31
+
25
32
  FAVORITE_EXTNAME = 'md'
26
33
 
27
34
  ##
@@ -40,7 +47,7 @@ module Textrepo
40
47
  #
41
48
  # Default values are set when `repository_name` and `default_extname`
42
49
  # were not defined in `conf`.
43
- #
50
+
44
51
  def initialize(conf)
45
52
  super
46
53
  base = conf[:repository_base]
@@ -53,10 +60,10 @@ module Textrepo
53
60
  ##
54
61
  # Creates a file into the repository, which contains the specified
55
62
  # text and is associated to the timestamp.
56
- #
63
+
57
64
  # :call-seq:
58
65
  # create(Timestamp, Array) => Timestamp
59
- #
66
+
60
67
  def create(timestamp, text)
61
68
  abs = abspath(timestamp)
62
69
  raise DuplicateTimestampError, timestamp if FileTest.exist?(abs)
@@ -69,10 +76,10 @@ module Textrepo
69
76
  ##
70
77
  # Reads the file content in the repository. Then, returns its
71
78
  # content.
72
- #
79
+
73
80
  # :call-seq:
74
81
  # read(Timestamp) => Array
75
- #
82
+
76
83
  def read(timestamp)
77
84
  abs = abspath(timestamp)
78
85
  raise MissingTimestampError, timestamp unless FileTest.exist?(abs)
@@ -86,10 +93,10 @@ module Textrepo
86
93
  ##
87
94
  # Updates the file content in the repository. A new timestamp
88
95
  # will be attached to the text.
89
- #
96
+
90
97
  # :call-seq:
91
98
  # update(Timestamp, Array) => Timestamp
92
- #
99
+
93
100
  def update(timestamp, text)
94
101
  raise EmptyTextError if text.empty?
95
102
  org_abs = abspath(timestamp)
@@ -108,10 +115,10 @@ module Textrepo
108
115
 
109
116
  ##
110
117
  # Deletes the file in the repository.
111
- #
118
+
112
119
  # :call-seq:
113
120
  # delete(Timestamp) => Array
114
- #
121
+
115
122
  def delete(timestamp)
116
123
  abs = abspath(timestamp)
117
124
  raise MissingTimestampError, timestamp unless FileTest.exist?(abs)
@@ -124,10 +131,10 @@ module Textrepo
124
131
 
125
132
  ##
126
133
  # Finds entries of text those timestamp matches the specified pattern.
127
- #
134
+
128
135
  # :call-seq:
129
136
  # entries(String = nil) => Array
130
- #
137
+
131
138
  def entries(stamp_pattern = nil)
132
139
  results = []
133
140
 
@@ -158,19 +165,28 @@ module Textrepo
158
165
  results
159
166
  end
160
167
 
168
+ ##
169
+ # Check the existence of text which is associated with the given
170
+ # timestamp.
171
+
172
+ # :call-seq:
173
+ # exist?(Timestamp) -> true or false
174
+
175
+ def exist?(timestamp)
176
+ FileTest.exist?(abspath(timestamp))
177
+ end
178
+
161
179
  # :stopdoc:
180
+
162
181
  private
163
182
  def abspath(timestamp)
164
183
  filename = timestamp_to_pathname(timestamp) + ".#{@extname}"
165
184
  File.expand_path(filename, @path)
166
185
  end
167
186
 
168
- ##
169
- # ```
170
187
  # %Y %m %d %H %M %S suffix %Y/%m/ %Y%m%d%H%M%S %L
171
188
  # "2020-12-30 12:34:56 (0 | nil)" => "2020/12/20201230123456"
172
189
  # "2020-12-30 12:34:56 (7)" => "2020/12/20201230123456_007"
173
- # ```
174
190
  def timestamp_to_pathname(timestamp)
175
191
  yyyy, mo = Timestamp.split_stamp(timestamp.to_s)[0..1]
176
192
  File.join(yyyy, mo, timestamp.to_s)
@@ -187,10 +203,6 @@ module Textrepo
187
203
  File.basename(text_path).delete_suffix(".#{@extname}")
188
204
  end
189
205
 
190
- def exist?(timestamp)
191
- FileTest.exist?(abspath(timestamp))
192
- end
193
-
194
206
  def find_entries(stamp_pattern)
195
207
  Dir.glob("#{@path}/**/#{stamp_pattern}*.#{@extname}").map { |e|
196
208
  timestamp_str(e)
@@ -1,31 +1,72 @@
1
1
  module Textrepo
2
2
  class Repository
3
- attr_reader :type, :name
3
+
4
+ ##
5
+ # Repository type. It specifies which concrete repository class
6
+ # will instantiated. For example, the type `:file_system` specifies
7
+ # `FileSystemRepository`.
8
+
9
+ attr_reader :type
10
+
11
+ ##
12
+ # Repository name. The usage of the value of `name` depends on a
13
+ # concrete repository class. For example, `FileSystemRepository`
14
+ # uses it as a part of the repository path.
15
+
16
+ attr_reader :name
17
+
18
+ ##
19
+ # Create a new repository. The argument must be an object which
20
+ # can be accessed like a Hash object.
4
21
 
5
22
  def initialize(conf)
6
23
  @type = conf[:repository_type]
7
24
  @name = conf[:repository_name]
8
25
  end
9
26
 
27
+ ##
10
28
  # Stores text data into the repository with the specified timestamp.
11
29
  # Returns the timestamp.
30
+
31
+ # :call-seq:
32
+ # create(Timestamp, Array) -> Timestamp
33
+
12
34
  def create(timestamp, text); timestamp; end
13
35
 
36
+ ##
14
37
  # Reads text data from the repository, which is associated to the
15
38
  # timestamp. Returns an array which contains the text.
39
+
40
+ # :call-seq:
41
+ # read(Timestamp) -> Array
42
+
16
43
  def read(timestamp); []; end
17
44
 
45
+ ##
18
46
  # Updates the content with text in the repository, which is
19
47
  # associated to the timestamp. Returns the timestamp.
48
+
49
+ # :call-seq:
50
+ # update(Timestamp, Array) -> Timestamp
51
+
20
52
  def update(timestamp, text); timestamp; end
21
53
 
54
+ ##
22
55
  # Deletes the content in the repository, which is associated to
23
56
  # the timestamp. Returns an array which contains the deleted text.
57
+
58
+ # :call-seq:
59
+ # delete(Timestamp) -> Array
60
+
24
61
  def delete(timestamp); []; end
25
62
 
63
+ ##
26
64
  # Finds all entries of text those have timestamps which mathes the
27
65
  # specified pattern of timestamp. Returns an array which contains
28
- # timestamps. A pattern must be one of the following:
66
+ # timestamps. If none of text was found, an empty array would be
67
+ # returned.
68
+ #
69
+ # A pattern must be one of the following:
29
70
  #
30
71
  # - yyyymoddhhmiss_lll : whole stamp
31
72
  # - yyyymoddhhmiss : omit millisecond part
@@ -37,17 +78,31 @@ module Textrepo
37
78
  # If `stamp_pattern` is omitted, the recent entries will be listed.
38
79
  # Then, how many entries are listed depends on the implementaiton
39
80
  # of the concrete repository class.
81
+
82
+ # :call-seq:
83
+ # entries(String) -> Array
84
+
40
85
  def entries(stamp_pattern = nil); []; end
41
86
 
87
+ ##
88
+ # Check the existence of text which is associated with the given
89
+ # timestamp.
90
+ #
91
+ # :call-seq:
92
+ # exist?(Timestamp) -> true or false
93
+
94
+ def exist?(timestamp); false; end
42
95
  end
43
96
 
44
97
  require_relative 'file_system_repository'
45
98
 
99
+ ##
46
100
  # Returns an instance which derived from Textrepo::Repository class.
47
- # `conf` must be a Hash object which has a value of
48
- # `:repository_type` and `:repository_name` at least. Some concrete
49
- # class derived from Textrepo::Repository may require more key-value
50
- # pairs in `conf`.
101
+ # `conf` must be an object which can be accessed like a Hash object.
102
+ # And it must also has a value of `:repository_type` and
103
+ # `:repository_name` at least. Some concrete class derived from
104
+ # Textrepo::Repository may require more key-value pairs in `conf`.
105
+
51
106
  def init(conf)
52
107
  type = conf[:repository_type]
53
108
  klass_name = type.to_s.split(/_/).map(&:capitalize).join + "Repository"
@@ -1,3 +1,3 @@
1
1
  module Textrepo
2
- VERSION = '0.4.2'
2
+ VERSION = '0.4.3'
3
3
  end
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.2
4
+ version: 0.4.3
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-23 00:00:00.000000000 Z
11
+ date: 2020-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -36,7 +36,6 @@ files:
36
36
  - ".travis.yml"
37
37
  - CHANGELOG.md
38
38
  - Gemfile
39
- - Gemfile.lock
40
39
  - LICENSE.txt
41
40
  - README.md
42
41
  - Rakefile
@@ -1,22 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- textrepo (0.4.2)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- minitest (5.14.2)
10
- rake (13.0.1)
11
-
12
- PLATFORMS
13
- ruby
14
-
15
- DEPENDENCIES
16
- bundler (~> 2.1)
17
- minitest (~> 5.0)
18
- rake (~> 13.0)
19
- textrepo!
20
-
21
- BUNDLED WITH
22
- 2.1.4