super_uri 0.1.0 → 0.1.1

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
  SHA1:
3
- metadata.gz: 7abba009347a073727d723c8b4c4fc5cc29f93d9
4
- data.tar.gz: 06ee087ee08947263c4543db2a3c38383dc31616
3
+ metadata.gz: d224d64c8343f47d13dab91f055e08b7c0031891
4
+ data.tar.gz: 8fa8bbf2a43852a6f5ad68acab65214de21ae3c1
5
5
  SHA512:
6
- metadata.gz: 8aee6eda0c5db337446458650a5d486e55d0cb81a03310cac2b88ac2afbdb1dd0c98c07d3fccc539da949fd9bc5d92a55d4a3d337581489f8a353c07c44ed9cb
7
- data.tar.gz: 614c41d44facbe3b637c4b129e9598ccb35ea0b9a82400817acbbf44238109cb04ef6aafdada7d2ef421d77d200e10763309168fbf01bf2234bba8870eceb65d
6
+ metadata.gz: 30c29b7d019199916d37cc65a9e560562b8a1934f3a7caef6316d15c8691d430bf086e66ac97227b38582989bb671bb61eaadeca534acba70b10d6f8619e9b60
7
+ data.tar.gz: f66ef6f105ba27238ae76e405e7894d932f27314af0f2d0aa86acdda501c47cd62f1e368c967f1f15bef6aa411c74fce26dd4350316420176ae96eb1d5965ddf
data/.travis.yml CHANGED
@@ -1,5 +1,15 @@
1
- sudo: false
2
- language: ruby
1
+ addons:
2
+ code_climate:
3
+ secure: VkxvWVpNOS80dyiX+qpoFikyapclc9puDKeWr1UkCDAJG1MVKGPw1LfB2Yr6YIKR1AL7c7tzobSNEFYBgUsa+rM0ktd7Vq1yBdFdfIeU+Hle8Eys24P3shZFQqc5ejUvGT0PpgDZv7XkjYPwPvnlAGuV+6JjkcjWVq670U5fmHKjKbaU1NYLoBNBimtkyMZSesnr5hklMK6GUTimqYs+81UHYMlbfsN6Bvjs3v8UCNlEfcjYUCgzlujhXbCqNmnCtNMJD26+Z/fYcCUZ0IHRgEN19gWz2UimRZrznBXL2/kfDWIsBYLOXr89yf6fiP9k7A1NWNTyzlKNvkijmgd9k+N1wcCBdO1c7FcnQZqORtQz8k8orLiqfCrLoNWboWhWdV6XY8+0+u3ioK0mtkk/NGssy6ssdEoqSWwrgZGqqz4uE8YMvtuo/KNdNijnyAPRdJUbOY7fWgn78Qr/fmtNG5YJU3XxILjvU6IGvRLZq65Au6dL4WyiyKgI9soP+KctxuMYTaJKSMYdUSdB+af6IOFER0tZSpjZXIJO9DWfJhfUxCBoDJlYsGQj3XRO+Zku0DfUTEHUKPjj3JZNpi8X+1rqwPnLadnmlZigplA+rXZ7qKESVJ3zvsW8/HLF0IEXkC7OH2uXrv/f+Pzc8A2ZKtxRxbjMZF9SjaimnP2jja8=
4
+ cache: bundler
3
5
  rvm:
4
- - 2.4.0
5
- before_install: gem install bundler -v 1.13.7
6
+ - 2.3.3
7
+ - 2.4.0
8
+ services:
9
+ before_script:
10
+ script: bundle exec rspec
11
+ after_success:
12
+ - bundle exec codeclimate-test-reporter
13
+ env:
14
+ secure: ZU8MnRwkMkpRhXoXd0bCVepNfK0FFzLdvekDJWguJJVHQwqGSjl6v4hp72nQrs4NcIPz+16UlRSEBzGvmYCQVimoGp4HqcunvAjJdzpSXCbdXzM+A5NYhslj0dUnfvjdKfszsuTmezZm2c7+c53boK2fvvxur9qVa0RrWRp11vMmevRB0K9VA/FZPRO94uZXQvFUQ5ZsSvx0fmCinwDFrBF/erPmOkkxZv87NoR0RykmpCv53/P8N+xBSVhspU7gYie7oekRIDUBVxXK+j1VNl8lChUoofTBMgh7A5cfVQ5NQEFDCl9LLfeBZMOrS/dvancmbG16oPxFzyd161Bw7xehFP76qTOX3eQAhWv8FL+GkM381q43ctoZQNcRh8AV0oM7ra5GWyPFz5A4yYSu2gpuUFxlmtxYRM8eRKIYUb7n3efK/ZYr0Zd0ZrS8ZYfeRIO8bb1izn6UcWnhXjnBrNOsrKKTe7t6DzMFIwRMSXBUl2k7R8n5TTKkkvbQrNmE/OB6dYdGJbOZ8Hdjy+hdhNMg7Jmph+wmK8wi+Buv5tU8uNVgULB6QQUWIO3WRG+ekBFySGv+HdFSnuHPbEWmYevg+guskmYzCxgA8xLkR6xHyBq5QUt1v9wFPWldwmjbrVRsUnGjlW2zNHwp+u9u/1gRO6N69/6xg4vNyzSuBdg=
15
+ notifications:
data/README.md CHANGED
@@ -1,8 +1,143 @@
1
- # SuperUri
1
+ [![Downloads](http://ruby-gem-downloads-badge.herokuapp.com/super_uri?type=total)](https://rubygems.org/gems/super_uri)
2
+ [![Gem Version](https://badge.fury.io/rb/super_uri.svg)](https://badge.fury.io/rb/super_uri)
2
3
 
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/super_uri`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+ [![Build Status](https://travis-ci.org/kigster/super_uri.svg?branch=master)](https://travis-ci.org/kigster/super_uri)
5
+ [![Code Climate](https://codeclimate.com/repos/588d08ab8dcb7c006a004c31/badges/fbe3044e50dfc06f7b93/gpa.svg)](https://codeclimate.com/repos/588d08ab8dcb7c006a004c31/feed)
6
+ [![Test Coverage](https://codeclimate.com/repos/588d08ab8dcb7c006a004c31/badges/fbe3044e50dfc06f7b93/coverage.svg)](https://codeclimate.com/repos/588d08ab8dcb7c006a004c31/coverage)
7
+ [![Issue Count](https://codeclimate.com/repos/588d08ab8dcb7c006a004c31/badges/fbe3044e50dfc06f7b93/issue_count.svg)](https://codeclimate.com/repos/588d08ab8dcb7c006a004c31/feed)
4
8
 
5
- TODO: Delete this and the text above, and describe your gem
9
+ > **WARNING**: This gem is currently under active development, and is not yet stable. Use at your own risk.
10
+
11
+ # SuperURI — Uniformly Locate Data Anywhere :)
12
+
13
+ ## Summary
14
+
15
+ This gem aims to combine the extensibility of the `URI` class — its design supports adding new and custom URI __schemes__, with the `open` and `read` semantics of the `OpenURI` standard ruby module, and aims to greatly expand the list of URIs that can be read.
16
+
17
+ Eventually this gem might also offer ability to **write** data to the URI.
18
+
19
+ ## Usage
20
+
21
+ As much as possible, we wanted to extend the existing `OpenURI` interface:
22
+
23
+ ```ruby
24
+ require 'super_uri'
25
+
26
+ contents = URI([String]).read
27
+
28
+ URI.parse([String]).open do |file|
29
+ #...
30
+ end
31
+ ```
32
+
33
+ ### Additional Schemes
34
+
35
+ The key to this gem is the large selection of the URIs that can be provided and instantly used to read data. Let's take a look at a few examples:
36
+
37
+ ```ruby
38
+ require 'super_uri'
39
+
40
+ URI('env://HOME').read
41
+ # => "/Users/"
42
+
43
+ URI('file:///usr/local/etc/hosts').read
44
+ # => "127.0.0.1 localhost\n...."
45
+
46
+ URI('redis:///1/mykey').read
47
+ # => "keyvalue"
48
+
49
+ ```
50
+
51
+ Future versions might allow writing and deleting of the data:
52
+
53
+ ```ruby
54
+ #
55
+ URI('file:///usr/local/etc/hosts').write(data)
56
+ # => 23425
57
+ URI('file:///usr/local/etc/hosts').delete
58
+ # => true
59
+
60
+ URI('redis:///1/mykey').write('keyvalue')
61
+ # => 8
62
+ URI('redis:///1/mykey').delet
63
+ # => true
64
+ ```
65
+
66
+
67
+ ### Motivation
68
+
69
+ This gem was born out of the desire to easily read and write data via a large number of ways during development of another gem — [sym](https://github.com/kigster/sym) — which performs symmetric encryption, and needs to read the private key and the data, and write the result (and sometimes the private key). After running out of flags to pass indiciating how exactly the private key is supplied, I had an epiphany — what if I can just use one flag with the data source URI?
70
+
71
+ ### Approach
72
+
73
+ There are two high-level steps required to create a unified way of reading/writing various resources:
74
+
75
+ 1. One must define the syntax for describing how to access it
76
+ 2. One must implement the actual read/write code for each supported syntax.
77
+
78
+ The most natural fit for 1 seems to be the `URI` module. It can be easily extended by design, and already supports many schemes out the box. In addition, a popular `OpenURI` extension adds the `open` call to `http[s]`, `ftp`, and `ssh` protocols, partially providing #2 for these schemes.
79
+
80
+ However, `OpenURI` only supports a few protocols, and does not currently support *delete* operation.
81
+
82
+ The approach we take is to extend `URI` with the schemes with support, and fulfill them using `Handlers` that can be easily added.
83
+
84
+ ## Supported URIs
85
+
86
+ The following types are planned to be supported:
87
+
88
+ ##### Environment Variables
89
+
90
+ ```ruby
91
+ URI('env://HOME').read
92
+ # => /Users/kig
93
+ ```
94
+ ##### Redis
95
+
96
+ ###### Read/Write Hash Value by Key
97
+
98
+ ```ruby
99
+ URI::IO['redis://localhost:6379/1/firstname').write('konstantin')
100
+ # => 'OK'
101
+ URI::IO['redis://localhost:6379/1/firstname').read
102
+ # => 'konstantin'
103
+ ```
104
+
105
+ ###### Any Operation?
106
+
107
+ ```ruby
108
+ URI::IO['redis://localhost:6379/1/operation').run(*args)
109
+ ```
110
+
111
+ ##### File Operation
112
+
113
+ ```ruby
114
+ URI::IO['scp://user@host/path/file').delete
115
+ ```
116
+
117
+ Suggested possible ways of accessing local and remote data:
118
+
119
+ ```ruby
120
+ URI('string://value').read
121
+ # => "value"
122
+
123
+ URI::IO['env://PATH').read
124
+ # => "/bin:/usr/bin:/usr/local/bin"
125
+
126
+ URI('stdin:/').read
127
+ # => data from STDIN until EOF
128
+
129
+ URI('shell://echo%20hello').read
130
+ # => "hello"
131
+
132
+ URI('redis://127.0.0.1:6397/1/get,firstname').read
133
+ # => 'konstantin'
134
+ ```
135
+
136
+ Similarly, we could read data from:
137
+
138
+ memcached://127.0.0.1:11211/operation,arg1,arg2,...
139
+ scp://user@host/path/file
140
+ postgresql://user@host/db/?sql=<sql-query>
6
141
 
7
142
  ## Installation
8
143
 
@@ -20,9 +155,6 @@ Or install it yourself as:
20
155
 
21
156
  $ gem install super_uri
22
157
 
23
- ## Usage
24
-
25
- TODO: Write usage instructions here
26
158
 
27
159
  ## Development
28
160
 
@@ -32,7 +164,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
164
 
33
165
  ## Contributing
34
166
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/super_uri.
167
+ Bug reports and pull requests are welcome on GitHub at https://github.com/kigster/super_uri.
36
168
 
37
169
 
38
170
  ## License
data/lib/super_uri.rb CHANGED
@@ -1,5 +1,10 @@
1
- require "super_uri/version"
1
+ require 'uri'
2
2
 
3
- module SuperUri
4
- # Your code goes here...
5
- end
3
+ require 'super_uri/version'
4
+
5
+ require 'super_uri/class/ext'
6
+ require 'super_uri/hash/case_insensitive_symbolized_hash'
7
+ require 'uri-ext'
8
+
9
+ require 'uri/scp'
10
+ require 'uri/file'
@@ -0,0 +1,7 @@
1
+ class Class
2
+ # For a class name, eg. MyApp::Module::MyClass it attempts to extract a scheme
3
+ # such as 'MYCLASS'.
4
+ def uri_scheme
5
+ name.gsub(/.*::(\w+)$/, '\1').upcase
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+
2
+ class CaseInsensitiveSymbolizedHash < Hash
3
+ def [](key)
4
+ super(normalize(key))
5
+ end
6
+
7
+ def []=(key, value)
8
+ super(normalize(key), value)
9
+ end
10
+
11
+ private
12
+ def normalize(key)
13
+ key.to_s.downcase.to_sym
14
+ end
15
+ end
@@ -1,3 +1,3 @@
1
- module SuperUri
2
- VERSION = "0.1.0"
1
+ module SuperURI
2
+ VERSION = '0.1.1'
3
3
  end
data/lib/uri-ext.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'uri'
2
+
3
+ module URI
4
+ # Helper method to hide the hedious @@schemes.
5
+ def self.<<(klass, verb = klass.uri_scheme)
6
+ self.class_variable_set(:@@schemes, {}) unless self.class_variable_get(:@@schemes)
7
+ self.class_variable_get(:@@schemes)[verb.to_s.upcase] = klass
8
+ end
9
+ end
data/lib/uri/file.rb ADDED
@@ -0,0 +1,22 @@
1
+ require 'uri'
2
+ require 'super_uri'
3
+ require 'forwardable'
4
+
5
+ module URI
6
+ class FILE < Generic
7
+
8
+ extend Forwardable
9
+ def_delegators :@path, :basename, :dirname
10
+
11
+ def buffer_open(buf, proxy, open_options)
12
+ buf << File.read(path)
13
+ buf.io.rewind
14
+ end
15
+
16
+ include OpenURI::OpenRead
17
+ end
18
+
19
+ self << FILE
20
+ end
21
+
22
+
data/lib/uri/scp.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'uri/scp'
2
+ require 'uri/open-scp'
data/super_uri.gemspec CHANGED
@@ -5,12 +5,12 @@ require 'super_uri/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "super_uri"
8
- spec.version = SuperUri::VERSION
8
+ spec.version = SuperURI::VERSION
9
9
  spec.authors = ["Konstantin Gredeskoul"]
10
10
  spec.email = ["kigster@gmail.com"]
11
11
 
12
- spec.summary = %q{Placeholder: Gem to read/write to URIs}
13
- spec.description = %q{Placeholder: Gem to read/write to URIs}
12
+ spec.summary = %q{Extension to the OpenURI module that understands many additional types of URI resources, and is able to open and read them. Included are: file://, scp://, env://, osxkeychain://, redis://, memcached:// schemes.}
13
+ spec.description = %q{Extension to the OpenURI module that understands many additional types of URI resources, and is able to open and read them. Included are: file://, scp://, env://, osxkeychain://, redis://, memcached:// schemes.}
14
14
  spec.homepage = "https://github.com/kigster/super_uri"
15
15
  spec.license = "MIT"
16
16
 
@@ -21,7 +21,14 @@ Gem::Specification.new do |spec|
21
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
22
  spec.require_paths = ["lib"]
23
23
 
24
- spec.add_development_dependency "bundler", "~> 1.13"
25
- spec.add_development_dependency "rake", "~> 10.0"
26
- spec.add_development_dependency "rspec", "~> 3.0"
24
+ spec.add_dependency 'net-scp'
25
+
26
+ spec.add_development_dependency 'bundler', '~> 1'
27
+ spec.add_development_dependency 'rake', '~> 10.0'
28
+ spec.add_development_dependency 'rspec-its'
29
+ spec.add_development_dependency 'awesome_print'
30
+ spec.add_development_dependency 'simplecov'
31
+ spec.add_development_dependency 'codeclimate-test-reporter',"~> 1.0.0"
32
+ spec.add_development_dependency 'rspec', '~> 3'
33
+
27
34
  end
metadata CHANGED
@@ -1,29 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: super_uri
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Konstantin Gredeskoul
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-01-27 00:00:00.000000000 Z
11
+ date: 2017-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: net-scp
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
31
  - - "~>"
18
32
  - !ruby/object:Gem::Version
19
- version: '1.13'
33
+ version: '1'
20
34
  type: :development
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
38
  - - "~>"
25
39
  - !ruby/object:Gem::Version
26
- version: '1.13'
40
+ version: '1'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rake
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -38,21 +52,79 @@ dependencies:
38
52
  - - "~>"
39
53
  - !ruby/object:Gem::Version
40
54
  version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-its
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: awesome_print
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: codeclimate-test-reporter
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 1.0.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 1.0.0
41
111
  - !ruby/object:Gem::Dependency
42
112
  name: rspec
43
113
  requirement: !ruby/object:Gem::Requirement
44
114
  requirements:
45
115
  - - "~>"
46
116
  - !ruby/object:Gem::Version
47
- version: '3.0'
117
+ version: '3'
48
118
  type: :development
49
119
  prerelease: false
50
120
  version_requirements: !ruby/object:Gem::Requirement
51
121
  requirements:
52
122
  - - "~>"
53
123
  - !ruby/object:Gem::Version
54
- version: '3.0'
55
- description: 'Placeholder: Gem to read/write to URIs'
124
+ version: '3'
125
+ description: 'Extension to the OpenURI module that understands many additional types
126
+ of URI resources, and is able to open and read them. Included are: file://, scp://,
127
+ env://, osxkeychain://, redis://, memcached:// schemes.'
56
128
  email:
57
129
  - kigster@gmail.com
58
130
  executables: []
@@ -69,7 +141,12 @@ files:
69
141
  - bin/console
70
142
  - bin/setup
71
143
  - lib/super_uri.rb
144
+ - lib/super_uri/class/ext.rb
145
+ - lib/super_uri/hash/case_insensitive_symbolized_hash.rb
72
146
  - lib/super_uri/version.rb
147
+ - lib/uri-ext.rb
148
+ - lib/uri/file.rb
149
+ - lib/uri/scp.rb
73
150
  - super_uri.gemspec
74
151
  homepage: https://github.com/kigster/super_uri
75
152
  licenses:
@@ -94,5 +171,7 @@ rubyforge_project:
94
171
  rubygems_version: 2.6.8
95
172
  signing_key:
96
173
  specification_version: 4
97
- summary: 'Placeholder: Gem to read/write to URIs'
174
+ summary: 'Extension to the OpenURI module that understands many additional types of
175
+ URI resources, and is able to open and read them. Included are: file://, scp://,
176
+ env://, osxkeychain://, redis://, memcached:// schemes.'
98
177
  test_files: []