user-configurations 0.0.1.pre

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: 8ba776a1792dfcdcf240050bf38ecd316cec095f
4
+ data.tar.gz: bef0f44caee78ca5f273ecb2153c2b6caf6c927c
5
+ SHA512:
6
+ metadata.gz: 552f316b1056bdea49bdbb009f5c54eaf4a4ebc827436d0a9fbdeefd54be0830b915141667bc4bb3189fe1c7a60a1d2dafbd64b3edfec91ba1b30ef351ce604d
7
+ data.tar.gz: 74916acf45fa9cabdcd0d8a795aa4bf1a21a2b59834f7df95ef4273aa5dd792807087a151629591462e9098269eaba47185875ba2f7b0f43f3cb493fba38878c
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,19 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ Documentation:
4
+ Enabled: false
5
+
6
+ AllCops:
7
+ # Include gemspec and Rakefile
8
+ Include:
9
+ - '**/*.gemspec'
10
+ - '**/Rakefile'
11
+ Exclude:
12
+ - 'vendor/**/*'
13
+ - 'db/**/*'
14
+ - 'bin/rails'
15
+ - 'bin/spring'
16
+ - 'bin/rake'
17
+ # By default, the rails cops are not run. Override in project or home
18
+ # directory .rubocop.yml files, or by giving the -R/--rails option.
19
+ RunRailsCops: true
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,11 @@
1
+ # This configuration was generated by `rubocop --auto-gen-config`
2
+ # on 2014-05-06 13:30:11 -0300 using RuboCop version 0.21.0.
3
+ # The point is for the user to remove these configuration records
4
+ # one by one as the offenses are removed from the code base.
5
+ # Note that changes in the inspected code, or installation of new
6
+ # versions of RuboCop, may require this file to be generated again.
7
+
8
+ # Offense count: 1
9
+ # Configuration parameters: Exclude.
10
+ FileName:
11
+ Enabled: false
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in user-configurations.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,13 @@
1
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
2
+ Version 2, December 2004
3
+
4
+ Copyright (C) 2013 Rafael Almeida <eusou@rafaelalmeida.net>
5
+
6
+ Everyone is permitted to copy and distribute verbatim or modified
7
+ copies of this license document, and changing it is allowed as long
8
+ as the name is changed.
9
+
10
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
11
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
12
+
13
+ 0. You just DO WHAT THE FUCK YOU WANT TO.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # User::Configurations
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'user-configurations'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install user-configurations
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/stupie4ever/user-configurations/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create a new Pull Request
@@ -0,0 +1,8 @@
1
+ require 'yaml'
2
+ require 'delegate'
3
+
4
+ require_relative 'user_configurations/version'
5
+ require_relative 'user_configurations/configurations'
6
+
7
+ module UserConfigurations
8
+ end
@@ -0,0 +1,41 @@
1
+ module UserConfigurations
2
+ class Configuration < SimpleDelegator
3
+ attr_accessor :project_name
4
+
5
+ def initialize(project_name)
6
+ @project_name = project_name
7
+ super global.merge(user).merge(environment)
8
+ end
9
+
10
+ def store(values)
11
+ File.write user_file, YAML.dump(user.merge(values))
12
+ merge! values
13
+ end
14
+
15
+ private
16
+
17
+ def global
18
+ load global_file
19
+ end
20
+
21
+ def user
22
+ load user_file
23
+ end
24
+
25
+ def user_file
26
+ File.expand_path File.join('~', ".#{project_name}")
27
+ end
28
+
29
+ def global_file
30
+ File.join('/', 'etc', project_name)
31
+ end
32
+
33
+ def load(file)
34
+ File.file?(file) ? YAML.load_file(file) : {}
35
+ end
36
+
37
+ def environment
38
+ ENV
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,3 @@
1
+ module UserConfigurations
2
+ VERSION = '0.0.1.pre'
3
+ end
@@ -0,0 +1,7 @@
1
+ require 'bundler/setup'
2
+ Bundler.setup
3
+
4
+ require 'user-configurations'
5
+
6
+ RSpec.configure do |_|
7
+ end
@@ -0,0 +1,73 @@
1
+ require 'spec_helper'
2
+
3
+ module UserConfigurations
4
+ describe Configuration do
5
+ subject(:configuration) { Configuration.new project_name }
6
+
7
+ let(:project_name) { 'some-fake-project' }
8
+
9
+ let(:register_environment) { ENV[key] = 'environment' }
10
+ let(:register_user) { register user_file, key => 'user' }
11
+ let(:register_global) { register global_file, key => 'global' }
12
+
13
+ let(:user_file) { File.expand_path(File.join('~', ".#{ project_name }")) }
14
+ let(:global_file) { File.join('/', 'etc', project_name) }
15
+
16
+ let(:key) { 'KEY' }
17
+
18
+ before do
19
+ ENV.delete key
20
+ allow(File).to receive(:file?).with(user_file).and_return(false)
21
+ allow(File).to receive(:file?).with(global_file).and_return(false)
22
+ end
23
+
24
+ it 'fetches from environment variables first' do
25
+ register_environment
26
+ register_user
27
+ register_global
28
+ expect(configuration[key]).to eq('environment')
29
+ end
30
+
31
+ it "fetches from user configuration file in `$HOME/.project' second" do
32
+ register_user
33
+ register_global
34
+ expect(configuration[key]).to eq('user')
35
+ end
36
+
37
+ it "fetches from global configuration file in `/etc/project' third" do
38
+ register_global
39
+ expect(configuration[key]).to eq('global')
40
+ end
41
+
42
+ describe '#store' do
43
+ subject(:store) { configuration.store values }
44
+
45
+ let(:values) { { other_key => other_value } }
46
+ let(:other_key) { 'OTHER_KEY' }
47
+ let(:other_value) { 'other_value' }
48
+
49
+ it "stores values in user configuration file in `$HOME/.project'" do
50
+ expect(File).to receive(:write).with(user_file, YAML.dump(values))
51
+ store
52
+ end
53
+
54
+ it 'keeps the contents of user configuration file' do
55
+ register_user
56
+ expect(File).to receive(:write)
57
+ .with(user_file, YAML.dump({ key => 'user' }.merge(values)))
58
+ store
59
+ end
60
+
61
+ it 'fetches the new stored values' do
62
+ allow(File).to receive(:write)
63
+ store
64
+ expect(configuration.fetch other_key).to eq(other_value)
65
+ end
66
+ end
67
+
68
+ def register(file, contents)
69
+ allow(File).to receive(:file?).with(file).and_return(true)
70
+ allow(YAML).to receive(:load_file).with(file).and_return(contents)
71
+ end
72
+ end
73
+ end
@@ -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 'user_configurations/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'user-configurations'
8
+ spec.version = UserConfigurations::VERSION
9
+ spec.authors = ['Rafael da Silva Almeida']
10
+ spec.email = ['eusou@rafaelalmeida.net']
11
+ spec.summary = %q(Configurations for a project)
12
+ spec.description = %q(Configurations for a project, it will read from
13
+ env vars, local or global files)
14
+ spec.homepage = 'http://github.com/stupied4ever/user-configurations'
15
+ spec.license = 'wtfpl'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(/^(test|spec|features)\//)
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_development_dependency 'rspec', '~> 2.0'
23
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: user-configurations
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.pre
5
+ platform: ruby
6
+ authors:
7
+ - Rafael da Silva Almeida
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ description: |-
28
+ Configurations for a project, it will read from
29
+ env vars, local or global files
30
+ email:
31
+ - eusou@rafaelalmeida.net
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - .gitignore
37
+ - .rspec
38
+ - .rubocop.yml
39
+ - .rubocop_todo.yml
40
+ - Gemfile
41
+ - LICENSE.txt
42
+ - README.md
43
+ - lib/user-configurations.rb
44
+ - lib/user_configurations/configuration.rb
45
+ - lib/user_configurations/version.rb
46
+ - spec/spec_helper.rb
47
+ - spec/user_configurations/configuration_spec.rb
48
+ - user-configurations.gemspec
49
+ homepage: http://github.com/stupied4ever/user-configurations
50
+ licenses:
51
+ - wtfpl
52
+ metadata: {}
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - '>'
65
+ - !ruby/object:Gem::Version
66
+ version: 1.3.1
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 2.2.2
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: Configurations for a project
73
+ test_files:
74
+ - spec/spec_helper.rb
75
+ - spec/user_configurations/configuration_spec.rb