env_compat 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +63 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/env_compat.gemspec +23 -0
- data/lib/env_compat/version.rb +3 -0
- data/lib/env_compat.rb +71 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 48b6b2f664497b9bc21ab7262b68012252a8aa9d
|
4
|
+
data.tar.gz: abab2b2f22800d4f1e5e07f0297bf16bcd8b13ed
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 74705b27246406f69d22ccb43c01849b2903225942845777293e6667d9b09ccea3e0c4538f0605aa0dc5542dcb442f2391928432d88736e34403d9cb441a38c6
|
7
|
+
data.tar.gz: 4a83f5b98a9eb24c1cbcaf207385712aa1fb1978b91425b530f59efb8e24d5a6743217de933224b9521880e1cf2bdbd44c0afb5ad2083019dfcac480b0f731da
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Daniel P. Clark
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# EnvCompat
|
2
|
+
|
3
|
+
Your tool for converting special characters to ENV friendly variables.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'env_compat', '~> 0.1'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install env_compat
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
EnvCompat.encode "https://github.com/company/private-repo.git"
|
25
|
+
# => "HTTPS_CFF_GITHUB_D_COM_F_COMPANY_F_PRIVATE_M_REPO_D_GIT"
|
26
|
+
|
27
|
+
EnvCompat.decode "HTTPS_CFF_GITHUB_D_COM_F_COMPANY_F_PRIVATE_M_REPO_D_GIT"
|
28
|
+
# => HTTPS://GITHUB.COM/COMPANY/PRIVATE-REPO.GIT
|
29
|
+
```
|
30
|
+
|
31
|
+
To define you own custom special character mappings feel free to overwrite
|
32
|
+
the EnvCompat module instance method of `:mapping`.
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
def EnvCompat.mapping
|
36
|
+
{
|
37
|
+
'1' => '/', # Forward Slash
|
38
|
+
'2' => ':', # Colon
|
39
|
+
'3' => '-', # Minus
|
40
|
+
'4' => '_', # Underscore
|
41
|
+
'5' => '.' # Dot
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
EnvCompat.encode "https://github.com/company/private-repo.git"
|
46
|
+
# => "HTTPS_211_GITHUB_5_COM_1_COMPANY_1_PRIVATE_3_REPO_5_GIT"
|
47
|
+
```
|
48
|
+
|
49
|
+
## Development
|
50
|
+
|
51
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
52
|
+
|
53
|
+
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).
|
54
|
+
|
55
|
+
## Contributing
|
56
|
+
|
57
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/danielpclark/env_compat.
|
58
|
+
|
59
|
+
|
60
|
+
## License
|
61
|
+
|
62
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
63
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "env_compat"
|
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
|
data/bin/setup
ADDED
data/env_compat.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'env_compat/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "env_compat"
|
8
|
+
spec.version = EnvCompat::VERSION
|
9
|
+
spec.authors = ["Daniel P. Clark"]
|
10
|
+
spec.email = ["6ftdan@gmail.com"]
|
11
|
+
spec.summary = %q{EnvCompat provides a way to map special characters to env friendly chars}
|
12
|
+
spec.description = %q{EnvCompat provides a way to map special characters to environment friendly characters}
|
13
|
+
spec.homepage = "https://github.com/danielpclark/env_compat"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
16
|
+
spec.bindir = "exe"
|
17
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
21
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
22
|
+
spec.add_development_dependency "minitest", "~> 5.8"
|
23
|
+
end
|
data/lib/env_compat.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
require "env_compat/version"
|
2
|
+
|
3
|
+
module EnvCompat
|
4
|
+
class << self
|
5
|
+
def encode str
|
6
|
+
builder = ''
|
7
|
+
_ = CodeBlock.new
|
8
|
+
str.chars.each do |chr|
|
9
|
+
case chr
|
10
|
+
when *mapping.values
|
11
|
+
builder = _.toggle(builder) unless _.in_block?
|
12
|
+
builder << mapping.invert[chr]
|
13
|
+
else
|
14
|
+
builder = _.toggle(builder) if _.in_block?
|
15
|
+
builder << chr
|
16
|
+
end
|
17
|
+
end
|
18
|
+
builder.upcase
|
19
|
+
end
|
20
|
+
|
21
|
+
def decode str
|
22
|
+
builder = ''
|
23
|
+
_ = CodeBlock.new
|
24
|
+
str.chars.each do |chr|
|
25
|
+
next _.cycle if chr == '_'
|
26
|
+
if _.in_block?
|
27
|
+
case chr
|
28
|
+
when *mapping.keys
|
29
|
+
builder << mapping[chr]
|
30
|
+
else
|
31
|
+
raise "Invalid input!"
|
32
|
+
end
|
33
|
+
else
|
34
|
+
builder << chr
|
35
|
+
end
|
36
|
+
end
|
37
|
+
builder.upcase
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
def mapping
|
42
|
+
{
|
43
|
+
'F' => '/', # Forward Slash
|
44
|
+
'C' => ':', # Colon
|
45
|
+
'M' => '-', # Minus
|
46
|
+
'U' => '_', # Underscore
|
47
|
+
'D' => '.' # Dot
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
class CodeBlock
|
52
|
+
def initialize
|
53
|
+
@code_block = [false, true].cycle
|
54
|
+
end
|
55
|
+
|
56
|
+
def cycle
|
57
|
+
@code_block.next
|
58
|
+
end
|
59
|
+
|
60
|
+
def in_block?
|
61
|
+
@code_block.peek
|
62
|
+
end
|
63
|
+
|
64
|
+
def toggle str
|
65
|
+
@code_block.next
|
66
|
+
str + '_'
|
67
|
+
end
|
68
|
+
end
|
69
|
+
private_constant :CodeBlock
|
70
|
+
end
|
71
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: env_compat
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Daniel P. Clark
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-26 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.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
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: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.8'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.8'
|
55
|
+
description: EnvCompat provides a way to map special characters to environment friendly
|
56
|
+
characters
|
57
|
+
email:
|
58
|
+
- 6ftdan@gmail.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".travis.yml"
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- bin/console
|
70
|
+
- bin/setup
|
71
|
+
- env_compat.gemspec
|
72
|
+
- lib/env_compat.rb
|
73
|
+
- lib/env_compat/version.rb
|
74
|
+
homepage: https://github.com/danielpclark/env_compat
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
metadata: {}
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 2.5.1
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: EnvCompat provides a way to map special characters to env friendly chars
|
98
|
+
test_files: []
|