bogy 1.1.0.1 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -1
- data/README.md +14 -10
- data/bogy.gemspec +1 -1
- data/lib/bogy.rb +7 -9
- data/lib/bogy/handler.rb +5 -5
- data/lib/bogy/version.rb +1 -1
- data/lib/bogy/writeable.rb +2 -0
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 017b3b815d63846fd691bb52d4d00e1cd5a9fbfc
|
4
|
+
data.tar.gz: 5c179c98447f8da644bf1b18bee7335045b9e262
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2821f00a1ca2b99d8d9e68aef66fafd60b7761b827560cd81d0038c2c5bd5466b91a3c54cb12065e45c5ef8ac6e85b421b8333168369e836c7e47ad1a2fad546
|
7
|
+
data.tar.gz: 9dec09f747276eec7aa02e47b75f7f9256893b5c68cb3caa7fdcad774b74f153bffc9810bdbf42953f16eb4a654c5c8d294458b359190cc31a10838d60ae7f19
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
*bogy* is Ruby
|
1
|
+
*bogy* is tiny Ruby tool, which provides a little more convenient interaction with YAML
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/bogy.svg)](http://badge.fury.io/rb/bogy)
|
4
4
|
[![Build Status](https://travis-ci.org/bogem/bogy.svg?branch=master)](https://travis-ci.org/bogem/bogy)
|
@@ -7,7 +7,11 @@
|
|
7
7
|
|
8
8
|
## Installation
|
9
9
|
|
10
|
-
|
10
|
+
`gem install bogy`
|
11
|
+
|
12
|
+
**or**
|
13
|
+
|
14
|
+
add `gem 'bogy'` to your application's Gemfile
|
11
15
|
|
12
16
|
## Available methods
|
13
17
|
```ruby
|
@@ -15,20 +19,20 @@
|
|
15
19
|
path = 'file.yml'
|
16
20
|
yaml = Bogy.new(file: path)
|
17
21
|
|
22
|
+
# Parsing hashes
|
23
|
+
hash = { 'a' => 1, 'b' => 2 }
|
24
|
+
yaml = Bogy.new(hash: hash)
|
25
|
+
|
18
26
|
# Parsing strings
|
19
|
-
string = "---\
|
27
|
+
string = "---\na: 1\nb: 2\n" # Looks {'a' => 1, 'b' => 2} as hash
|
20
28
|
yaml = Bogy.new(string: string)
|
21
29
|
|
22
30
|
yaml['foo'] = 'bar' # => "bar". Automatically writes to file, if you parse file
|
23
31
|
yaml['foo'] # => "bar"
|
24
32
|
yaml.delete('foo') # => "bar". Also automatically writes to file, if you parse file
|
25
|
-
yaml.to_h # => {
|
26
|
-
yaml.to_yaml # => ---\
|
27
|
-
yaml.write_to_file('
|
28
|
-
|
29
|
-
# Also you can easy convert hash to YAML and write it to file
|
30
|
-
hash = {a: 1, b:2}
|
31
|
-
Bogy.new(hash: hash).write_to_file('file.yml') # Automatically converts to YAML
|
33
|
+
yaml.to_h # => {'a'=>1, 'b'=>2}
|
34
|
+
yaml.to_yaml # => ---\na: 1\nb: 2\n"
|
35
|
+
yaml.write_to_file('yaml_file.yml') # Converts to YAML and writes to 'yaml_file.yml' file
|
32
36
|
```
|
33
37
|
|
34
38
|
## License
|
data/bogy.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ['albertnigma@gmail.com']
|
11
11
|
|
12
12
|
spec.summary = %q{Ruby wrapper for YAML}
|
13
|
-
spec.description = %q{bogy is Ruby
|
13
|
+
spec.description = %q{bogy is tiny Ruby tool, which provides a little more convenient interaction with YAML}
|
14
14
|
spec.homepage = 'https://github.com/bogem/bogy'
|
15
15
|
spec.license = 'MIT'
|
16
16
|
spec.required_ruby_version = '>= 1.9.3'
|
data/lib/bogy.rb
CHANGED
@@ -7,19 +7,17 @@ require 'bogy/hash_handler'
|
|
7
7
|
require 'bogy/string_handler'
|
8
8
|
|
9
9
|
class Bogy
|
10
|
-
def initialize(options =
|
11
|
-
# If user provides
|
12
|
-
fail ArgumentError,
|
13
|
-
|
14
|
-
# If user provides more than one arguments
|
15
|
-
fail ArgumentError, 'you should provide only one argument' if options.length > 1
|
10
|
+
def initialize(options = {})
|
11
|
+
# If user provides incorrect number of arguments (not one)
|
12
|
+
fail ArgumentError, "wrong number of arguments (#{options.length} for 1)" if options.length > 1 || options.empty?
|
16
13
|
|
17
14
|
@handler =
|
18
|
-
|
15
|
+
case
|
16
|
+
when options[:file]
|
19
17
|
FileHandler.new(options[:file])
|
20
|
-
|
18
|
+
when options[:hash]
|
21
19
|
HashHandler.new(options[:hash])
|
22
|
-
|
20
|
+
when options[:string]
|
23
21
|
StringHandler.new(options[:string])
|
24
22
|
end
|
25
23
|
end
|
data/lib/bogy/handler.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
class Bogy
|
2
2
|
# Abstract class for handlers (FileHandler, StringHandler...)
|
3
|
+
# Handler is object, which can work with certain data type (string, YAML file and etc.)
|
4
|
+
# and convert it to Ruby hash
|
3
5
|
class Handler
|
4
6
|
def hash
|
5
|
-
|
7
|
+
@hash ||= load
|
6
8
|
end
|
7
9
|
|
10
|
+
# Abstract method
|
11
|
+
# Used to convert raw YAML data from specified format to Ruby hash
|
8
12
|
def load; end
|
9
|
-
|
10
|
-
def load_to_hash
|
11
|
-
@hash ||= load
|
12
|
-
end
|
13
13
|
end
|
14
14
|
end
|
data/lib/bogy/version.rb
CHANGED
data/lib/bogy/writeable.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bogy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Albert Nigmatzianov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,8 +52,8 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 3.3.0
|
55
|
-
description: bogy is Ruby
|
56
|
-
|
55
|
+
description: bogy is tiny Ruby tool, which provides a little more convenient interaction
|
56
|
+
with YAML
|
57
57
|
email:
|
58
58
|
- albertnigma@gmail.com
|
59
59
|
executables: []
|
@@ -95,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
95
|
version: '0'
|
96
96
|
requirements: []
|
97
97
|
rubyforge_project:
|
98
|
-
rubygems_version: 2.4.
|
98
|
+
rubygems_version: 2.4.5.1
|
99
99
|
signing_key:
|
100
100
|
specification_version: 4
|
101
101
|
summary: Ruby wrapper for YAML
|