kubo 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.editorconfig +9 -0
- data/.github/workflows/main.yml +16 -0
- data/.gitignore +16 -0
- data/.rspec +3 -0
- data/.rubocop.yml +13 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +55 -0
- data/README.md +35 -0
- data/Rakefile +12 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/kubo.gemspec +30 -0
- data/lib/kubo/base_file.rb +89 -0
- data/lib/kubo/version.rb +5 -0
- data/lib/kubo/zip.rb +28 -0
- data/lib/kubo.rb +11 -0
- metadata +63 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f8c9bd4c6990fd5ecd030402ada88e024a1e8ceb387f750f7e1449bbfe04b713
|
4
|
+
data.tar.gz: 3b3f29bc6b6812bf6ee7e89aae06ae0231a8feccb3e993c6089feec00634522c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dd43e82ea73669280432d968424dd868a16c44830aed3f193602e7abbd5d1c524d611b1748387153f6d15456ad6761ee9ec4363610e732164e8ec33b3231cae7
|
7
|
+
data.tar.gz: d0f7264308d8e08246ac881dd17cacd882a1533e86bdec5adbd1f627153dc2619ee672c19a06bc27bb5e348f563784d5b9a2ba933eab79033f7de0d9b1c92151
|
data/.editorconfig
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on: [push,pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
steps:
|
9
|
+
- uses: actions/checkout@v2
|
10
|
+
- name: Set up Ruby
|
11
|
+
uses: ruby/setup-ruby@v1.84.0
|
12
|
+
with:
|
13
|
+
ruby-version: 3.0.2
|
14
|
+
bundler-cache: true
|
15
|
+
- name: Run the default task
|
16
|
+
run: bundle exec rake
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
kubo (1.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.2)
|
10
|
+
diff-lcs (1.4.4)
|
11
|
+
parallel (1.21.0)
|
12
|
+
parser (3.0.2.0)
|
13
|
+
ast (~> 2.4.1)
|
14
|
+
rainbow (3.0.0)
|
15
|
+
rake (13.0.6)
|
16
|
+
regexp_parser (2.1.1)
|
17
|
+
rexml (3.2.5)
|
18
|
+
rspec (3.10.0)
|
19
|
+
rspec-core (~> 3.10.0)
|
20
|
+
rspec-expectations (~> 3.10.0)
|
21
|
+
rspec-mocks (~> 3.10.0)
|
22
|
+
rspec-core (3.10.1)
|
23
|
+
rspec-support (~> 3.10.0)
|
24
|
+
rspec-expectations (3.10.1)
|
25
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
26
|
+
rspec-support (~> 3.10.0)
|
27
|
+
rspec-mocks (3.10.2)
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
+
rspec-support (~> 3.10.0)
|
30
|
+
rspec-support (3.10.2)
|
31
|
+
rubocop (1.22.3)
|
32
|
+
parallel (~> 1.10)
|
33
|
+
parser (>= 3.0.0.0)
|
34
|
+
rainbow (>= 2.2.2, < 4.0)
|
35
|
+
regexp_parser (>= 1.8, < 3.0)
|
36
|
+
rexml
|
37
|
+
rubocop-ast (>= 1.12.0, < 2.0)
|
38
|
+
ruby-progressbar (~> 1.7)
|
39
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
40
|
+
rubocop-ast (1.12.0)
|
41
|
+
parser (>= 3.0.1.1)
|
42
|
+
ruby-progressbar (1.11.0)
|
43
|
+
unicode-display_width (2.1.0)
|
44
|
+
|
45
|
+
PLATFORMS
|
46
|
+
x86_64-linux
|
47
|
+
|
48
|
+
DEPENDENCIES
|
49
|
+
kubo!
|
50
|
+
rake (~> 13.0)
|
51
|
+
rspec (~> 3.0)
|
52
|
+
rubocop (~> 1.7)
|
53
|
+
|
54
|
+
BUNDLED WITH
|
55
|
+
2.2.22
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Kubo
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/kubo`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'kubo'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install kubo
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/kubo.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "kubo"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/kubo.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/kubo/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "kubo"
|
7
|
+
spec.version = Kubo::VERSION
|
8
|
+
spec.authors = ["EVOKE"]
|
9
|
+
spec.email = ["evoke.lektrique@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "Cache files."
|
12
|
+
spec.description = "Cache files long description here."
|
13
|
+
spec.homepage = "http://github.com/evokelektrique/kubo"
|
14
|
+
spec.required_ruby_version = ">= 2.7.0"
|
15
|
+
|
16
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
17
|
+
|
18
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
19
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
20
|
+
spec.metadata["changelog_uri"] = "http://github.com/evokelektrique/kubo/CHANGELOG.md"
|
21
|
+
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
25
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
26
|
+
end
|
27
|
+
spec.bindir = "exe"
|
28
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kubo
|
4
|
+
# Base file class
|
5
|
+
class BaseFile
|
6
|
+
attr_accessor :path, :time
|
7
|
+
|
8
|
+
def initialize(time = "1h", path = "./cache")
|
9
|
+
@time = parse_time(time)
|
10
|
+
@path = parse_path(path)
|
11
|
+
generate_path
|
12
|
+
end
|
13
|
+
|
14
|
+
def parse_path(path)
|
15
|
+
File.expand_path(path)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Convert given time to seconds
|
19
|
+
def parse_time(time)
|
20
|
+
duration_time = time[...-1].to_i
|
21
|
+
|
22
|
+
raise(StandardError, "Expiration time has to be greater than zero") if duration_time <= 0
|
23
|
+
|
24
|
+
duration_type = time[-1..]
|
25
|
+
convert_to_seconds(duration_type, duration_time)
|
26
|
+
end
|
27
|
+
|
28
|
+
def expired?(key)
|
29
|
+
path = get_file_path(key)
|
30
|
+
(Time.now - File.mtime(path)) >= @time
|
31
|
+
end
|
32
|
+
|
33
|
+
def delete_if_expired(key)
|
34
|
+
return false unless file_empty?(key) || file_exists(key)
|
35
|
+
|
36
|
+
delete(key) if expired?(key)
|
37
|
+
|
38
|
+
true
|
39
|
+
end
|
40
|
+
|
41
|
+
def delete(key)
|
42
|
+
path = get_file_path(key)
|
43
|
+
File.delete(path)
|
44
|
+
end
|
45
|
+
|
46
|
+
def flush(key)
|
47
|
+
path = get_file_path(key)
|
48
|
+
File.truncate(path, 0)
|
49
|
+
end
|
50
|
+
|
51
|
+
# Check whether the files is empty or not
|
52
|
+
def file_empty?(key)
|
53
|
+
path = get_file_path(key)
|
54
|
+
File.size(path)
|
55
|
+
end
|
56
|
+
|
57
|
+
def file_exists?(key)
|
58
|
+
path = get_file_path(key)
|
59
|
+
|
60
|
+
return false unless File.exist?(path)
|
61
|
+
|
62
|
+
true
|
63
|
+
end
|
64
|
+
|
65
|
+
# Concatenate absolute path with key
|
66
|
+
def get_file_path(key)
|
67
|
+
"#{@path}/#{key}"
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def generate_path
|
73
|
+
FileUtils.mkdir_p @path
|
74
|
+
end
|
75
|
+
|
76
|
+
def convert_to_seconds(type, time)
|
77
|
+
case type
|
78
|
+
when "s"
|
79
|
+
time
|
80
|
+
when "m"
|
81
|
+
time * 60
|
82
|
+
when "h"
|
83
|
+
time * 60 * 60
|
84
|
+
when "d"
|
85
|
+
time * 60 * 60 * 24
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
data/lib/kubo/version.rb
ADDED
data/lib/kubo/zip.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kubo
|
4
|
+
# Base caching class
|
5
|
+
class Zip < BaseFile
|
6
|
+
# Write the compressed value to file
|
7
|
+
def save(key, value)
|
8
|
+
path = get_file_path(key.to_s)
|
9
|
+
file = File.new(path, "w+")
|
10
|
+
file.puts(compress(value))
|
11
|
+
file.close
|
12
|
+
end
|
13
|
+
|
14
|
+
# Decompress file
|
15
|
+
def read(key)
|
16
|
+
path = get_file_path(key.to_s)
|
17
|
+
file = File.read(path)
|
18
|
+
Zlib::Inflate.inflate(file)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
# Compress file to gz
|
24
|
+
def compress(value)
|
25
|
+
Zlib::Deflate.deflate(value)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/kubo.rb
ADDED
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kubo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- EVOKE
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-11-02 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Cache files long description here.
|
14
|
+
email:
|
15
|
+
- evoke.lektrique@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".editorconfig"
|
21
|
+
- ".github/workflows/main.yml"
|
22
|
+
- ".gitignore"
|
23
|
+
- ".rspec"
|
24
|
+
- ".rubocop.yml"
|
25
|
+
- CHANGELOG.md
|
26
|
+
- Gemfile
|
27
|
+
- Gemfile.lock
|
28
|
+
- README.md
|
29
|
+
- Rakefile
|
30
|
+
- bin/console
|
31
|
+
- bin/setup
|
32
|
+
- kubo.gemspec
|
33
|
+
- lib/kubo.rb
|
34
|
+
- lib/kubo/base_file.rb
|
35
|
+
- lib/kubo/version.rb
|
36
|
+
- lib/kubo/zip.rb
|
37
|
+
homepage: http://github.com/evokelektrique/kubo
|
38
|
+
licenses: []
|
39
|
+
metadata:
|
40
|
+
allowed_push_host: https://rubygems.org
|
41
|
+
homepage_uri: http://github.com/evokelektrique/kubo
|
42
|
+
source_code_uri: http://github.com/evokelektrique/kubo
|
43
|
+
changelog_uri: http://github.com/evokelektrique/kubo/CHANGELOG.md
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 2.7.0
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
requirements: []
|
59
|
+
rubygems_version: 3.2.22
|
60
|
+
signing_key:
|
61
|
+
specification_version: 4
|
62
|
+
summary: Cache files.
|
63
|
+
test_files: []
|