configstruct 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 +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +23 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +9 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +62 -0
- data/Rakefile +20 -0
- data/configstruct.gemspec +25 -0
- data/lib/config_struct.rb +44 -0
- data/spec/files/config.yml +5 -0
- data/spec/lib/config_struct_spec.rb +31 -0
- data/spec/spec_helper.rb +35 -0
- metadata +131 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bb58d6d732dd097347d370186a628e928d952895
|
4
|
+
data.tar.gz: f3bcc9f1cd3a29221290012cb695f74e58e84563
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2fd2311c70f643639a514fa977474f2e0211ef0efb6a41d6940f76cd749fa1a624976d87a31907853f0b2432a34672dc385b1bb35103454ef7005f2475ec1100
|
7
|
+
data.tar.gz: fa588bd523532d54302959fe8d9a23e225dd2c597a38dfc7176fe1a825d695695fed476895a071e9b553c0edfbd4e29cb997d5af6ab95e8373a822dbcedbddb5
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
repo_token: PJCj4fDDbnGb3BA3qehKdZmQOWGXVulAl
|
data/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
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
|
23
|
+
vendor/
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 mose
|
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,62 @@
|
|
1
|
+
Configstruct
|
2
|
+
=============
|
3
|
+
|
4
|
+
[](http://rubygems.org/gems/configstruct)
|
5
|
+
[](https://travis-ci.org/mose/configstruct)
|
6
|
+
[](https://coveralls.io/r/mose/configstruct)
|
7
|
+
[](https://gemnasium.com/mose/configstruct)
|
8
|
+
[](https://codeclimate.com/github/mose/configstruct)
|
9
|
+
|
10
|
+
----
|
11
|
+
|
12
|
+
This gem is a lib for managing configfile for cli applications, including
|
13
|
+
|
14
|
+
- call a setup of the config file if it does not exist
|
15
|
+
- edit configuration and update the config file
|
16
|
+
|
17
|
+
It's for now totally experimental, please do not use yet.
|
18
|
+
|
19
|
+
## Installation
|
20
|
+
|
21
|
+
Add this line to your application's Gemfile:
|
22
|
+
|
23
|
+
gem 'configstruct'
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
````ruby
|
28
|
+
require 'cliprompt'
|
29
|
+
class Config < ConfigStruct
|
30
|
+
|
31
|
+
include Cliprompt
|
32
|
+
|
33
|
+
def set_defaults
|
34
|
+
super
|
35
|
+
default :name, 'default'
|
36
|
+
default :url, 'http://greenruby.org'
|
37
|
+
end
|
38
|
+
|
39
|
+
def setup
|
40
|
+
values = {}
|
41
|
+
output.puts Paint['Applicaton configuration.', :blue]
|
42
|
+
values['api_id'] = guess 'API_CLIENT', 'What is your Client ID?'
|
43
|
+
values['api_secret'] = guess 'API_SECRET', 'What is your Secret Key?'
|
44
|
+
write values
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
````
|
49
|
+
|
50
|
+
## Contributing
|
51
|
+
|
52
|
+
1. Fork it
|
53
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
54
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
55
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
56
|
+
5. Create a new Pull Request
|
57
|
+
|
58
|
+
Copyright
|
59
|
+
----------
|
60
|
+
|
61
|
+
(c) Copy is right, 2014 - mose - this code is distributed under MIT license
|
62
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
require 'bundler/setup'
|
8
|
+
require 'bundler/gem_tasks'
|
9
|
+
require 'rake/testtask'
|
10
|
+
require 'rspec/core/rake_task' # RSpec 2.0
|
11
|
+
|
12
|
+
desc 'launch rspec tests'
|
13
|
+
task :spec do
|
14
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
15
|
+
t.rspec_opts = ['-c', '-f progress', '-r ./spec/spec_helper.rb']
|
16
|
+
t.pattern = 'spec/lib/**/*_spec.rb'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
task default: :spec
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "configstruct"
|
7
|
+
spec.version = File.read(File.expand_path('../CHANGELOG.md', __FILE__))[/([0-9]+\.[0-9]+\.[0-9]+)/]
|
8
|
+
spec.authors = ["mose"]
|
9
|
+
spec.email = ["mose@mose.com"]
|
10
|
+
spec.summary = %q{Lib for managing config files based on OpenStruct.}
|
11
|
+
spec.description = %q{Lib for managing config files based on OpenStruct, includes file saving and prompt at creation.}
|
12
|
+
spec.homepage = "https://github.com/mose/configstruct"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(/^spec\//)
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
spec.add_development_dependency 'rspec'
|
23
|
+
spec.add_development_dependency 'coveralls'
|
24
|
+
spec.add_development_dependency 'codeclimate-test-reporter'
|
25
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
class ConfigStruct < OpenStruct
|
5
|
+
|
6
|
+
def initialize(options = nil, input = STDIN, output = STDOUT)
|
7
|
+
super(options)
|
8
|
+
set_defaults
|
9
|
+
prepare_dirs
|
10
|
+
addvalues
|
11
|
+
end
|
12
|
+
|
13
|
+
def set_defaults
|
14
|
+
default :basedir, '/tmp'
|
15
|
+
default :basefile, File.join(self.basedir, 'config.yml')
|
16
|
+
end
|
17
|
+
|
18
|
+
def prepare_dirs
|
19
|
+
FileUtils.mkdir_p self.basedir unless Dir.exist? self.basedir
|
20
|
+
end
|
21
|
+
|
22
|
+
def addvalues
|
23
|
+
setup unless File.exist? self.basefile
|
24
|
+
YAML.load_file(self.basefile).each do |k, v|
|
25
|
+
new_ostruct_member(k)
|
26
|
+
send("#{k}=", v)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def setup
|
31
|
+
write Hash.new
|
32
|
+
end
|
33
|
+
|
34
|
+
def default(var, value)
|
35
|
+
send(var).nil? && send("#{var}=", value)
|
36
|
+
end
|
37
|
+
|
38
|
+
def write(values)
|
39
|
+
File.open(self.basefile, 'w') do |f|
|
40
|
+
f.write YAML.dump(values)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'config_struct'
|
5
|
+
|
6
|
+
describe ConfigStruct do
|
7
|
+
|
8
|
+
let(:basedir) { File.expand_path('../../files', __FILE__) }
|
9
|
+
let(:basefile) { File.expand_path('../../files/config.yml', __FILE__) }
|
10
|
+
let(:options) { { basedir: basedir, basefile: basefile } }
|
11
|
+
let(:value1) { 'newdefault' }
|
12
|
+
|
13
|
+
describe '.default' do
|
14
|
+
subject { ConfigStruct.new options }
|
15
|
+
before { subject.default :var, value1 }
|
16
|
+
it { expect(subject.var).to eq value1 }
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'new' do
|
20
|
+
context 'when there is no config file, ' do
|
21
|
+
let(:basefile) { File.expand_path('../../files/xxx.yml', __FILE__) }
|
22
|
+
after { FileUtils.rm basefile if File.exist? basefile }
|
23
|
+
subject { ConfigStruct.new options }
|
24
|
+
it 'then a config file is created calling' do
|
25
|
+
expect(subject.basefile).to eq basefile
|
26
|
+
expect(File.exist? basefile).to be_true
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
$LOAD_PATH << File.expand_path('../../lib', __FILE__)
|
2
|
+
require 'rubygems'
|
3
|
+
require 'bundler'
|
4
|
+
|
5
|
+
if ENV['COV']
|
6
|
+
require 'simplecov'
|
7
|
+
SimpleCov.profiles.define :app do
|
8
|
+
add_filter '/vendor/'
|
9
|
+
add_filter '/spec/'
|
10
|
+
end
|
11
|
+
SimpleCov.start :app
|
12
|
+
else
|
13
|
+
require 'coveralls'
|
14
|
+
Coveralls.wear!
|
15
|
+
|
16
|
+
# require "codeclimate-test-reporter"
|
17
|
+
# CodeClimate::TestReporter.start
|
18
|
+
end
|
19
|
+
|
20
|
+
RSpec.configure do |config|
|
21
|
+
config.mock_with :rspec
|
22
|
+
config.expect_with :rspec do |c|
|
23
|
+
c.syntax = :expect
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# Warning:
|
28
|
+
# I'm not an expert tester, and on this project I wanted to try
|
29
|
+
# a super-isolation way. So each spec is testing each method and
|
30
|
+
# uses a lock of stubbing and doubles. Up to now I find it quite
|
31
|
+
# convenient because it makes the interdependencies more obvious,
|
32
|
+
# and when something changes in the code the need for changes in
|
33
|
+
# the stubbing is an occasion to think about the whole architecture.
|
34
|
+
# Also, it doesn't lie about the coverage, by stubbing all things,
|
35
|
+
# a thing is not covered if not explicitely tested.
|
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: configstruct
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- mose
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-31 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.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: coveralls
|
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: codeclimate-test-reporter
|
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
|
+
description: Lib for managing config files based on OpenStruct, includes file saving
|
84
|
+
and prompt at creation.
|
85
|
+
email:
|
86
|
+
- mose@mose.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".coveralls.yml"
|
92
|
+
- ".gitignore"
|
93
|
+
- ".travis.yml"
|
94
|
+
- CHANGELOG.md
|
95
|
+
- Gemfile
|
96
|
+
- LICENSE.txt
|
97
|
+
- README.md
|
98
|
+
- Rakefile
|
99
|
+
- configstruct.gemspec
|
100
|
+
- lib/config_struct.rb
|
101
|
+
- spec/files/config.yml
|
102
|
+
- spec/lib/config_struct_spec.rb
|
103
|
+
- spec/spec_helper.rb
|
104
|
+
homepage: https://github.com/mose/configstruct
|
105
|
+
licenses:
|
106
|
+
- MIT
|
107
|
+
metadata: {}
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options: []
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 2.2.2
|
125
|
+
signing_key:
|
126
|
+
specification_version: 4
|
127
|
+
summary: Lib for managing config files based on OpenStruct.
|
128
|
+
test_files:
|
129
|
+
- spec/files/config.yml
|
130
|
+
- spec/lib/config_struct_spec.rb
|
131
|
+
- spec/spec_helper.rb
|