gitconfigio 0.0.1 → 0.0.2

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.
data/.gitignore CHANGED
@@ -12,3 +12,4 @@
12
12
  *.o
13
13
  *.a
14
14
  mkmf.log
15
+ *.gem
data/.travis.yml CHANGED
@@ -1,3 +1,10 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.5
6
+ - 2.2.0
7
+ branches:
8
+ only:
9
+ - master
10
+ - test
data/README.md CHANGED
@@ -1,4 +1,12 @@
1
- # Gitconfigio
1
+ #### master:
2
+
3
+ [![Build Status](https://travis-ci.org/mocchit/gitconfigio.svg?branch=master)](https://travis-ci.org/mocchit/gitconfigio)
4
+ [![Code Climate](https://codeclimate.com/github/mocchit/gitconfigio/badges/gpa.svg)](https://codeclimate.com/github/mocchit/gitconfigio)
5
+
6
+ #### test:
7
+
8
+ [![Build Status](https://travis-ci.org/mocchit/gitconfigio.svg?branch=test)](https://travis-ci.org/mocchit/gitconfigio)
9
+ # GitConfigIO
2
10
 
3
11
  gitconfig Input/Output
4
12
 
@@ -19,12 +27,22 @@ Or install it yourself as:
19
27
  $ gem install gitconfigio
20
28
 
21
29
  ## Usage
30
+ ```
31
+ require 'gitconfigio'
32
+ # load gitconfig
33
+ conf = GitConfigIO::load('~/.gitconfig')
34
+ # create value
35
+ color = {'diff' => 'auto' , 'ui' => 'auto'}
36
+ # safe merge value
37
+ conf['color'] = color.merge conf['color'] || {}
38
+ # dump file
39
+ GitConfigIO::dump('~/.gitconfig.bak',conf)
40
+ ```
22
41
 
23
- TODO: Write usage instructions here
24
42
 
25
43
  ## Contributing
26
44
 
27
- 1. Fork it ( https://github.com/[my-github-username]/gitconfigio/fork )
45
+ 1. Fork it ( https://github.com/mocchit/gitconfigio/fork )
28
46
  2. Create your feature branch (`git checkout -b my-new-feature`)
29
47
  3. Commit your changes (`git commit -am 'Add some feature'`)
30
48
  4. Push to the branch (`git push origin my-new-feature`)
data/gitconfigio.gemspec CHANGED
@@ -5,7 +5,7 @@ require 'gitconfigio/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "gitconfigio"
8
- spec.version = Gitconfigio::VERSION
8
+ spec.version = GitConfigIO::VERSION
9
9
  spec.authors = ["mocchi"]
10
10
  spec.email = ["boom.boom.planet@gmail.com"]
11
11
  spec.summary = %q{gitconfig Input/Output}
@@ -1,3 +1,3 @@
1
- module Gitconfigio
2
- VERSION = "0.0.1"
1
+ module GitConfigIO
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/gitconfigio.rb CHANGED
@@ -48,4 +48,15 @@ module GitConfigIO
48
48
  source = generate(source) if source.class == Hash
49
49
  File.write(File.expand_path(path),source)
50
50
  end
51
+
52
+ def self.concat(hash,source = '')
53
+ source = parse(source) if source.class == String
54
+ hash.merge! source
55
+ end
56
+
57
+ def self.merge!(path,source = '')
58
+ config = load(path)
59
+ concat(config, source)
60
+ dump(path,config)
61
+ end
51
62
  end
@@ -1,11 +1,54 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Gitconfigio do
3
+ describe GitConfigIO do
4
+ ls = [
5
+ '[core]',
6
+ "\tname = mocchi"
7
+ ]
8
+ name = {
9
+ 'name' => 'mocchi'
10
+ }
11
+ ext = {
12
+ 'core' => name
13
+ }
14
+ code = <<-EOS
15
+ [core]
16
+ \tname = mocchi
17
+ EOS
18
+ color_hash = {
19
+ 'color' => {
20
+ 'ui' => 'auto'
21
+ }
22
+ }
23
+ color_str = <<-EOS
24
+ [color]
25
+ \tui = auto
26
+ EOS
27
+
4
28
  it 'has a version number' do
5
- expect(Gitconfigio::VERSION).not_to be nil
29
+ expect(GitConfigIO::VERSION).not_to be nil
30
+ end
31
+
32
+ it 'parse_value method' do
33
+ expect(GitConfigIO::parse_value("\tname = mocchi")).to eq(name.to_a[0])
34
+ end
35
+
36
+ it 'parse_node method' do
37
+ expect(GitConfigIO::parse_node(ls)).to eq(ext)
38
+ end
39
+
40
+ it 'parse method' do
41
+ expect(GitConfigIO::parse(code)).to eq(ext)
42
+ end
43
+
44
+ it 'generate method' do
45
+ expect(GitConfigIO::generate(ext)).to eq(code)
6
46
  end
7
47
 
8
- it 'does something useful' do
9
- expect(false).to eq(true)
48
+ it 'concat method' do
49
+ g_code = ext.merge color_hash
50
+ ext_cp = ext.dup
51
+ GitConfigIO::concat(ext_cp,color_str)
52
+ expect(ext_cp).to eq(g_code)
10
53
  end
11
54
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitconfigio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-02-20 00:00:00.000000000 Z
12
+ date: 2015-02-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler