cookie_flag 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: 204f38b746d648087ae9cc7674d93accb8f78249
4
+ data.tar.gz: 967ef333d53e7665d255a4da196c3b1d020a8b1a
5
+ SHA512:
6
+ metadata.gz: 11bc366710c50c21397832c3f261b01fec1b71481aab75e322b3bcde227340e0e4b043a7d7cbe1795353536f9f834e9bf6018fa9f82513c256ada2593db05bde
7
+ data.tar.gz: 1302efc1606bdfe0a18fa3b2f98c99fba9d16cf41362a776258e0c2c7a2393e7d92e5a9719cadd5707cbe2ff455fc3716fb511412ba2778e2bc61760c88a0829
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.16.0
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in cookie_flag.gemspec
6
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Shota Iguchi
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.
@@ -0,0 +1,26 @@
1
+ # CookieFlag
2
+
3
+ Cookie based feature flags implementation for Rails.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'cookie_flag'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```shell
16
+ $ bundle
17
+ $ bundle exec rails generate cookie_flag:install
18
+ ```
19
+
20
+ ## Contributing
21
+
22
+ Bug reports and pull requests are welcome on GitHub at https://github.com/iguchi1124/cookie_flag.
23
+
24
+ ## License
25
+
26
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "cookie_flag"
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(__FILE__)
@@ -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,29 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "cookie_flag/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "cookie_flag"
7
+ spec.version = CookieFlag::VERSION
8
+ spec.author = "Shota Iguchi"
9
+ spec.email = "shota-iguchi@cookpad.com"
10
+
11
+ spec.summary = "Cookie based feature flags implementation for Rails."
12
+ spec.homepage = "https://github.com/iguchi1124/cookie_flag"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
+ f.match(%r{^(test|spec|features)/})
17
+ end
18
+
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "activesupport", ">= 4.2"
24
+ spec.add_development_dependency "railties", ">= 4.2"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.16"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rspec", "~> 3.0"
29
+ end
@@ -0,0 +1,15 @@
1
+ require 'cookie_flag/configuration'
2
+ require 'cookie_flag/railtie'
3
+ require "cookie_flag/version"
4
+
5
+ module CookieFlag
6
+ class << self
7
+ def config
8
+ @config ||= Configuration.new
9
+ end
10
+
11
+ def configure
12
+ yield config
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ module CookieFlag
2
+ class Configuration
3
+ attr_accessor :name
4
+
5
+ def initialize
6
+ @name = 'cookie_flag'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,33 @@
1
+ require 'cookie_flag/unavailable_error'
2
+
3
+ module CookieFlag
4
+ module Helper
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ helper_method :feature_available?
9
+ end
10
+
11
+ module ClassMethods
12
+ def feature(feature_name)
13
+ before_action -> {
14
+ unless feature_available?(feature_name)
15
+ raise UnavailableError
16
+ end
17
+ }
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def feature_available?(feature_name)
24
+ feature_flags[feature_name].present? &&
25
+ cookies.has_key?(feature_name) &&
26
+ cookies[feature_name] == feature_flags[feature_name]
27
+ end
28
+
29
+ def feature_flags
30
+ @feature_flags ||= Rails.application.config_for(CookieFlag.config.name).with_indifferent_access
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,13 @@
1
+ require 'cookie_flag/helper'
2
+
3
+ module CookieFlag
4
+ class Railtie < Rails::Railtie
5
+ config.action_dispatch.rescue_responses.merge!('CookieFlag::UnavailableError' => :not_found)
6
+
7
+ initializer 'cookie_flag' do
8
+ ActiveSupport.on_load(:action_controller) do
9
+ include CookieFlag::Helper if to_s != 'ActionController::API'
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,4 @@
1
+ module CookieFlag
2
+ class UnavailableError < StandardError
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module CookieFlag
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,11 @@
1
+ require 'rails'
2
+
3
+ module CookieFlag
4
+ class InstallGenerator < ::Rails::Generators::Base
5
+ source_root File.expand_path("../templates", __dir__)
6
+
7
+ def install
8
+ copy_file "cookie_flag.yml", "config/cookie_flag.yml"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ default: &default
2
+
3
+ development:
4
+ <<: *default
5
+
6
+ test:
7
+ <<: *default
8
+
9
+ production:
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cookie_flag
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Shota Iguchi
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-01-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.2'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: railties
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '4.2'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '4.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
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.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description:
84
+ email: shota-iguchi@cookpad.com
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - ".gitignore"
90
+ - ".rspec"
91
+ - ".travis.yml"
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - bin/console
97
+ - bin/setup
98
+ - cookie_flag.gemspec
99
+ - lib/cookie_flag.rb
100
+ - lib/cookie_flag/configuration.rb
101
+ - lib/cookie_flag/helper.rb
102
+ - lib/cookie_flag/railtie.rb
103
+ - lib/cookie_flag/unavailable_error.rb
104
+ - lib/cookie_flag/version.rb
105
+ - lib/generators/cookie_flag/install_generator.rb
106
+ - lib/generators/templates/cookie_flag.yml
107
+ homepage: https://github.com/iguchi1124/cookie_flag
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.6.11
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: Cookie based feature flags implementation for Rails.
131
+ test_files: []