kstarv 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MmMxNDMwY2YzNDM1MzZjOTUzZjgxMjY2ZjA3YTJlZWYzNTBjZmU5Yw==
4
+ N2EyNGIzZjEyODQ5OTUxMzc0ZDE2MDVkMGQ1ZWI0MjhmZDk2NzE5Mg==
5
5
  data.tar.gz: !binary |-
6
- MGI2NGVlODk2MDFiMzg5NzRmOGU2MzY5YTc0Y2Q3MTJjMGJjYTcwZg==
6
+ YTIzMmQyMTJiMWI4OWUwZWZhYjEzNWJmZDM2YjIwNDMyMGQwZThkYQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NDFlNTM1YWEyMTVlZjRiMTdlNmZjOGJjYmE4Yzc4ZTIwNWVkNWM0M2EzZGNh
10
- NjY0MzhkZDRjYjZmNmNmNDczZmE3MTJhMGNmODFjZDZlMWNmYzE5OTA2YTBl
11
- OTRmN2Y1OWZkZDM4MzIyODdhMjc2MjZmYzZmOTk4YzgxMDRmMTk=
9
+ YTQ0NjgxM2M3ZjVjNTI2YTc3ZjZjY2NjMmRmYWZiOTVhODU4YjZmMzQ5N2Fj
10
+ YWEyMzM5MGM1NmUzZTY3YjVkYzc2NWY4OGU1MjBhZjNlZWNmMmNjNTlmMjZh
11
+ ZDAxZTMyMjc2N2Y5MTA3NWMwZTgzMjBjYjExOTJlNjBhMzkxMDg=
12
12
  data.tar.gz: !binary |-
13
- NGQ0N2EzNDA5NTJkYWJjMWNhZjU5NzZhOTI5ODgyZjdkODhhODY5N2UwNzQx
14
- NGY4Mjc4MmE3ZDM2NjVmZjQxYjFkMDliYzhlYWNkZWRmN2FlMWM1YzFkMGFh
15
- YmI1Njk0ZjQyNzg1ZTFiYzJlMGU3OGUxOWI0YjQwZjczNGZmOWM=
13
+ ZTEyMWFmZjVmYjg5N2Q0YzEzOWU0MWMxZTUxNzlhNzUwODBkNzU1ZWVhMzJh
14
+ ZjM5OWY0YTkxYWM1MjBlYTBlNDY0ZDc1NDE3ZDNjMjRiMWU1OTQwYmRhY2Nl
15
+ ZjE1OTA2ODA3OGZjMzlkZWZmODZlN2I1YzVjOWQ1ODg5YzdhYjc=
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Wrap a Ruby object by parsing file including key-values
4
4
 
5
- [![Build Status](https://travis-ci.org/simlegate/kstarv.png?branch=master)](https://travis-ci.org/simlegate/kstarv)
5
+ [![Gem Version](https://badge.fury.io/rb/kstarv.png)](http://badge.fury.io/rb/kstarv) [![Build Status](https://travis-ci.org/simlegate/kstarv.png?branch=master)](https://travis-ci.org/simlegate/kstarv)
6
6
  ## Installation
7
7
 
8
8
  Add this line to your application's Gemfile:
@@ -18,7 +18,7 @@ Or install it yourself as:
18
18
  $ gem install kstarv
19
19
 
20
20
  ## Example text file
21
- centos network config file
21
+ Centos network config file
22
22
  ```ruby
23
23
  DEVICE=eth0
24
24
  HWADDR=00:1E:67:24:E8:2D
@@ -33,7 +33,7 @@ GATEWAY=192.168.0.1
33
33
  BORADCAST=192.168.0.255
34
34
  ```
35
35
  ## Usage
36
- set decollator spliting key and vaule
36
+ Set decollator spliting key and vaule
37
37
  ```ruby
38
38
  # decollator is '=' by default
39
39
  @kv = Kstarv.from(/path/to/config)
@@ -41,20 +41,14 @@ set decollator spliting key and vaule
41
41
  @kv = Kstarv.from(/path/to/config, '*')
42
42
  ```
43
43
 
44
- set key case
45
- ```ruby
46
- # 'upcase' or 'downcase'
47
- @kv.case = 'upcase'
48
- @kv.write
49
- ```
50
- read value by key
44
+ Read value by key
51
45
  ```ruby
52
46
  @kv.device # => eth0
53
47
  @kv.ipaddr # => 192.168.0.201
54
48
  ....
55
49
  ```
56
50
 
57
- write value
51
+ Write value
58
52
  ```ruby
59
53
  @kv.ipaddr # => 127.0.0.1
60
54
  @kv.write
@@ -67,7 +61,7 @@ write value
67
61
  # BORADCAST=192.168.0.255
68
62
  # ....
69
63
  ```
70
- set key case
64
+ Set key case
71
65
  ```ruby
72
66
  # you can set case of key
73
67
  # downcase and @case is true by default
@@ -81,6 +75,17 @@ set key case
81
75
  # gatewaY=192.168.0.1
82
76
  # boradcast=192.168.0.255
83
77
  # ....
78
+ #
79
+ @kv.case = true
80
+ @kv.write
81
+ # output:
82
+ # ......
83
+ # BOOTPROTO=static
84
+ # IPADDR=192.168.0.201
85
+ # NETMASK=255.255.255.0
86
+ # GATEWAY=192.168.0.1
87
+ # BORADCAST=192.168.0.255
88
+ # ....
84
89
  ```
85
90
 
86
91
  ## Contributing
data/kstarv.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["simlegate@163.com"]
11
11
  spec.description = %q{Wrap a Ruby object by parsing text file including key-values}
12
12
  spec.summary = %q{Wrap a Ruby object by parsing text file including key-values}
13
- spec.homepage = ""
13
+ spec.homepage = "https://github.com/simlegate/kstarv"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
data/lib/kstarv.rb CHANGED
@@ -3,13 +3,16 @@ require "kstarv/k_v"
3
3
 
4
4
  module Kstarv
5
5
  class NoSuchFile < StandardError
6
+ def initialize path
7
+ @path = path
8
+ end
9
+
6
10
  def message
7
- # TODO should say file path to message
8
- "can not find _such file_"
11
+ "can not find #{@path}"
9
12
  end
10
13
  end
11
14
 
12
15
  def self.from file,join='='
13
- File.exists?(file) ? KV.new(file, join) : (raise NoSuchFile)
16
+ File.exists?(file) ? KV.new(file, join) : (raise NoSuchFile.new(file))
14
17
  end
15
18
  end
data/lib/kstarv/k_v.rb CHANGED
@@ -19,8 +19,6 @@ module Kstarv
19
19
  # @net_work_config.write
20
20
  def write
21
21
  kvs = @instance_vars.map do | var |
22
- # TODO var upcase or downcase
23
- # 调用case method
24
22
  "#{convert_case(var)}=#{instance_var_get(var)}"
25
23
  end
26
24
  # kvs => [ "DEVICE=eth0", "HWADDR=00:1E:67:24:E8:2D", "TYPE=Ethernet" ...]
@@ -40,7 +38,7 @@ module Kstarv
40
38
  f.each do |line|
41
39
  # remove blank line
42
40
  # remove beginning and end space
43
- create_attr(line.strip.split(@join)) unless line.gsub("\n",'').length == 0
41
+ create_attr(line.strip.split(@join)) if line.gsub("\n",'').length != 0 && !(line.strip =~ /^#/)
44
42
  end
45
43
  end
46
44
  end
@@ -52,9 +50,8 @@ module Kstarv
52
50
  create_attr [name.to_s.split('=')[0], v]
53
51
  end
54
52
 
55
- # TODO
56
53
  def to_s
57
- 'convert kv to str'
54
+ @str ||= File.read(@file)
58
55
  end
59
56
 
60
57
  private
@@ -1,3 +1,3 @@
1
1
  module Kstarv
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -6,6 +6,7 @@ ONBOOT=yes
6
6
  NM_CONTROLLED=no
7
7
  BOOTPROTO=static
8
8
  IPADDR=192.168.0.201
9
+ # comment by simlegate
9
10
  NETMASK=255.255.255.0
10
11
  GATEWAY=192.168.0.1
11
12
  BORADCAST=192.168.0.255
@@ -6,15 +6,16 @@ describe '#KV' do
6
6
  @kv = Kstarv::KV.new @file
7
7
  end
8
8
 
9
+ after :each do
10
+ FileUtils.copy File.expand_path('../../fixtures/kv', __FILE__),@file
11
+ end
12
+
9
13
  context 'dynamic create attr' do
10
14
  it 'should not including other attr ' do
11
15
  @kv.instance_variable_get(:@instance_vars).should == [:device, :hwaddr, :type, :uuid, :onboot, :nm_controlled, :bootproto, :ipaddr, :netmask, :gateway, :boradcast]
12
16
  end
13
17
 
14
18
  context 'attr do not exists' do
15
- after :each do
16
- FileUtils.copy File.expand_path('../../fixtures/kv', __FILE__),@file
17
- end
18
19
 
19
20
  it 'should be empty string' do
20
21
  @kv.chinesename.should == ''
@@ -62,14 +63,33 @@ describe '#KV' do
62
63
  end
63
64
 
64
65
  context 'set key case' do
65
- it '____' do
66
- pending('wait me....')
66
+ it 'downcase by default' do
67
+ @kv.write
68
+ File.readlines(@file).first.should == "device=eth0\n"
67
69
  end
70
+
71
+ it 'set upcase' do
72
+ @kv.case = false
73
+ @kv.write
74
+ File.readlines(@file).first.should == "DEVICE=eth0\n"
75
+ end
76
+ end
77
+
78
+ it 'convert content of file to string' do
79
+ @kv.to_s.should == File.read(@file)
68
80
  end
69
81
 
70
82
  context 'private method' do
71
- it '____' do
72
- pending('wait me....')
83
+ before :each do
84
+ @methods = [:create_attr, :save_instance_var, :prefix_at, :instance_var_get, :convert_case ]
85
+ end
86
+
87
+ it 'should have 5 privte methods ' do
88
+ @methods.count.should == 5
89
+ end
90
+
91
+ it 'should respond_to all of @methods' do
92
+ @methods.map {|method| @kv.private_methods.should include method}
73
93
  end
74
94
  end
75
95
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kstarv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - 都是牛奶装什么特仑苏丶
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-23 00:00:00.000000000 Z
11
+ date: 2013-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -91,7 +91,7 @@ files:
91
91
  - spec/kstarv/k_v_spec.rb
92
92
  - spec/kstarv_spec.rb
93
93
  - spec/spec_helper.rb
94
- homepage: ''
94
+ homepage: https://github.com/simlegate/kstarv
95
95
  licenses:
96
96
  - MIT
97
97
  metadata: {}
@@ -111,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
111
  version: '0'
112
112
  requirements: []
113
113
  rubyforge_project:
114
- rubygems_version: 2.0.6
114
+ rubygems_version: 2.0.7
115
115
  signing_key:
116
116
  specification_version: 4
117
117
  summary: Wrap a Ruby object by parsing text file including key-values