dont_repeat_for 1.0.0.0

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: d6a2223e610c2c4a6359c0aee70254bb04960a4f
4
+ data.tar.gz: 652200549e9120537b7130961fe302b73b08d94e
5
+ SHA512:
6
+ metadata.gz: fe2dededa9102667c038ef3c6fa44aa49b0d3cacbd54ef9898f1a4171d002e10a620cfc5d3dcfa05aad89398a44d136556e4dbcacf0250b8eff3c9f120f93834
7
+ data.tar.gz: d1410275b765fb7e55780f194ec3554074c852ca5ae2801c95084ad130ed331157a9e0667e07a068c5d8fbbd80d84d31293294a6c9fe4d0590012b65f1280609
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /.idea
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+ .DS_Store
12
+ /*.gem
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - "2.1.0"
4
+ - "2.2.3"
5
+ script: 'bundle exec rake'
6
+ notifications:
7
+ email:
8
+ on_success: never
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at najibkaake@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in activemodel_flags.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Jay El-Kaake
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,81 @@
1
+ # Don't Repeat For Gem
2
+
3
+ Runs a block only once in the given time frame and lets you make sure it doesn't repeat more than the times you specify per time block.
4
+
5
+ Uses redis to know if we've run the block before.
6
+
7
+ ### Why?
8
+ Sometimes you don't want to flood your logs with repeated messages, or you want to make sure notifications are not send multiple times to your messaging groups.
9
+
10
+ **Table of Contents**
11
+ * [Installation](#installation)
12
+ * [Usage](#usage)
13
+ * [Other Things](#Other_Things)
14
+
15
+ # Installation
16
+ Add this line to your application's Gemfile:
17
+ ```ruby
18
+ gem 'dont_repeat_for'
19
+ ```
20
+ And then execute:
21
+ $ bundle
22
+ Or install it yourself as:
23
+ $ gem install dont_repeat_for
24
+
25
+ ### Requirements
26
+ Requires `redis` to be available and installed. That's what it will use for memory.
27
+
28
+
29
+ # Usage
30
+ ```ruby
31
+ ##
32
+ # @param time [Integer] The amount of seconds that we don't want to repeat the process for
33
+ # @param key [String] A unique key to identify the process that we don't want to repeat for the given time
34
+ def initialize(time, key)
35
+ ```
36
+
37
+ ### Example 1: Global Key
38
+
39
+ ```ruby
40
+ 20.times do
41
+ DontRepeatFor.new("Everyone/Test", 1.second) { puts "This message will only be displayed once every 1 second."; }
42
+ end
43
+ sleep(1.second)
44
+ DontRepeatFor.new("Everyone/Test", 1.second) { puts "This message will only be displayed once every 1 second."; }
45
+
46
+ # Output:
47
+ # This message will only be displayed once every 1 second.
48
+ # This message will only be displayed once every 1 second.
49
+ ```
50
+
51
+ ### Example 2: User Key
52
+
53
+ ```ruby
54
+ user1 = User.new(id: -1)
55
+ user2 = User.new(id: -2)
56
+ 20.times do
57
+ DontRepeatFor.new("User-#{user1.id}/Test", 1.second) { puts "This message will only be displayed once every 1 second for user #{user1.id}."; }
58
+ DontRepeatFor.new("User-#{user2.id}/Test", 1.second) { puts "This message will only be displayed once every 1 second for user #{user2.id}."; }
59
+ end
60
+ sleep(1.second)
61
+ DontRepeatFor.new("User-#{user1.id}/Test", 1.second) { puts "This message will only be displayed once every 1 second for user #{user1.id}."; }
62
+ DontRepeatFor.new("User-#{user2.id}/Test", 1.second) { puts "This message will only be displayed once every 1 second for user #{user2.id}."; }
63
+
64
+ # Output:
65
+ # This message will only be displayed once every 1 second for user -1.
66
+ # This message will only be displayed once every 1 second for user -2.
67
+ # This message will only be displayed once every 1 second for user -1.
68
+ # This message will only be displayed once every 1 second for user -2.
69
+ ```
70
+
71
+ # Other Things
72
+ ### Roadmap
73
+ * Make this system compatible with memory-baseds storage and other data storage systems.
74
+
75
+ ### Contributing
76
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jayelkaake/dont_repeat_for.
77
+ This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to
78
+ adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
79
+
80
+ ### License
81
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "activemodel_flags"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,39 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dont_repeat_for/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dont_repeat_for"
8
+ spec.version = DontRepeatFor::VERSION
9
+ spec.authors = ["Jay El-Kaake"]
10
+ spec.email = ["najibkaake@gmail.com"]
11
+
12
+ spec.summary = %q{Adds beautifully readable true/false flags to user and account active models (like devise).}
13
+ spec.description = %q{This gem adds the ability for models to have an unlimited number of custom flags \
14
+ that are stored within one database column cell instead of several columns.}
15
+ spec.homepage = "https://www.github.com/jayelkaake/dont_repeat_for"
16
+ spec.license = "MIT"
17
+
18
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
19
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
20
+ # if spec.respond_to?(:metadata)
21
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
22
+ # else
23
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
24
+ # end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ spec.add_development_dependency "rails", ">= 4.0.0"
32
+
33
+ spec.add_development_dependency "bundler"
34
+ spec.add_development_dependency "temping", "~> 3.3.0"
35
+ spec.add_development_dependency "rake", "~> 10.0"
36
+ spec.add_development_dependency "rspec", '~> 3.4'
37
+ spec.add_development_dependency "sqlite3", '~> 1.3.11'
38
+
39
+ end
@@ -0,0 +1,3 @@
1
+ class DontRepeatFor
2
+ VERSION = '1.0.0.0'
3
+ end
@@ -0,0 +1,56 @@
1
+ require "dont_repeat_for/version"
2
+
3
+ ##
4
+ # Runs a block only once in the given time frame
5
+ # Uses redis to know if we've run the block before.
6
+ # Example 1:
7
+ # ```ruby
8
+ # 20.times do
9
+ # DontRepeatFor.new("test_dont_repeat/test", 5.minutes) { puts "This message will only be displayed once every 5 minutes.";
10
+ # sleep(1.minute)
11
+ # end
12
+ # ```
13
+ #
14
+ # @hint: You can include an ID in the key to enforce rate limiting for a specific store.
15
+ class DontRepeatFor
16
+ attr_accessor :key, :time
17
+
18
+ ##
19
+ # @param time [Integer] The amount of seconds that we don't want to repeat the process for
20
+ # @param key [String] A unique key to identify the process that we don't want to repeat for the given time
21
+ def initialize(time, key)
22
+ @key = key
23
+ @time = time.to_i
24
+
25
+ return nil if ran_recently?
26
+
27
+ remember_not_to_repeat!
28
+
29
+ yield
30
+ end
31
+
32
+ private
33
+
34
+ def remember_not_to_repeat!
35
+ redis.set(storage_key, true, ex: time)
36
+ end
37
+
38
+ def ran_recently?
39
+ redis.get(storage_key)
40
+ end
41
+
42
+ def storage_key
43
+ @storage_key ||= "DontRepeatFor/Keys/#{@key}"
44
+ end
45
+
46
+ def redis
47
+ return $redis if defined?($redis)
48
+
49
+ self.class.redis
50
+ end
51
+
52
+ def self.redis
53
+ @redis ||= Redis.new
54
+ end
55
+ end
56
+
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dont_repeat_for
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jay El-Kaake
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-05-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 4.0.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 4.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
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: temping
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.3.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.3.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.4'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.4'
83
+ - !ruby/object:Gem::Dependency
84
+ name: sqlite3
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.3.11
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.3.11
97
+ description: |-
98
+ This gem adds the ability for models to have an unlimited number of custom flags \
99
+ that are stored within one database column cell instead of several columns.
100
+ email:
101
+ - najibkaake@gmail.com
102
+ executables: []
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - ".gitignore"
107
+ - ".travis.yml"
108
+ - CODE_OF_CONDUCT.md
109
+ - Gemfile
110
+ - LICENSE.txt
111
+ - README.md
112
+ - Rakefile
113
+ - bin/console
114
+ - bin/setup
115
+ - dont_repeat_for.gemspec
116
+ - lib/dont_repeat_for.rb
117
+ - lib/dont_repeat_for/version.rb
118
+ homepage: https://www.github.com/jayelkaake/dont_repeat_for
119
+ licenses:
120
+ - MIT
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.6.10
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: Adds beautifully readable true/false flags to user and account active models
142
+ (like devise).
143
+ test_files: []