kubo 1.0.1

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 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,9 @@
1
+ root = true
2
+
3
+ [*]
4
+ indent_style = space
5
+ indent_size = 2
6
+ end_of_line = lf
7
+ charset = utf-8
8
+ trim_trailing_whitespace = true
9
+ insert_final_newline = true
@@ -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
@@ -0,0 +1,16 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ # Ignore TODO List
14
+ TODO
15
+
16
+ /test/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.7
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2021-10-31
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in kubo.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "rubocop", "~> 1.7"
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
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
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
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
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
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kubo
4
+ VERSION = "1.0.1"
5
+ end
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
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "fileutils"
4
+ require "zlib"
5
+ require_relative "kubo/version"
6
+ require_relative "kubo/base_file"
7
+ require_relative "kubo/zip"
8
+
9
+ module Kubo
10
+ class Error < StandardError; end
11
+ end
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: []