cinch-storage 1.0.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 112eeeb9907a13161c643e3242a57153f138a941abfe612cc7fc96731969df2a
4
+ data.tar.gz: 6af933b544576f5f2d34f379475bee24d44dd8cd73be9dcc2708f3c51762fdce
5
+ SHA512:
6
+ metadata.gz: c02e483ce7080587718908926c3048c7d63f2aa7d8b5820656597b0a2945a1d048c08915ed84f597867cef92de5e8a6df428e655bac37e1a42724c3b4f7b0b6f
7
+ data.tar.gz: fa4d71472116de7c499d13a74dcf523bca6ed27838d7798dabcf8e7ca2cc7b750d14138ab07767a3756bec0c2b62545739bec9c94738fcf436c2821f1057b9ff
@@ -1,4 +1,23 @@
1
1
  language: ruby
2
+ env:
3
+ global:
4
+ - "JRUBY_OPTS=-Xcext.enabled=true"
2
5
  rvm:
3
- - 1.9.2
6
+ - 2.1.0
7
+ - 2.0.0
4
8
  - 1.9.3
9
+ - 1.9.2
10
+ - 1.8.7
11
+ - jruby-18mode
12
+ - jruby-19mode
13
+ - ruby-head
14
+ - jruby-head
15
+ - ree
16
+ matrix:
17
+ allow_failures:
18
+ - rvm: 1.8.7
19
+ - rvm: ree
20
+ - rvm: jruby-18mode
21
+ - rvm: jruby-19mode
22
+ - rvm: jruby-head
23
+ fast_finish: true
data/README.md CHANGED
@@ -26,6 +26,10 @@ Or install it yourself as:
26
26
 
27
27
  ## Usage
28
28
 
29
+ First, require it.
30
+
31
+ require 'cinch/storage'
32
+
29
33
  In your plugin you will need to spin up a Storage object as part of your init.
30
34
 
31
35
  def initialize(*args)
@@ -42,14 +46,10 @@ data collision.
42
46
  @storage.save
43
47
  end
44
48
 
45
- ## This is Horrible Code!
46
-
47
- The module is very fragile at the moment as a result of being written in like 20 minutes
48
- or something as a stopgap.
49
+ ## Think this is terrible?
49
50
 
50
- However, since it doesn't look like Cinch::Storage will be happening very soon I will
51
- be going back through and adding tests and error handling and proper debugging and a
52
- little tighter integration with Cinch.
51
+ I wouldn't disagree; this is my first time writing anyting remotely
52
+ ORM-like. Please feel free to fork and submit pulls to increase sanity.
53
53
 
54
54
  ## Contributing
55
55
 
@@ -4,23 +4,24 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'cinch/storage/version'
5
5
 
6
6
  Gem::Specification.new do |gem|
7
- gem.name = "cinch-storage"
7
+ gem.name = 'cinch-storage'
8
8
  gem.version = Cinch::Storage::VERSION
9
- gem.authors = ["Brian Haberer"]
10
- gem.email = ["bhaberer@gmail.com"]
11
- gem.description = %q{Simle YAML backed Storage solution for Cinch plugins.}
12
- gem.summary = %q{Simle YAML backed Storage solution for Cinch plugins.}
13
- gem.homepage = "https://github.com/bhaberer/cinch-storage"
14
-
9
+ gem.authors = ['Brian Haberer']
10
+ gem.email = ['bhaberer@gmail.com']
11
+ gem.description = %q(Simple YAML backed Storage for Cinch plugins.)
12
+ gem.summary = %q(Data Storage for Cinch plugins.)
13
+ gem.homepage = 'https://github.com/bhaberer/cinch-storage'
14
+ gem.license = 'MIT'
15
15
  gem.files = `git ls-files`.split($/)
16
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
- gem.require_paths = ["lib"]
16
+ gem.executables = gem.files.grep(/^bin\//).map { |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(/^(test|spec|features)\//)
18
+ gem.require_paths = ['lib']
19
19
 
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'
20
+ gem.add_development_dependency 'rake', '~> 12.3.3'
21
+ gem.add_development_dependency 'rspec', '~> 3'
22
+ gem.add_development_dependency 'coveralls', '~> 0.7'
23
+ gem.add_development_dependency 'cinch-test', '~> 0.1', '>= 0.1.2'
24
24
 
25
- gem.add_dependency 'psych', '~> 1.3.4'
25
+ gem.add_dependency 'cinch', '~> 2', '>= 2.0.8'
26
+ gem.add_dependency 'psych', '~> 2.0', '>= 2.0.4'
26
27
  end
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'cinch/storage/version'
3
+ require 'psych'
4
+
5
+ module Cinch
6
+ # Addon for Cinch to allow for simple YAML storage of data
7
+ class Storage
8
+ attr_accessor :filename, :data
9
+
10
+ def initialize(file, init = {})
11
+ @filename = file
12
+ @data = Psych.load(File.open(@filename)) if File.exist?(@filename)
13
+ @data ||= init
14
+ end
15
+
16
+ def save
17
+ File.open(@filename, 'w') do |file|
18
+ Psych.dump(@data, file)
19
+ end
20
+ end
21
+
22
+ def synced_save(bot = @bot)
23
+ bot.synchronize(@filename) do
24
+ save
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,5 +1,7 @@
1
+ # -*- encoding: utf-8 -*-
1
2
  module Cinch
2
- module Storage
3
- VERSION = "1.0.0"
3
+ # versioning info
4
+ class Storage
5
+ VERSION = '1.2.1'
4
6
  end
5
7
  end
@@ -1,43 +1,56 @@
1
1
  require 'spec_helper'
2
2
 
3
+ Thing = Struct.new(:foo)
4
+
3
5
  class MyPlugin
4
6
  include Cinch::Plugin
5
7
 
6
8
  def initialize(*args)
7
9
  super
8
- @storage = CinchStorage.new(config[:filename] || '/dev/null', [])
10
+ @storage = Cinch::Storage.new(config[:filename] || '/dev/null', [])
9
11
  end
10
12
 
11
- match /store (.*)/
12
13
 
13
- def execute(m, thing)
14
- @storage.data << thing
14
+ match /store (.*)/, method: :store_text
15
+ match /storething (.*)/, method: :store_object
16
+
17
+ def store_text(m, text)
18
+ @storage.data << text
19
+ @storage.synced_save(@bot)
20
+ end
21
+
22
+ def store_object(m, text)
23
+ @storage.data << Thing.new(text)
15
24
  @storage.synced_save(@bot)
16
25
  end
17
26
  end
18
27
 
19
28
 
20
- describe CinchStorage do
29
+ describe Cinch::Storage do
21
30
  include Cinch::Test
22
31
 
23
32
  before(:each) do
24
33
  @filename = '/tmp/storage_test.tmp'
25
34
  File.delete(@filename) if File.exist?(@filename)
26
- @bot = make_bot(MyPlugin, { :filename => @filename })
35
+ @bot = make_bot(MyPlugin, { filename: @filename })
27
36
  end
28
37
 
29
38
  it 'should allow users to store information between bot runs' do
30
- storage = CinchStorage.new(@filename, [])
39
+ storage = Cinch::Storage.new(@filename, [])
31
40
  storage.data << 'foo'
32
41
  storage.save
33
42
 
34
- CinchStorage.new(@filename).data.
35
- should include 'foo'
43
+ expect(Cinch::Storage.new(@filename).data)
44
+ .to include('foo')
36
45
  end
37
46
 
38
47
  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
48
+ 10.times { |x| get_replies(make_message(@bot, "!store #{x}")) }
49
+ expect(Cinch::Storage.new(@filename).data.length).to eq(10)
50
+ end
51
+
52
+ it 'should write object data to the disk' do
53
+ get_replies(make_message(@bot, "!storething foobar"))
54
+ expect(Cinch::Storage.new(@filename).data.first).to eq(Thing.new('foobar'))
42
55
  end
43
56
  end
@@ -1,4 +1,4 @@
1
1
  require 'coveralls'
2
2
  Coveralls.wear!
3
- require 'cinch-storage'
3
+ require 'cinch/storage'
4
4
  require 'cinch/test'
metadata CHANGED
@@ -1,139 +1,158 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cinch-storage
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
5
- prerelease:
4
+ version: 1.2.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Brian Haberer
9
- autorequire:
8
+ autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-07-04 00:00:00.000000000 Z
11
+ date: 2021-01-27 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rake
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
- version: '0'
19
+ version: 12.3.3
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
- version: '0'
26
+ version: 12.3.3
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rspec
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - "~>"
36
32
  - !ruby/object:Gem::Version
37
- version: '0'
33
+ version: '3'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - "~>"
44
39
  - !ruby/object:Gem::Version
45
- version: '0'
40
+ version: '3'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: coveralls
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - "~>"
52
46
  - !ruby/object:Gem::Version
53
- version: '0'
47
+ version: '0.7'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - "~>"
60
53
  - !ruby/object:Gem::Version
61
- version: '0'
54
+ version: '0.7'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: cinch-test
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - "~>"
68
60
  - !ruby/object:Gem::Version
69
- version: '0'
61
+ version: '0.1'
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 0.1.2
70
65
  type: :development
71
66
  prerelease: false
72
67
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
68
  requirements:
75
- - - ! '>='
69
+ - - "~>"
70
+ - !ruby/object:Gem::Version
71
+ version: '0.1'
72
+ - - ">="
76
73
  - !ruby/object:Gem::Version
77
- version: '0'
74
+ version: 0.1.2
75
+ - !ruby/object:Gem::Dependency
76
+ name: cinch
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '2'
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: 2.0.8
85
+ type: :runtime
86
+ prerelease: false
87
+ version_requirements: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - "~>"
90
+ - !ruby/object:Gem::Version
91
+ version: '2'
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: 2.0.8
78
95
  - !ruby/object:Gem::Dependency
79
96
  name: psych
80
97
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
98
  requirements:
83
- - - ~>
99
+ - - "~>"
100
+ - !ruby/object:Gem::Version
101
+ version: '2.0'
102
+ - - ">="
84
103
  - !ruby/object:Gem::Version
85
- version: 1.3.4
104
+ version: 2.0.4
86
105
  type: :runtime
87
106
  prerelease: false
88
107
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
108
  requirements:
91
- - - ~>
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: '2.0'
112
+ - - ">="
92
113
  - !ruby/object:Gem::Version
93
- version: 1.3.4
94
- description: Simle YAML backed Storage solution for Cinch plugins.
114
+ version: 2.0.4
115
+ description: Simple YAML backed Storage for Cinch plugins.
95
116
  email:
96
117
  - bhaberer@gmail.com
97
118
  executables: []
98
119
  extensions: []
99
120
  extra_rdoc_files: []
100
121
  files:
101
- - .gitignore
102
- - .travis.yml
122
+ - ".gitignore"
123
+ - ".travis.yml"
103
124
  - Gemfile
104
125
  - LICENSE.txt
105
126
  - README.md
106
127
  - Rakefile
107
128
  - cinch-storage.gemspec
108
- - lib/cinch-storage.rb
129
+ - lib/cinch/storage.rb
109
130
  - lib/cinch/storage/version.rb
110
131
  - spec/cinch-storage_spec.rb
111
132
  - spec/spec_helper.rb
112
133
  homepage: https://github.com/bhaberer/cinch-storage
113
- licenses: []
114
- post_install_message:
134
+ licenses:
135
+ - MIT
136
+ metadata: {}
137
+ post_install_message:
115
138
  rdoc_options: []
116
139
  require_paths:
117
140
  - lib
118
141
  required_ruby_version: !ruby/object:Gem::Requirement
119
- none: false
120
142
  requirements:
121
- - - ! '>='
143
+ - - ">="
122
144
  - !ruby/object:Gem::Version
123
145
  version: '0'
124
146
  required_rubygems_version: !ruby/object:Gem::Requirement
125
- none: false
126
147
  requirements:
127
- - - ! '>='
148
+ - - ">="
128
149
  - !ruby/object:Gem::Version
129
150
  version: '0'
130
151
  requirements: []
131
- rubyforge_project:
132
- rubygems_version: 1.8.24
133
- signing_key:
134
- specification_version: 3
135
- summary: Simle YAML backed Storage solution for Cinch plugins.
152
+ rubygems_version: 3.2.6
153
+ signing_key:
154
+ specification_version: 4
155
+ summary: Data Storage for Cinch plugins.
136
156
  test_files:
137
157
  - spec/cinch-storage_spec.rb
138
158
  - spec/spec_helper.rb
139
- has_rdoc:
@@ -1,25 +0,0 @@
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
-