hoohoo 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7791d3e5e0e7d84b84f2ffffed8e42dc1f159f72
4
+ data.tar.gz: 261d1afb55342bb7a6c63e5fb6c6996d51a22f92
5
+ SHA512:
6
+ metadata.gz: 73203e7902f08bf8ec93cc8b8fbd9f4163c77710a836118b7c92eaa96d3ea2250be4096ef6f1e848d42a3fdf82f7e922caf56c4fc6d7affd920725aadc0cab30
7
+ data.tar.gz: caf4024a4d266f1b4b56afd0c606af9955d2dc5a18d986829e47620f15f1a3390d6374bc23165e88d3169cc45c01fe26979d9e4089047a9b0f6986de139d811f
data/.gitignore ADDED
@@ -0,0 +1,22 @@
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
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.travis.yml ADDED
@@ -0,0 +1,15 @@
1
+ .travis.ymllanguage: ruby
2
+ cache: bundler
3
+
4
+ rvm:
5
+ - jruby
6
+ - 2.0.0
7
+
8
+ script: 'bundle exec rake'
9
+
10
+ notifications:
11
+ email:
12
+ recipients:
13
+ - bonetsu@gmail.com
14
+ on_failure: change
15
+ on_success: never
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hoohoo.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,11 @@
1
+ guard 'rspec', cmd: "bundle exec rspec" do
2
+ # watch /lib/ files
3
+ watch(%r{^lib/(.+).rb$}) do |m|
4
+ "spec/#{m[1]}_spec.rb"
5
+ end
6
+
7
+ # watch /spec/ files
8
+ watch(%r{^spec/(.+).rb$}) do |m|
9
+ "spec/#{m[1]}.rb"
10
+ end
11
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Bonet Sugiarto
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.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Hoohoo
2
+
3
+ This is description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'hoohoo'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install hoohoo
18
+
19
+ ## Usage
20
+
21
+ This is usage instructions
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/[my-github-username]/hoohoo/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'rspec/core/rake_task'
2
+ require 'bundler/gem_tasks'
3
+
4
+ # Default directory to look in is `/specs`
5
+ # Run with `rake spec`
6
+ RSpec::Core::RakeTask.new(:spec) do |task|
7
+ task.rspec_opts = ['--color', '--format', 'nested']
8
+ end
9
+
10
+ task :default => :spec
data/hoohoo.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'hoohoo/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "hoohoo"
8
+ spec.version = Hoohoo::VERSION
9
+ spec.authors = ["Bonet Sugiarto"]
10
+ spec.email = ["bonetsu@gmail.com"]
11
+ spec.summary = %q{This is summary}
12
+ spec.description = %q{This is description}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+
24
+ spec.add_development_dependency "rspec"
25
+ spec.add_development_dependency "rspec-nc"
26
+ spec.add_development_dependency "guard"
27
+ spec.add_development_dependency "guard-rspec"
28
+ spec.add_development_dependency "pry"
29
+ spec.add_development_dependency "pry-remote"
30
+ spec.add_development_dependency "pry-nav"
31
+ spec.add_development_dependency "crimp"
32
+ end
@@ -0,0 +1,34 @@
1
+ require 'singleton'
2
+
3
+ class DataStore
4
+ include Singleton
5
+
6
+ def set(data)
7
+ hash_data = {
8
+ :original => data[:original],
9
+ :transformed => data[:transformed]
10
+ }
11
+
12
+ container.store(data[:id], hash_data)
13
+ end
14
+
15
+ def get(id)
16
+ container.fetch(id)
17
+ end
18
+
19
+ def reset(id)
20
+ original = container.fetch(id)[:original]
21
+ hash_data = {
22
+ :original => original,
23
+ :transformed => original
24
+ }
25
+
26
+ container.store(id, hash_data)
27
+ end
28
+
29
+ private
30
+
31
+ def container
32
+ @store ||= Hash.new
33
+ end
34
+ end
@@ -0,0 +1,3 @@
1
+ module Hoohoo
2
+ VERSION = "0.0.1"
3
+ end
data/lib/hoohoo.rb ADDED
@@ -0,0 +1,47 @@
1
+ require 'hoohoo/version'
2
+ require 'hoohoo/data_store'
3
+ require 'crimp'
4
+
5
+ module Hoohoo
6
+ def self.transforms(data, till_midnight = 60)
7
+ identifier = Crimp.signature(data)
8
+ cloned_data = deep_copy data
9
+ transformed = yield cloned_data
10
+
11
+ store({
12
+ :id => identifier,
13
+ :original => data,
14
+ :transformed => transformed
15
+ })
16
+
17
+ check(identifier, till_midnight)
18
+
19
+ identifier
20
+ end
21
+
22
+ def self.get(id)
23
+ DataStore.instance.get(id)[:transformed]
24
+ end
25
+
26
+ def self.midnight(id)
27
+ reset_data_at(id)
28
+ end
29
+
30
+ private
31
+
32
+ def self.store(data)
33
+ DataStore.instance.set(data)
34
+ end
35
+
36
+ def self.deep_copy(object)
37
+ Marshal.load(Marshal.dump(object))
38
+ end
39
+
40
+ def self.check(id, seconds)
41
+ Thread.new { sleep seconds; reset_data_at id }
42
+ end
43
+
44
+ def self.reset_data_at(id)
45
+ DataStore.instance.reset(id)
46
+ end
47
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe DataStore do
4
+ let(:instance) { DataStore.instance }
5
+ let(:original) { 'bar' }
6
+ let(:transformed) { 'BAR' }
7
+
8
+ before(:each) do
9
+ instance.set({
10
+ :id => 'foo',
11
+ :original => original,
12
+ :transformed => transformed
13
+ })
14
+ end
15
+
16
+ describe 'set(data)' do
17
+ it 'stores original and transformed data' do
18
+ expect(instance.get('foo')[:original]).to eq(original)
19
+ expect(instance.get('foo')[:transformed]).to eq(transformed)
20
+ end
21
+ end
22
+
23
+ describe 'get(id)' do
24
+ it 'returns data object' do
25
+ expect(instance.get('foo')).to be_a Hash
26
+ expect(instance.get('foo').key?(:original)).to be true
27
+ expect(instance.get('foo').key?(:transformed)).to be true
28
+ end
29
+ end
30
+
31
+ describe 'reset(id)' do
32
+ it 'replaces the transformed data with original data' do
33
+ instance.reset('foo')
34
+ foo = instance.get('foo')
35
+ expect(foo[:original]).to eq(foo[:transformed])
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hoohoo do
4
+ let(:data) {{ :key => 'value' }}
5
+ let(:till_midnight) { 0 }
6
+
7
+ def create_new_instance
8
+ @id = subject.transforms(data, till_midnight) do |data|
9
+ data.each do |key, value|
10
+ data.tap { |d| d[key].upcase! }
11
+ end
12
+ end
13
+ end
14
+
15
+ describe '.transforms(data, till_midnight)' do
16
+ it 'returns a MD5 hash of the provided data' do
17
+ create_new_instance
18
+ expect(@id).to be_a String
19
+ expect(@id).to eq '24e73d3a4f027ff81ed4f32c8a9b8713'
20
+ end
21
+ end
22
+
23
+ describe '.get(id)' do
24
+ context 'before midnight (before time expired)' do
25
+ it 'returns the transformed data' do
26
+ Hoohoo.stub(:check)
27
+ create_new_instance
28
+ expect(subject.get(@id)).to eq({ :key => 'VALUE' })
29
+ end
30
+ end
31
+
32
+ context 'past midnight (after time expired)' do
33
+ it 'returns the original data' do
34
+ create_new_instance
35
+ Hoohoo.reset_data_at @id
36
+ expect(subject.get(@id)).to eq({ :key => 'value' })
37
+ end
38
+ end
39
+ end
40
+
41
+ describe '.midnight(id)' do
42
+ context 'before midnight (before time expired)' do
43
+ it 'restores the data to its original state' do
44
+ Hoohoo.stub(:check)
45
+ create_new_instance
46
+ subject.midnight(@id)
47
+ expect(subject.get(@id)).to eq({ :key => 'value' })
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,2 @@
1
+ require 'pry'
2
+ require 'hoohoo'
metadata ADDED
@@ -0,0 +1,201 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hoohoo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Bonet Sugiarto
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-31 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.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
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: rspec
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
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-nc
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: guard
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: guard-rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry-remote
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: pry-nav
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: crimp
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - '>='
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description: This is description
154
+ email:
155
+ - bonetsu@gmail.com
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - .gitignore
161
+ - .travis.yml
162
+ - Gemfile
163
+ - Guardfile
164
+ - LICENSE.txt
165
+ - README.md
166
+ - Rakefile
167
+ - hoohoo.gemspec
168
+ - lib/hoohoo.rb
169
+ - lib/hoohoo/data_store.rb
170
+ - lib/hoohoo/version.rb
171
+ - spec/data_store_spec.rb
172
+ - spec/hoohoo_spec.rb
173
+ - spec/spec_helper.rb
174
+ homepage: ''
175
+ licenses:
176
+ - MIT
177
+ metadata: {}
178
+ post_install_message:
179
+ rdoc_options: []
180
+ require_paths:
181
+ - lib
182
+ required_ruby_version: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - '>='
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
187
+ required_rubygems_version: !ruby/object:Gem::Requirement
188
+ requirements:
189
+ - - '>='
190
+ - !ruby/object:Gem::Version
191
+ version: '0'
192
+ requirements: []
193
+ rubyforge_project:
194
+ rubygems_version: 2.2.2
195
+ signing_key:
196
+ specification_version: 4
197
+ summary: This is summary
198
+ test_files:
199
+ - spec/data_store_spec.rb
200
+ - spec/hoohoo_spec.rb
201
+ - spec/spec_helper.rb