yapit 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5c5bd617c4fb0f018fc907b0e0eb3d34950659bb
4
+ data.tar.gz: 9c0dbac122c27eb33785d952c933a1a1d06e4465
5
+ SHA512:
6
+ metadata.gz: 570b66ecd4f48ecc0e6659de5357a368d274de4d8dcf02ab4ef7b19726734f31baac32f9025374581eee2eca6715adc8680878b49cc822213e47f269a848f81a
7
+ data.tar.gz: 57d98b52570430b13fa7175463016d3b7dd9d9e3afd8cfde922170e02561c576e9e6be988e3fb665db32dbe02fd710abb70873ab0a1df9e28698e4a6b1258dee
@@ -0,0 +1,17 @@
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
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - "1.9.3"
4
+ - "2.0.0"
5
+ - "2.1.1"
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 tanabe-sunao
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.
@@ -0,0 +1,32 @@
1
+ # Yapit
2
+
3
+ [![Build Status](https://travis-ci.org/sunaot/yapit.png?branch=master)](https://travis-ci.org/sunaot/yapit)
4
+
5
+ Yet another simple Pit library.
6
+
7
+ ## Installation
8
+
9
+ $ gem install yapit
10
+
11
+ ## Usage
12
+
13
+ ```
14
+ require 'yapit'
15
+
16
+ Yapit.configure do |c|
17
+ c.root = '/path/to/pit/directory' # ~/.pit for default
18
+ c.default_profile = 'twitter' # 'default' for default
19
+ end
20
+
21
+ yapit = Yapit.new('profile_name') # or use default_profile
22
+ auth = yapit.get('twitter.com')
23
+ puts auth['id'], auth['id']
24
+ ```
25
+
26
+ ## Contributing
27
+
28
+ 1. Fork it
29
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
30
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
31
+ 4. Push to the branch (`git push origin my-new-feature`)
32
+ 5. Create new Pull Request
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ task 'default' => 'test'
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.libs << 'test/lib'
8
+ t.test_files = FileList['test/**/*_test.rb']
9
+ end
@@ -0,0 +1,63 @@
1
+ require "yapit/version"
2
+ require 'yaml'
3
+ require 'pathname'
4
+ require 'forwardable'
5
+
6
+ class Yapit
7
+ class Configuration
8
+ extend Forwardable
9
+ attr_accessor :root, :default_profile
10
+ def_delegators :@yapit, :root=, :default_profile=
11
+
12
+ def initialize(yapit)
13
+ @yapit = yapit
14
+ end
15
+ end
16
+
17
+ class << self
18
+ attr_accessor :root, :default_profile
19
+
20
+ def configure &block
21
+ c = Configuration.new(Yapit)
22
+ block.call(c)
23
+ end
24
+ end
25
+
26
+ def initialize profile = nil
27
+ @root = Pathname.new(self.class.root || '~/.pit').expand_path
28
+ @default_profile = self.class.default_profile || 'default'
29
+ @profile = profile
30
+ end
31
+
32
+ def write name, value
33
+ lock_file = @root + ".#{profile}.lock"
34
+ lock_file.open('w') do |f|
35
+ f.flock(File::LOCK_EX)
36
+ object = read_file
37
+ object[name] = value
38
+ profile_file.open('w') {|f| f.write(YAML::dump(object)) }
39
+ lock_file.unlink
40
+ end
41
+ end
42
+ alias_method :set, :write
43
+
44
+ def read name
45
+ read_file[name] || {}
46
+ end
47
+ alias_method :get, :read
48
+
49
+ private
50
+ def read_file
51
+ YAML::load(profile_file.read)
52
+ rescue Errno::ENOENT
53
+ {}
54
+ end
55
+
56
+ def profile
57
+ "#{@profile || @default_profile}.yaml"
58
+ end
59
+
60
+ def profile_file
61
+ @root + profile
62
+ end
63
+ end
@@ -0,0 +1,3 @@
1
+ class Yapit
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,71 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/unit'
3
+ require 'test_friends/tempfile'
4
+ require 'yapit'
5
+
6
+ class TestYapit < MiniTest::Unit::TestCase
7
+ def setup
8
+ @file = TestFriends::Tempfile.new :extname => '.yaml'
9
+ create_sample_yaml_file @file
10
+ Yapit.configure do |c|
11
+ c.root = @file.dirname
12
+ end
13
+ @yapit = Yapit.new @file.basename(@file.extname)
14
+ end
15
+
16
+ def teardown
17
+ @file.teardown
18
+ end
19
+
20
+ def test_read
21
+ assert_equal 'Foo', @yapit.read('sample')['foo']
22
+ end
23
+
24
+ def test_write
25
+ sample = { 'foo' => 'Changed', 'bar' => 'Bar', 'baz' => 'Baz' }
26
+ @yapit.write('sample', sample)
27
+ assert_equal 'Changed', @yapit.read('sample')['foo']
28
+ end
29
+
30
+ def test_write_does_not_break_other_record
31
+ sample = { 'foo' => 'Changed', 'bar' => 'Bar', 'baz' => 'Baz' }
32
+ @yapit.write('sample', sample)
33
+ assert_equal 'Bar', @yapit.read('sample')['bar']
34
+ end
35
+
36
+ def test_read_a_missing_profile
37
+ @file.unlink
38
+ assert_equal({}, @yapit.read('sample'))
39
+ end
40
+
41
+ def test_invalid_root_directory
42
+ @file.parent.rmtree
43
+ assert_equal({}, @yapit.read('sample'))
44
+ end
45
+
46
+ def test_empty_yaml_file
47
+ @file.unlink
48
+ @file.touch
49
+ assert_raises(NoMethodError) { @yapit.read('sample') }
50
+ end
51
+
52
+ def test_default
53
+ file = TestFriends::Tempfile.new :filename => 'default.yaml'
54
+ create_sample_yaml_file file
55
+ Yapit.configure do |c|
56
+ c.root = file.dirname
57
+ end
58
+ assert_equal 'Foo', Yapit.new.read('sample')['foo']
59
+ end
60
+
61
+ private
62
+ def create_sample_yaml_file file
63
+ file.open('w') {|f| f.write(<<-YAML.gsub(/^ /, '')) }
64
+ ---
65
+ sample:
66
+ foo: Foo
67
+ bar: Bar
68
+ baz: Baz
69
+ YAML
70
+ end
71
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'yapit/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "yapit"
8
+ spec.version = Yapit::VERSION
9
+ spec.authors = ["sunaot"]
10
+ spec.email = ["sunao.tanabe@gmail.com"]
11
+ spec.description = %q{Yet another simple Pit library.}
12
+ spec.summary = %q{Yet another simple Pit library which does not use pit.yaml file to switch context. Have no backward API compatibility to original cho45/pit interfaces.}
13
+ spec.homepage = "https://github.com/sunaot/yapit"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^test/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake", '~> 0'
23
+ spec.add_development_dependency "test_friends", '~> 0'
24
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yapit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - sunaot
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-11 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
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: test_friends
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
+ description: Yet another simple Pit library.
56
+ email:
57
+ - sunao.tanabe@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".travis.yml"
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - lib/yapit.rb
69
+ - lib/yapit/version.rb
70
+ - test/yapit_test.rb
71
+ - yapit.gemspec
72
+ homepage: https://github.com/sunaot/yapit
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.2.2
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Yet another simple Pit library which does not use pit.yaml file to switch
96
+ context. Have no backward API compatibility to original cho45/pit interfaces.
97
+ test_files:
98
+ - test/yapit_test.rb
99
+ has_rdoc: