command-cacheable 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 88dad12c02550c892fa096ff0565f05c0597b9e8
4
+ data.tar.gz: 0538a70ce6428325e720184cceaf9fb49bdb48e4
5
+ SHA512:
6
+ metadata.gz: 83a22f48f0137df50ddd7226d0f029f66683d4946f27c6f7f28c5e64bc1916195995f71c0cc4ea61e5c4ea2b81cb535db72d058d2f7aa9392ae2b9587cdad080
7
+ data.tar.gz: 93af6a869d61815bd36933b60afe2c6ede2095063dd5cd9c3bfce53b6fe4cd444ad25dc353ce5fe1f073770f032fa2c057ed6c113a8eaae44c950fed0cd78453
data/.gitignore ADDED
@@ -0,0 +1,50 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ ## Environment normalization:
39
+ /.bundle/
40
+ /vendor/bundle
41
+ /lib/bundler/man/
42
+
43
+ # for a library or gem, you might want to ignore these files since the code is
44
+ # intended to run in multiple environments; otherwise, check them in:
45
+ # Gemfile.lock
46
+ # .ruby-version
47
+ # .ruby-gemset
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in command-cacheable.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,31 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ command-cacheable (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ logue (1.0.8)
10
+ rainbow (~> 2.0, >= 2.0.0)
11
+ paramesan (0.1.1)
12
+ power_assert (1.1.1)
13
+ rainbow (2.2.2)
14
+ rake
15
+ rake (10.5.0)
16
+ test-unit (3.2.6)
17
+ power_assert
18
+
19
+ PLATFORMS
20
+ ruby
21
+
22
+ DEPENDENCIES
23
+ bundler (~> 1.16)
24
+ command-cacheable!
25
+ logue (~> 1.0)
26
+ paramesan (~> 0.1.1)
27
+ rake (~> 10.0)
28
+ test-unit (~> 3.1)
29
+
30
+ BUNDLED WITH
31
+ 1.16.0
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Jeff Pace
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Command::Cacheable
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/command/cacheable`. 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 'command-cacheable'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install command-cacheable
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. 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 tags, 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/jpace/command-cacheable.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "command/cacheable"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ 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
@@ -0,0 +1,38 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "command/cacheable/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "command-cacheable"
8
+ spec.version = Command::Cacheable::VERSION
9
+ spec.authors = ["Jeff Pace"]
10
+ spec.email = ["jeugenepace@gmail.com"]
11
+
12
+ spec.summary = %q{Command-line execution, caching results.}
13
+ spec.description = %q{Executes on the command line, caching results for performance of repeated invocations.}
14
+ spec.homepage = "http://www.github.com/jpace/arbolobra"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.16"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "test-unit", "~> 3.1"
36
+ spec.add_development_dependency "paramesan", "~> 0.1.1"
37
+ spec.add_development_dependency "logue", "~> 1.0"
38
+ end
@@ -0,0 +1,7 @@
1
+ require "command/cacheable/version"
2
+
3
+ module Command
4
+ module Cacheable
5
+
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ module Command::Cacheable
5
+ class Argument < String
6
+ # just a string, but quotes itself
7
+
8
+ def to_s
9
+ '"' + super + '"'
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ # require 'command/cacheable/command'
5
+ require 'command/cacheable/filename'
6
+ require 'command/cacheable/gzpathname'
7
+
8
+ module Command::Cacheable
9
+ # A file that has a pathname and output
10
+ #$$$ todo: cache error
11
+ class CacheFile
12
+ attr_reader :output
13
+ attr_reader :pathname
14
+
15
+ def initialize cache_dir, args
16
+ @args = args
17
+ basename = FileName.new(args).name
18
+ fullname = Pathname(cache_dir) + basename
19
+ @pathname = GzipPathname.new fullname
20
+ @output = nil
21
+ end
22
+
23
+ def read
24
+ @output = @pathname.exist? && @pathname.read_file
25
+ end
26
+
27
+ def save output
28
+ @pathname.save_file output
29
+ end
30
+
31
+ def to_s
32
+ @pathname.to_s
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'command/cacheable/command'
5
+ require 'command/cacheable/cachefile'
6
+
7
+ module Command::Cacheable
8
+ class CachingCommand < Command
9
+ # caches its input and values.
10
+
11
+ def initialize *args, debug: false, dir: nil
12
+ @args = args.dup
13
+ @dir = dir || '/tmp' + Pathname.new($0).expand_path.to_s
14
+ end
15
+
16
+ def cache_dir
17
+ @dir
18
+ end
19
+
20
+ def cache_file
21
+ CacheFile.new cache_dir, @args
22
+ end
23
+
24
+ def execute
25
+ cachefile = cache_file
26
+ @output = cachefile.read
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'logue/loggable'
5
+ require 'open3'
6
+ require 'command/cacheable/cachefile'
7
+
8
+ module Command
9
+ module Cacheable
10
+ end
11
+ end
12
+
13
+ module Command::Cacheable
14
+ # A command line executable, by default not caching.
15
+ class Command
16
+ include Logue::Loggable
17
+
18
+ CACHEDIR = "/tmp/cmdcache"
19
+
20
+ attr_reader :args
21
+ attr_reader :output
22
+ attr_reader :error
23
+ attr_reader :status
24
+
25
+ def initialize *args, debug: false, caching: false, cachedir: nil
26
+ @args = args.dup
27
+ @caching = caching
28
+ @cachedir = cachedir || CACHEDIR
29
+ end
30
+
31
+ def << arg
32
+ @args << arg
33
+ end
34
+
35
+ def execute
36
+ if @caching
37
+ read_cache_file
38
+ else
39
+ exec
40
+ end
41
+ end
42
+
43
+ def exec
44
+ cmd = to_command
45
+ Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thread|
46
+ @output = stdout.readlines
47
+ @error = stderr.readlines
48
+ @status = wait_thread.value
49
+ end
50
+
51
+ #$$$ this functionality isn't in Logue yet (dump of one element per line):
52
+ # debug "output", @output
53
+ # debug "error", @error
54
+
55
+ debug "@status: #{@status}"
56
+
57
+ @output
58
+ end
59
+
60
+ def read_cache_file
61
+ cachefile = CacheFile.new @cachedir, @args
62
+ if cachefile.pathname.exist?
63
+ @output = cachefile.pathname.read_file
64
+ else
65
+ exec
66
+ cachefile.pathname.save_file @output
67
+ @output
68
+ end
69
+ end
70
+
71
+ def to_command
72
+ @args.join ' '
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ module Command
5
+ module Cacheable
6
+ end
7
+ end
8
+
9
+ module Command::Cacheable
10
+ class FileName
11
+ attr_reader :name
12
+
13
+ def initialize args
14
+ @name = args.join('-').gsub('/', '_slash_') + '.gz'
15
+ end
16
+
17
+ def to_s
18
+ @name
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'zlib'
5
+ require 'pathname'
6
+
7
+ module Command
8
+ end
9
+
10
+ module Command::Cacheable
11
+ # A pathname (file) that reads and writes a list of lines, as gzipped
12
+ class GzipPathname < Pathname
13
+ def save_file content
14
+ parent.mkpath unless parent.exist?
15
+ unlink if exist?
16
+ Zlib::GzipWriter.open(to_s) do |gz|
17
+ gz.puts content
18
+ end
19
+ end
20
+
21
+ def read_file
22
+ content = nil
23
+ Zlib::GzipReader.open(to_s) do |gz|
24
+ content = gz.readlines
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,5 @@
1
+ module Command
2
+ module Cacheable
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: command-cacheable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jeff Pace
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-02-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: test-unit
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: paramesan
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.1.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.1.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: logue
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.0'
83
+ description: Executes on the command line, caching results for performance of repeated
84
+ invocations.
85
+ email:
86
+ - jeugenepace@gmail.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - Gemfile
93
+ - Gemfile.lock
94
+ - LICENSE
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - command-cacheable.gemspec
100
+ - lib/command/cacheable.rb
101
+ - lib/command/cacheable/arg.rb
102
+ - lib/command/cacheable/cachefile.rb
103
+ - lib/command/cacheable/caching.rb
104
+ - lib/command/cacheable/command.rb
105
+ - lib/command/cacheable/filename.rb
106
+ - lib/command/cacheable/gzpathname.rb
107
+ - lib/command/cacheable/version.rb
108
+ homepage: http://www.github.com/jpace/arbolobra
109
+ licenses:
110
+ - MIT
111
+ metadata:
112
+ allowed_push_host: https://rubygems.org
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubyforge_project:
129
+ rubygems_version: 2.6.3
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: Command-line execution, caching results.
133
+ test_files: []