cinch-storage 0.0.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
data/README.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Cinch::Storage
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/cinch-storage.png)](http://badge.fury.io/rb/cinch-storage)
4
+ [![Dependency Status](https://gemnasium.com/bhaberer/cinch-storage.png)](https://gemnasium.com/bhaberer/cinch-storage)
5
+ [![Build Status](https://travis-ci.org/bhaberer/cinch-storage.png?branch=master)](https://travis-ci.org/bhaberer/cinch-storage)
6
+ [![Coverage Status](https://coveralls.io/repos/bhaberer/cinch-storage/badge.png?branch=master)](https://coveralls.io/r/bhaberer/cinch-storage?branch=master)
7
+ [![Code Climate](https://codeclimate.com/github/bhaberer/cinch-storage.png)](https://codeclimate.com/github/bhaberer/cinch-storage)
8
+
3
9
  Simple YAML backed Storage solution for Cinch plugins.
4
10
 
5
11
  Warning: Once Cinch's author finishes Cinch::Storage I will deprecate this gem.
data/Rakefile CHANGED
@@ -1 +1,7 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
7
+ task :test => :spec
@@ -1,7 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'cinch-storage/version'
4
+ require 'cinch/storage/version'
5
5
 
6
6
  Gem::Specification.new do |gem|
7
7
  gem.name = "cinch-storage"
@@ -17,5 +17,10 @@ Gem::Specification.new do |gem|
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ["lib"]
19
19
 
20
- gem.add_dependency('psych', '1.3.4')
20
+ gem.add_development_dependency 'rake'
21
+ gem.add_development_dependency 'rspec'
22
+ gem.add_development_dependency 'coveralls'
23
+ gem.add_development_dependency 'cinch-test'
24
+
25
+ gem.add_dependency 'psych', '~> 1.3.4'
21
26
  end
@@ -1,5 +1,5 @@
1
1
  module Cinch
2
2
  module Storage
3
- VERSION = "0.0.2"
3
+ VERSION = "1.0.0"
4
4
  end
5
5
  end
data/lib/cinch-storage.rb CHANGED
@@ -1,2 +1,25 @@
1
- require "cinch-storage/version"
2
- require "cinch-storage/storage"
1
+ require 'cinch/storage/version'
2
+ require 'psych'
3
+
4
+ class CinchStorage
5
+ attr_accessor :filename, :data
6
+
7
+ def initialize(file, init = Hash.new)
8
+ @filename = file
9
+ @data = YAML::load(File.open(@filename)) if File::exist?(@filename)
10
+ @data ||= init
11
+ end
12
+
13
+ def save
14
+ File.open(@filename, 'w') do |file|
15
+ YAML::dump(@data, file)
16
+ end
17
+ end
18
+
19
+ def synced_save(bot = @bot)
20
+ bot.synchronize(@filename) do
21
+ save
22
+ end
23
+ end
24
+ end
25
+
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ class MyPlugin
4
+ include Cinch::Plugin
5
+
6
+ def initialize(*args)
7
+ super
8
+ @storage = CinchStorage.new(config[:filename] || '/dev/null', [])
9
+ end
10
+
11
+ match /store (.*)/
12
+
13
+ def execute(m, thing)
14
+ @storage.data << thing
15
+ @storage.synced_save(@bot)
16
+ end
17
+ end
18
+
19
+
20
+ describe CinchStorage do
21
+ include Cinch::Test
22
+
23
+ before(:each) do
24
+ @filename = '/tmp/storage_test.tmp'
25
+ File.delete(@filename) if File.exist?(@filename)
26
+ @bot = make_bot(MyPlugin, { :filename => @filename })
27
+ end
28
+
29
+ it 'should allow users to store information between bot runs' do
30
+ storage = CinchStorage.new(@filename, [])
31
+ storage.data << 'foo'
32
+ storage.save
33
+
34
+ CinchStorage.new(@filename).data.
35
+ should include 'foo'
36
+ end
37
+
38
+ it 'should handle multiple bot threads attempting to write to the same file' do
39
+ 10.times { |x| get_replies(make_message(@bot, "!store #{x}"))}
40
+ CinchStorage.new(@filename).data.length.
41
+ should == 10
42
+ end
43
+ end
@@ -0,0 +1,4 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+ require 'cinch-storage'
4
+ require 'cinch/test'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cinch-storage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,14 +9,78 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-29 00:00:00.000000000 Z
12
+ date: 2013-07-04 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: coveralls
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: cinch-test
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
14
78
  - !ruby/object:Gem::Dependency
15
79
  name: psych
16
80
  requirement: !ruby/object:Gem::Requirement
17
81
  none: false
18
82
  requirements:
19
- - - '='
83
+ - - ~>
20
84
  - !ruby/object:Gem::Version
21
85
  version: 1.3.4
22
86
  type: :runtime
@@ -24,7 +88,7 @@ dependencies:
24
88
  version_requirements: !ruby/object:Gem::Requirement
25
89
  none: false
26
90
  requirements:
27
- - - '='
91
+ - - ~>
28
92
  - !ruby/object:Gem::Version
29
93
  version: 1.3.4
30
94
  description: Simle YAML backed Storage solution for Cinch plugins.
@@ -35,14 +99,16 @@ extensions: []
35
99
  extra_rdoc_files: []
36
100
  files:
37
101
  - .gitignore
102
+ - .travis.yml
38
103
  - Gemfile
39
104
  - LICENSE.txt
40
105
  - README.md
41
106
  - Rakefile
42
107
  - cinch-storage.gemspec
43
108
  - lib/cinch-storage.rb
44
- - lib/cinch-storage/storage.rb
45
- - lib/cinch-storage/version.rb
109
+ - lib/cinch/storage/version.rb
110
+ - spec/cinch-storage_spec.rb
111
+ - spec/spec_helper.rb
46
112
  homepage: https://github.com/bhaberer/cinch-storage
47
113
  licenses: []
48
114
  post_install_message:
@@ -67,4 +133,7 @@ rubygems_version: 1.8.24
67
133
  signing_key:
68
134
  specification_version: 3
69
135
  summary: Simle YAML backed Storage solution for Cinch plugins.
70
- test_files: []
136
+ test_files:
137
+ - spec/cinch-storage_spec.rb
138
+ - spec/spec_helper.rb
139
+ has_rdoc:
@@ -1,24 +0,0 @@
1
- class CinchStorage
2
- require 'yaml'
3
-
4
- attr_accessor :filename, :data
5
-
6
- def initialize(file)
7
- @filename = file
8
- @data = YAML::load(File.open(@filename)) if File::exist?(@filename)
9
- @data ||= Hash.new
10
- end
11
-
12
- def save
13
- File.open(@filename, 'w') do |file|
14
- YAML::dump(@data, file)
15
- end
16
- end
17
-
18
- def synced_save(bot)
19
- bot.synchronize(@filename) do
20
- save
21
- end
22
- end
23
- end
24
-