process_flags 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 75cac056c4e045386d6a2a37f72f495128df461d
4
+ data.tar.gz: 6f64b1cbd3fc8e9897ada161017f0a61552da468
5
+ SHA512:
6
+ metadata.gz: 5466761b5cbe83d95545552c053c74d8c1b06fc07a20a26402fb93b250990ba2d5bd6a74e1da09792659b1f811915f71cefc1d82701299726aa112ca15892803
7
+ data.tar.gz: 994131ffc05667ed8477bee068ece3fff6c9b7402d6f0bea9705f12393a0d6c35638d2980b294ef347ee26a5c17a98bf1342dfd805f4196bc5f8a77f5da41951
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /.idea/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in process_flags.gemspec
4
+ gemspec
@@ -0,0 +1,50 @@
1
+ # ProcessFlags
2
+
3
+ Process flags are files in the log directory that can be used to change the functionality of the process without needing a restart.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'process_flags'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install process_flags
20
+
21
+ ## Usage
22
+
23
+ The following method checks for a process flag.
24
+ ```
25
+ ProcessFlags.is_set?(:disable_slave_database_access)
26
+ ```
27
+ The above will return true if the file "log/flag.disable_slave_database_access" exists.
28
+
29
+ You can also store values in a process flag. For example:
30
+ ```
31
+ ProcessFlags[:max_calls]
32
+ ```
33
+
34
+ This returns nil if the file does not exist, or it returns the content of the file.
35
+
36
+
37
+
38
+ ## Development
39
+
40
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
41
+
42
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
43
+
44
+ ## Contributing
45
+
46
+ 1. Fork it ( https://github.com/[my-github-username]/process_flags/fork )
47
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
48
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
49
+ 4. Push to the branch (`git push origin my-new-feature`)
50
+ 5. Create a new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "process_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
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,79 @@
1
+ require 'fileutils'
2
+
3
+ # Process flags are files in the log directory that can be used to change the functionality of the process without needing a restart.
4
+
5
+ class ProcessFlags
6
+ RECHECK_INTERVAL_SECONDS = 5
7
+
8
+ class << self
9
+ @@process_flags = {}
10
+
11
+ # Convenience method
12
+ def is_set?(flag_sym)
13
+ find_or_init(flag_sym).is_set?
14
+ end
15
+
16
+ def filename(flag_sym)
17
+ find_or_init(flag_sym).filename
18
+ end
19
+
20
+ def [](symbol)
21
+ find_or_init(symbol).value
22
+ end
23
+
24
+ def reset_cache!
25
+ @@process_flags = {}
26
+ end
27
+
28
+ private
29
+ def find_or_init(symbol)
30
+ @@process_flags[symbol] ||= new(symbol)
31
+ end
32
+ end
33
+
34
+ def initialize(symbol)
35
+ @symbol = symbol
36
+ @value = nil
37
+ @mtime = nil
38
+ @last_checked = nil
39
+ end
40
+
41
+ def is_set?
42
+ check
43
+ !@value.nil?
44
+ end
45
+
46
+ def value
47
+ check
48
+ if @value && @value != ""
49
+ @value
50
+ end
51
+ end
52
+
53
+ def filename
54
+ @filename ||= "#{Rails.root}/log/flag.#{@symbol}"
55
+ end
56
+
57
+ private
58
+ def check
59
+ if should_check?
60
+ @last_checked = Time.now
61
+ read_if_modified
62
+ end
63
+ end
64
+
65
+ def should_check?
66
+ @last_checked.nil? || Time.now > @last_checked + RECHECK_INTERVAL_SECONDS
67
+ end
68
+
69
+ def read_if_modified
70
+ stat = File.stat(filename)
71
+ if stat.mtime != @mtime
72
+ @mtime = stat.mtime
73
+ @value = File.read(filename)
74
+ end
75
+ rescue Errno::ENOENT
76
+ @value = nil
77
+ @mtime = nil
78
+ end
79
+ end
@@ -0,0 +1,3 @@
1
+ module ProcessFlags
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'process_flags/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "process_flags"
8
+ spec.version = ProcessFlags::VERSION
9
+ spec.authors = ["Bob Smith"]
10
+ spec.email = ["bob@invoca.com"]
11
+
12
+ spec.summary = %q{Control application behavior by setting files in filesystem.}
13
+ spec.description = %q{Control application behavior by setting files in filesystem.}
14
+ spec.homepage = "https://github.com/invoca/process_flags"
15
+
16
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
17
+ # delete this section to allow pushing this gem to any host.
18
+ # if spec.respond_to?(:metadata)
19
+ # spec.metadata['allowed_push_host'] = "http://invoca.net"
20
+ # else
21
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
+ # end
23
+
24
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_dependency 'rails', '~> 3.2.21'
30
+
31
+ spec.add_development_dependency "bundler", "~> 1.9"
32
+ spec.add_development_dependency "rake", "~> 10.0"
33
+ spec.add_development_dependency "rspec", "~> 3.2"
34
+ spec.add_development_dependency "pry"
35
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: process_flags
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Bob Smith
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-06-26 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: 3.2.21
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 3.2.21
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.9'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.2'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
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
+ description: Control application behavior by setting files in filesystem.
84
+ email:
85
+ - bob@invoca.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - Gemfile
92
+ - README.md
93
+ - Rakefile
94
+ - bin/console
95
+ - bin/setup
96
+ - lib/process_flags.rb
97
+ - lib/process_flags/version.rb
98
+ - process_flags.gemspec
99
+ homepage: https://github.com/invoca/process_flags
100
+ licenses: []
101
+ metadata: {}
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 2.2.2
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: Control application behavior by setting files in filesystem.
122
+ test_files: []