glass_slippers 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: f6bd2a06107ffbb2a783b894a0f94a0adde87c73
4
+ data.tar.gz: 9751e28ce8638e4c80b20b4a65700d22578be255
5
+ SHA512:
6
+ metadata.gz: eb88512eedfa0d29589884ff36f67b4cff24170af7d9f3a0a076b13e23e19f993f6a3f709f7fb3ba55f5c8796d0b2098da6376b65fd1192558e26de539265918
7
+ data.tar.gz: 49ea70a498f215165463cda4669203f47fa6111bfdb4182fdc7b33c141a1e88153000a8b26df37126ea85f916b05ed9d370c8800345ee0038447553ea2ac7f4a
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ service_name: travis-ci
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
+ language: 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
+ - naomi.freeman@yahoo.ca
14
+ on_failure: change
15
+ on_success: never
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in glass_slippers.gemspec
4
+ # Look here instead:
5
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,11 @@
1
+ guard 'rspec' do
2
+ # watch /lib/ files
3
+ watch(%r{^lib/(.+)\.rb$}) do |m| # match any files in lib directory
4
+ "spec/#{m[1]}_spec.rb"
5
+ end
6
+
7
+ # watch /spec/ files
8
+ watch(%r{^spec/(.+)\.rb$}) do |m| # match any files in spec directory
9
+ "spec/#{m[1]}.rb"
10
+ end
11
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Naomi
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,31 @@
1
+ [![Build Status](https://travis-ci.org/summerspirit/glass_slippers.png?branch=master)](https://travis-ci.org/summerspirit/glass_slippers) [![Gem Version](https://badge.fury.io/rb/glass_slippers.png)](http://badge.fury.io/rb/glass_slippers) [![Coverage Status](https://coveralls.io/repos/summerspirit/glass_slippers/badge.png)](https://coveralls.io/r/summerspirit/glass_slippers)
2
+
3
+ # Glass Slippers
4
+
5
+ This gem magically transforms things and then transforms them back at midnight.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'glass_slippers'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install glass_slippers
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/summerspirit/glass_slippers/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require 'rspec/core/rake_task'
2
+ require 'bundler/gem_tasks'
3
+
4
+
5
+ # Default directory to look in is '/specs'
6
+ # Run with 'rake spec'
7
+
8
+ RSpec::Core::RakeTask.new(:spec) do |task|
9
+ task.rspec_opts = ['--color', '--format', 'nested']
10
+ end
11
+
12
+ task :default => :spec
13
+
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'glass_slippers/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "glass_slippers"
8
+ spec.version = GlassSlippers::VERSION
9
+ spec.authors = ["Naomi"]
10
+ spec.email = ["naomi.freeman@yahoo.ca"]
11
+ spec.summary = %q{This gem magically transforms things and transforms them back at midnight.}
12
+ spec.description = %q{A further and completely not helpful 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
+
32
+ spec.add_development_dependency "coveralls"
33
+ end
@@ -0,0 +1,48 @@
1
+ require 'glass_slippers/version'
2
+ require 'glass_slippers/data_store'
3
+ require 'crimp'
4
+
5
+ module GlassSlippers
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
48
+
@@ -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 => transformed
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 GlassSlippers
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe DataStore do
4
+ let(:instance) { DataStore.instance }
5
+ let(:original) { 'cat' }
6
+ let(:transformed) { 'CAT' }
7
+
8
+ before(:each) do
9
+ instance.set({
10
+ :id => 'boo',
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('boo')[:original]).to eq(original)
19
+ expect(instance.get('boo')[:transformed]).to eq(transformed)
20
+ end
21
+ end
22
+
23
+ describe 'get(id)' do
24
+ it 'returns data object' do
25
+ expect(instance.get('boo')).to be_a Hash
26
+ expect(instance.get('boo').key?(:original)).to be true
27
+ expect(instance.get('boo').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('boo')
34
+ boo = instance.get('boo')
35
+ expect(boo[:original]).to eq(boo[:transformed])
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+
3
+ describe GlassSlippers 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 passed 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 transformed data' do
26
+ GlassSlippers.stub(:check)
27
+ create_new_instance
28
+ expect(subject.get(@id)).to eq({ :key => 'VALUE' })
29
+ end
30
+ end
31
+
32
+
33
+ context 'past midnight (after time expired)' do
34
+ it 'returns original data' do
35
+ create_new_instance
36
+ GlassSlippers.reset_data_at @id
37
+ expect(subject.get(@id)).to eq({ :key => 'value' })
38
+ end
39
+ end
40
+ end
41
+
42
+ describe '.midnight(id)' do
43
+ context 'before midnight (before time expired)' do
44
+ it 'restores the data to its original state' do
45
+ GlassSlippers.stub(:check)
46
+ create_new_instance
47
+ subject.midnight(@id)
48
+ expect(subject.get(@id)).to eq({ :key => 'value' })
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,5 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
4
+ require 'pry'
5
+ require 'glass_slippers'
metadata ADDED
@@ -0,0 +1,202 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: glass_slippers
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Naomi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-08 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: coveralls
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: A further and completely not helpful description.
154
+ email:
155
+ - naomi.freeman@yahoo.ca
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - ".coveralls.yml"
161
+ - ".gitignore"
162
+ - ".travis.yml"
163
+ - Gemfile
164
+ - Guardfile
165
+ - LICENSE.txt
166
+ - README.md
167
+ - Rakefile
168
+ - glass_slippers.gemspec
169
+ - lib/glass_slippers.rb
170
+ - lib/glass_slippers/data_store.rb
171
+ - lib/glass_slippers/version.rb
172
+ - spec/data_store_spec.rb
173
+ - spec/glass_slippers_spec.rb
174
+ - spec/spec_helper.rb
175
+ homepage: ''
176
+ licenses:
177
+ - MIT
178
+ metadata: {}
179
+ post_install_message:
180
+ rdoc_options: []
181
+ require_paths:
182
+ - lib
183
+ required_ruby_version: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ required_rubygems_version: !ruby/object:Gem::Requirement
189
+ requirements:
190
+ - - ">="
191
+ - !ruby/object:Gem::Version
192
+ version: '0'
193
+ requirements: []
194
+ rubyforge_project:
195
+ rubygems_version: 2.2.0.preview.1
196
+ signing_key:
197
+ specification_version: 4
198
+ summary: This gem magically transforms things and transforms them back at midnight.
199
+ test_files:
200
+ - spec/data_store_spec.rb
201
+ - spec/glass_slippers_spec.rb
202
+ - spec/spec_helper.rb