env_paths 0.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
+ SHA1:
3
+ metadata.gz: c2cc22755ba9902f3b8f54858a6dd275f1fe700a
4
+ data.tar.gz: 3509ff818d39a36d394bc9bde666fa2c467fb3b7
5
+ SHA512:
6
+ metadata.gz: 6c55f3fbd5708d5a0595d872a3d00ebdd4259376c8aa51a69af00396023dc4abf46aaad9915b922325c0387230ecce83e04bbcb6e4ca15cb6ef13d22e8814e85
7
+ data.tar.gz: de871e6a93e54322e279e76772e112213ebd6a903ca2212dc85abbbabea7b140437c4cc835b81781d8d9358733df6b16a0f2362853a5fefff198f80346580b2a
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,4 @@
1
+ Documentation:
2
+ Enabled: false
3
+ Metrics/LineLength:
4
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.3
5
+ before_install:
6
+ - gem update bundler
7
+ notifications:
8
+ email:
9
+ on_success: never
10
+ on_failure: always
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in env_paths.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2016 Nick Tomlin
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,65 @@
1
+ EnvPaths
2
+ ===
3
+
4
+ Provides OS specific paths for your gem/application.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'env_paths'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install env_paths
21
+
22
+ ## Usage
23
+
24
+ ```ruby
25
+ paths = EnvPaths.get('my_app')
26
+
27
+ paths.temp
28
+ # => /var/folders/82/6j4l32lj4_g09w60_vjxh09h392d05/T/my_app-ruby
29
+
30
+ paths.config
31
+ # => /Users/your_user/Library/Preferences/my_app-ruby
32
+ ```
33
+
34
+ ### Options
35
+
36
+ `suffix`
37
+
38
+ If there is a conflict with a native application and the default suffix (`ruby`), you can pass a `suffix` key in the options hash:
39
+
40
+ ```ruby
41
+ paths = EnvPaths.get('my_app', suffix: 'my_suffix')
42
+
43
+ paths.temp
44
+ # => /var/folders/82/6j4l32lj4_g09w60_vjxh09h392d05/T/my_app-my_suffix
45
+
46
+ ```
47
+
48
+ Or disable it entirely by passing `false`:
49
+
50
+ ```ruby
51
+ paths = EnvPaths.get('my_app', suffix: false)
52
+
53
+ paths.temp
54
+ # => /var/folders/82/6j4l32lj4_g09w60_vjxh09h392d05/T/my_app
55
+
56
+ ```
57
+
58
+ ## Contributing
59
+
60
+ 1. Fork it ( https://github.com/nicktomlin/env_paths/fork )
61
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
62
+ 3. Run the tests `rake`
63
+ 4. Commit your changes (`git commit -am 'Add some feature'`)
64
+ 5. Push to the branch (`git push origin my-new-feature`)
65
+ 6. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rubocop/rake_task'
3
+ require 'rubygems/package_task'
4
+ require 'rspec/core/rake_task'
5
+
6
+ spec = eval(File.read('env_paths.gemspec')) # rubocop:disable Lint/Eval
7
+
8
+ Gem::PackageTask.new(spec)
9
+ RuboCop::RakeTask.new
10
+ RSpec::Core::RakeTask.new(:spec)
11
+
12
+ task default: %w(rubocop spec)
data/env_paths.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_paths/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'env_paths'
8
+ spec.version = EnvPaths::VERSION
9
+ spec.authors = ['Nick Tomlin']
10
+ spec.email = ['nick.tomlin@gmail.com']
11
+ spec.summary = 'Environment specific paths. A port of npm\'s env-paths'
12
+ spec.license = 'MIT'
13
+
14
+ spec.files = `git ls-files -z`.split("\x0")
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ['lib']
18
+
19
+ spec.add_development_dependency 'bundler', '~> 1.7'
20
+ spec.add_development_dependency 'rspec', '~> 3.5'
21
+ spec.add_development_dependency 'rake', '~> 10.0'
22
+ spec.add_development_dependency 'rubocop', '~> 0.45.0'
23
+ end
data/lib/env_paths.rb ADDED
@@ -0,0 +1,66 @@
1
+ require 'env_paths/version'
2
+ require 'tmpdir'
3
+ require 'etc'
4
+
5
+ module EnvPaths
6
+ OSData = Struct.new(:data, :config, :cache, :log, :temp)
7
+ HOMEDIR = Dir.home
8
+
9
+ module Linux
10
+ def self.config(app_name)
11
+ OSData.new(
12
+ ENV.fetch('XDG_DATA_HOME', File.join(HOMEDIR, '.local', 'share', app_name)),
13
+ ENV.fetch('XDG_CONFIG_HOME', File.join(HOMEDIR, '.config', app_name)),
14
+ ENV.FETCH('XDG_CACHE_HOME', File.join(HOMEDIR, '.cache', app_name)),
15
+ # https://wiki.debian.org/XDGBaseDirectorySpecification#state
16
+ ENV.FETCH('XDG_STATE_HOME', File.join(HOMEDIR, '.local', 'state', app_name)),
17
+ File.join(Dir.tmpdir, ENV['user'], app_name)
18
+ )
19
+ end
20
+ end
21
+
22
+ module Windows
23
+ def self.config(app_name)
24
+ app_data = ENV.fetch('LOCALAPPDATA', File.join(HOMEDIR, 'AppData', 'Local'))
25
+
26
+ OSData.new(
27
+ File.join(app_data, app_name, 'Data'),
28
+ File.join(app_data, app_name, 'Config'),
29
+ File.join(app_data, app_name, 'Cache'),
30
+ File.join(app_data, app_name, 'Log'),
31
+ File.join(Dir.tmpdir, app_name)
32
+ )
33
+ end
34
+ end
35
+
36
+ module MacOs
37
+ def self.config(app_name)
38
+ library = File.join(Dir.home, 'Library')
39
+
40
+ OSData.new(
41
+ File.join(library, 'Application Support', app_name),
42
+ File.join(library, 'Preferences', app_name),
43
+ File.join(library, 'Caches', app_name),
44
+ File.join(library, 'Logs', app_name),
45
+ File.join(Dir.tmpdir, app_name)
46
+ )
47
+ end
48
+ end
49
+
50
+ def self._platform
51
+ RUBY_PLATFORM
52
+ end
53
+
54
+ def self.get(app_name, opts = {})
55
+ suffix = opts.fetch(:suffix, 'ruby')
56
+ app_name += "-#{suffix}" unless opts[:suffix] == false
57
+ case _platform.downcase
58
+ when /win32/
59
+ Windows.config(app_name)
60
+ when /darwin/
61
+ MacOs.config(app_name)
62
+ else
63
+ Linux.config(app_name)
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,3 @@
1
+ module EnvPaths
2
+ VERSION = '0.0.1'.freeze
3
+ end
@@ -0,0 +1,34 @@
1
+ describe EnvPaths do
2
+ it 'accepts and uses a suffix to avoid conflicting with other applications' do
3
+ env_paths = EnvPaths.get('my_app', suffix: 'my_suffix')
4
+
5
+ expect(env_paths.data).to match(/my_app-my_suffix$/)
6
+ end
7
+
8
+ it 'allows overriding suffix by passing "false"' do
9
+ env_paths = EnvPaths.get('my_app', suffix: false)
10
+
11
+ expect(env_paths.data).to match(/my_app$/)
12
+ end
13
+
14
+ context 'MacOs' do
15
+ it 'returs osx specific data' do
16
+ allow(EnvPaths).to receive(:_platform).and_return('x86_64-darwin13.0')
17
+ env_paths = EnvPaths.get('my_app')
18
+
19
+ expect(env_paths.data).to match(%r{/Users/.*/Library/Application Support/my_app-ruby})
20
+ expect(env_paths.config).to match(%r{/Users/.*/Library/Preferences/my_app-ruby})
21
+ expect(env_paths.cache).to match(%r{/Users/.*/Library/Caches/my_app-ruby})
22
+ expect(env_paths.log).to match(%r{/Users/.*/Library/Logs/my_app-ruby})
23
+ expect(env_paths.temp).to match(%r{/var/folders/.*/my_app-ruby})
24
+ end
25
+ end
26
+
27
+ context 'Linux' do
28
+ it 'returs linux specific data'
29
+ end
30
+
31
+ context 'Windows' do
32
+ it 'returs windows specific data'
33
+ end
34
+ end
@@ -0,0 +1,14 @@
1
+ require 'env_paths'
2
+
3
+ RSpec.configure do |config|
4
+ config.expect_with :rspec do |expectations|
5
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
6
+ end
7
+
8
+ config.mock_with :rspec do |mocks|
9
+ mocks.verify_partial_doubles = true
10
+ end
11
+
12
+ config.shared_context_metadata_behavior = :apply_to_host_groups
13
+ config.order = :random
14
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: env_paths
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Nick Tomlin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-11-25 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.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.45.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.45.0
69
+ description:
70
+ email:
71
+ - nick.tomlin@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".rubocop.yml"
79
+ - ".travis.yml"
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - env_paths.gemspec
85
+ - lib/env_paths.rb
86
+ - lib/env_paths/version.rb
87
+ - spec/env_paths_spec.rb
88
+ - spec/spec_helper.rb
89
+ homepage:
90
+ licenses:
91
+ - MIT
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.2.2
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: Environment specific paths. A port of npm's env-paths
113
+ test_files:
114
+ - spec/env_paths_spec.rb
115
+ - spec/spec_helper.rb