bogy 1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5b1ee1ae283a26e39506b06845d4b059f72b94c5
4
+ data.tar.gz: 572b8d10e7ee2cefc1e5d0b304b16a8dc20e4e47
5
+ SHA512:
6
+ metadata.gz: f753efd287bc5965420fd58e770fce362059d1f1d8b15cd6f219ac8cc4d784f78644f60e3c8bdc5897924037caa289ce5bce85f4a661b94345537de68bb78aa4
7
+ data.tar.gz: b205e53b61e8da6be7856b3a8a726dd7b7e32c89b400093d1995e3a6691b0ef8ff0dd7b890c9eefd67688dcaf7b00119d08309c0f3f89191a577525b4b083c27
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
11
+ .DS_Store
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bogy.gemspec
4
+ gemspec
@@ -0,0 +1,47 @@
1
+ # Introduction
2
+
3
+ *bogy* is YAML wrapper, which provides a little more convenient interaction with YAML
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'bogy'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install bogy
20
+
21
+ ## Usage
22
+
23
+ ### Available methods
24
+ ```ruby
25
+ # Parsing files
26
+ path = 'file.yml'
27
+ yaml = Bogy.new(file: path)
28
+
29
+ # Parsing strings
30
+ string = "---\n:a: 1\n:b: 2\n" # Looks {a: 1, b: 2} as hash
31
+ yaml = Bogy.new(string: string)
32
+
33
+ yaml[:foo] = 'bar' # => "bar". Automatically writes to file, if you parse file
34
+ yaml[:foo] # => "bar"
35
+ yaml.delete(:foo) # => "bar". Also automatically writes to file, if you parse file
36
+ yaml.to_h # => {:a=>1, :b=>2}
37
+ yaml.to_yaml # => ---\n:a: 1\n:b: 2\n"
38
+ yaml.write_to_file('another_yaml_file.yml') # Writes to 'another_yaml_file.yml' file
39
+
40
+ # Also you can easy convert hash to YAML and write it to file
41
+ hash = {a: 1, b:2}
42
+ Bogy.new(hash: hash).write_to_file('file.yml') # Automatically converts to YAML
43
+ ```
44
+
45
+ ## Contributing
46
+
47
+ Bug reports and pull requests are welcome on GitHub at https://github.com/bogem/bogy.
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bogy/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'bogy'
8
+ spec.version = Bogy::VERSION
9
+ spec.authors = ['Albert']
10
+ spec.email = ['albertnigma@gmail.com']
11
+
12
+ spec.summary = %q{Little more convenient interaction with YAML}
13
+ spec.description = %q{bogy is YAML wrapper, which provides a little more convenient interaction with YAML}
14
+ spec.homepage = 'https://github.com/bogem/bogy'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency 'bundler', '~> 1.10'
21
+ spec.add_development_dependency 'rake', '~> 10.0'
22
+ end
@@ -0,0 +1,50 @@
1
+ require 'yaml'
2
+
3
+ require 'bogy/handler'
4
+ require 'bogy/writeable'
5
+ require 'bogy/file_handler'
6
+ require 'bogy/hash_handler'
7
+ require 'bogy/string_handler'
8
+
9
+ class Bogy
10
+ def initialize(file: nil, hash: nil, string: nil)
11
+ # If user provides two arguments
12
+ fail ArgumentError.new('You should provide only one argument') if file && string
13
+
14
+ @handler =
15
+ if file
16
+ FileHandler.new(file)
17
+ elsif hash
18
+ HashHandler.new(hash)
19
+ elsif string
20
+ StringHandler.new(string)
21
+ end
22
+ end
23
+
24
+ def [](key)
25
+ @handler.hash[key]
26
+ end
27
+
28
+ def []=(key, value)
29
+ @handler.hash[key] = value
30
+ @handler.write if @handler.is_a? Writeable
31
+ end
32
+
33
+ def delete(key)
34
+ deleted = @handler.hash.delete(key)
35
+ @handler.write if @handler.is_a? Writeable
36
+ deleted
37
+ end
38
+
39
+ def to_h
40
+ @handler.hash
41
+ end
42
+
43
+ def to_yaml
44
+ @handler.hash.to_yaml
45
+ end
46
+
47
+ def write_to_file(path)
48
+ IO.write(path, @handler.hash.to_yaml)
49
+ end
50
+ end
@@ -0,0 +1,17 @@
1
+ class Bogy
2
+ class FileHandler < Handler
3
+ include Writeable
4
+
5
+ def initialize(path)
6
+ @path = path
7
+ end
8
+
9
+ def load
10
+ YAML.load_file(@path)
11
+ end
12
+
13
+ def write
14
+ IO.write(@path, @hash.to_yaml)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,15 @@
1
+ class Bogy
2
+ # Abstract class for handlers (FileHandler, StringHandler...)
3
+ class Handler
4
+ def hash
5
+ load_to_hash
6
+ @hash
7
+ end
8
+
9
+ def load; end
10
+
11
+ def load_to_hash
12
+ @hash ||= load
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ class Bogy
2
+ class HashHandler < Handler
3
+ def initialize(hash)
4
+ @hash = hash
5
+ end
6
+
7
+ def load
8
+ @hash
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ class Bogy
2
+ class StringHandler < Handler
3
+ def initialize(string)
4
+ @string = string
5
+ end
6
+
7
+ def load
8
+ YAML.load(@string)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module Bogy
2
+ VERSION = '1.0'.freeze
3
+ end
@@ -0,0 +1,5 @@
1
+ class Bogy
2
+ module Writeable
3
+ def write; end
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bogy
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ platform: ruby
6
+ authors:
7
+ - Albert
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-23 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.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: bogy is YAML wrapper, which provides a little more convenient interaction
42
+ with YAML
43
+ email:
44
+ - albertnigma@gmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - ".travis.yml"
51
+ - Gemfile
52
+ - README.md
53
+ - Rakefile
54
+ - bogy.gemspec
55
+ - lib/bogy.rb
56
+ - lib/bogy/file_handler.rb
57
+ - lib/bogy/handler.rb
58
+ - lib/bogy/hash_handler.rb
59
+ - lib/bogy/string_handler.rb
60
+ - lib/bogy/version.rb
61
+ - lib/bogy/writeable.rb
62
+ homepage: https://github.com/bogem/bogy
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.4.8
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: Little more convenient interaction with YAML
86
+ test_files: []