Skip to content

Commit

Permalink
Merge pull request #743 from jnunemaker/the-one-true-gem
Browse files Browse the repository at this point in the history
Merge flipper-cloud into flipper gem
  • Loading branch information
bkeepers authored Aug 1, 2023
2 parents e1af0da + 94cfbdd commit f25e1af
Show file tree
Hide file tree
Showing 27 changed files with 300 additions and 310 deletions.
8 changes: 7 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ All notable changes to this project will be documented in this file.

## Unreleased changes

* ui, api: Allow Rack 3 (https://github.com/jnunemaker/flipper/pull/670/files)
* ui, api: Allow Rack 3 (https://github.com/jnunemaker/flipper/pull/670)
* cloud: The `flipper-cloud` gem has been merged into the `flipper` and no longer needs to be added separately. Configure cloud by setting the `FLIPPER_CLOUD_TOKEN` environment variable. (https://github.com/jnunemaker/flipper/pull/743)
```diff
# Gemfile
gem 'flipper'
- gem 'flipper-cloud'
```

## 0.28.3

Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ gem 'stackprof'
gem 'benchmark-ips'
gem 'stackprof-webnav'
gem 'flamegraph'
gem 'climate_control'

group(:guard) do
gem 'guard', '~> 2.15'
Expand Down
4 changes: 2 additions & 2 deletions flipper-active_record.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ end

Gem::Specification.new do |gem|
gem.authors = ['John Nunemaker']
gem.email = ['[email protected]']
gem.email = '[email protected]'
gem.summary = 'ActiveRecord adapter for Flipper'
gem.license = 'MIT'
gem.homepage = 'https://github.com/jnunemaker/flipper'
gem.homepage = 'https://www.flippercloud.io/docs/adapters/active-record'

extra_files = [
'lib/generators/flipper/templates/migration.erb',
Expand Down
4 changes: 2 additions & 2 deletions flipper-active_support_cache_store.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ end

Gem::Specification.new do |gem|
gem.authors = ['John Nunemaker']
gem.email = ['[email protected]']
gem.email = '[email protected]'
gem.summary = 'ActiveSupport::Cache store adapter for Flipper'
gem.license = 'MIT'
gem.homepage = 'https://github.com/jnunemaker/flipper'
gem.homepage = 'https://www.flippercloud.io/docs/optimization#activesupportcachestore'

gem.files = `git ls-files`.split("\n").select(&flipper_active_support_cache_store_files) + ['lib/flipper/version.rb']
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n").select(&flipper_active_support_cache_store_files)
Expand Down
4 changes: 2 additions & 2 deletions flipper-api.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ end

Gem::Specification.new do |gem|
gem.authors = ['John Nunemaker']
gem.email = ['[email protected]']
gem.email = '[email protected]'
gem.summary = 'API for the Flipper gem'
gem.license = 'MIT'
gem.homepage = 'https://github.com/jnunemaker/flipper'
gem.homepage = 'https://www.flippercloud.io/docs/api'
gem.files = `git ls-files`.split("\n").select(&flipper_api_files) + ['lib/flipper/version.rb']
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n").select(&flipper_api_files)
gem.name = 'flipper-api'
Expand Down
17 changes: 4 additions & 13 deletions flipper-cloud.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,18 @@
require File.expand_path('../lib/flipper/version', __FILE__)
require File.expand_path('../lib/flipper/metadata', __FILE__)

flipper_cloud_files = lambda do |file|
file =~ /cloud/
end

Gem::Specification.new do |gem|
gem.authors = ['John Nunemaker']
gem.email = ['[email protected]']
gem.summary = 'FlipperCloud.io adapter for Flipper'
gem.email = '[email protected]'
gem.summary = '[DEPRECATED] This gem has been merged into the `flipper` gem'
gem.license = 'MIT'
gem.homepage = 'https://github.com/jnunemaker/flipper'
gem.homepage = 'https://www.flippercloud.io'

extra_files = [
'lib/flipper/version.rb',
]
gem.files = `git ls-files`.split("\n").select(&flipper_cloud_files) + extra_files
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n").select(&flipper_cloud_files)
gem.files = [ 'lib/flipper-cloud.rb', 'lib/flipper/version.rb' ]
gem.name = 'flipper-cloud'
gem.require_paths = ['lib']
gem.version = Flipper::VERSION
gem.metadata = Flipper::METADATA

gem.add_dependency 'flipper', "~> #{Flipper::VERSION}"
gem.add_dependency "brow", "~> 0.4.1"
end
4 changes: 2 additions & 2 deletions flipper-dalli.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ end

Gem::Specification.new do |gem|
gem.authors = ['John Nunemaker']
gem.email = ['[email protected]']
gem.email = '[email protected]'
gem.summary = 'Dalli adapter for Flipper'
gem.license = 'MIT'
gem.homepage = 'https://github.com/jnunemaker/flipper'
gem.homepage = 'https://www.flippercloud.io/docs/adapters'

gem.files = `git ls-files`.split("\n").select(&flipper_dalli_files) + ['lib/flipper/version.rb']
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n").select(&flipper_dalli_files)
Expand Down
4 changes: 2 additions & 2 deletions flipper-moneta.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ end

Gem::Specification.new do |gem|
gem.authors = ['John Nunemaker']
gem.email = ['[email protected]']
gem.email = '[email protected]'
gem.summary = 'Moneta adapter for Flipper'
gem.license = 'MIT'
gem.homepage = 'https://github.com/jnunemaker/flipper'
gem.homepage = 'https://www.flippercloud.io/docs/adapters/moneta'

gem.files = `git ls-files`.split("\n").select(&flipper_moneta_files) + ['lib/flipper/version.rb']
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n").select(&flipper_moneta_files)
Expand Down
4 changes: 2 additions & 2 deletions flipper-mongo.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ end

Gem::Specification.new do |gem|
gem.authors = ['John Nunemaker']
gem.email = ['[email protected]']
gem.email = '[email protected]'
gem.summary = 'Mongo adapter for Flipper'
gem.license = 'MIT'
gem.homepage = 'https://github.com/jnunemaker/flipper'
gem.homepage = 'https://www.flippercloud.io/docs/adapters/mongo'

gem.files = `git ls-files`.split("\n").select(&flipper_mongo_files) + ['lib/flipper/version.rb']
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n").select(&flipper_mongo_files)
Expand Down
4 changes: 2 additions & 2 deletions flipper-redis.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ end

Gem::Specification.new do |gem|
gem.authors = ['John Nunemaker']
gem.email = ['[email protected]']
gem.email = '[email protected]'
gem.summary = 'Redis adapter for Flipper'
gem.license = 'MIT'
gem.homepage = 'https://github.com/jnunemaker/flipper'
gem.homepage = 'https://www.flippercloud.io/docs/adapters/redis'

gem.files = `git ls-files`.split("\n").select(&flipper_redis_files) + ['lib/flipper/version.rb']
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n").select(&flipper_redis_files)
Expand Down
4 changes: 2 additions & 2 deletions flipper-rollout.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ end

Gem::Specification.new do |gem|
gem.authors = ['John Nunemaker']
gem.email = ['[email protected]']
gem.email = '[email protected]'
gem.summary = 'Rollout adapter for Flipper'
gem.license = 'MIT'
gem.homepage = 'https://github.com/jnunemaker/flipper'
gem.homepage = 'https://www.flippercloud.io/docs/adapters/rollout'

gem.files = `git ls-files`.split("\n").select(&flipper_rollout_files) + ['lib/flipper/version.rb']
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n").select(&flipper_rollout_files)
Expand Down
4 changes: 2 additions & 2 deletions flipper-sequel.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ flipper_sequel_files = ->(file) { file =~ /sequel/ }

Gem::Specification.new do |gem|
gem.authors = ['John Nunemaker']
gem.email = ['[email protected]']
gem.email = '[email protected]'
gem.summary = 'Sequel adapter for Flipper'
gem.license = 'MIT'
gem.homepage = 'https://github.com/jnunemaker/flipper'
gem.homepage = 'https://www.flippercloud.io/docs/adapters/sequel'

extra_files = [
'lib/flipper/version.rb',
Expand Down
4 changes: 2 additions & 2 deletions flipper-ui.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ end

Gem::Specification.new do |gem|
gem.authors = ['John Nunemaker']
gem.email = ['[email protected]']
gem.email = '[email protected]'
gem.summary = 'UI for the Flipper gem'
gem.license = 'MIT'
gem.homepage = 'https://github.com/jnunemaker/flipper'
gem.homepage = 'https://www.flippercloud.io/docs/ui'

gem.files = `git ls-files`.split("\n").select(&flipper_ui_files) + ['lib/flipper/version.rb']
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n").select(&flipper_ui_files)
Expand Down
5 changes: 3 additions & 2 deletions flipper.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ ignored_test_files.flatten!.uniq!

Gem::Specification.new do |gem|
gem.authors = ['John Nunemaker']
gem.email = ['[email protected]']
gem.email = '[email protected]'
gem.summary = 'Feature flipper for ANYTHING'
gem.homepage = 'https://github.com/jnunemaker/flipper'
gem.homepage = 'https://www.flippercloud.io/docs'
gem.license = 'MIT'

gem.files = `git ls-files`.split("\n") - ignored_files + ['lib/flipper/version.rb']
Expand All @@ -35,4 +35,5 @@ Gem::Specification.new do |gem|
gem.metadata = Flipper::METADATA

gem.add_dependency 'concurrent-ruby', '< 2'
gem.add_dependency 'brow', '~> 0.4.1'
end
2 changes: 1 addition & 1 deletion lib/flipper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,4 @@ def groups_registry=(registry)
require 'flipper/typecast'
require 'flipper/version'

require "flipper/railtie" if defined?(Rails::Railtie)
require "flipper/engine" if defined?(Rails)
10 changes: 3 additions & 7 deletions lib/flipper/cloud.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
require "flipper/cloud/configuration"
require "flipper/cloud/dsl"
require "flipper/cloud/middleware"
require "flipper/cloud/engine" if defined?(Rails::Engine)

module Flipper
module Cloud
Expand Down Expand Up @@ -40,13 +39,10 @@ def self.app(flipper = nil, options = {})

# Private: Configure Flipper to use Cloud by default
def self.set_default
Flipper.configure do |config|
config.default do
if ENV["FLIPPER_CLOUD_TOKEN"]
if ENV["FLIPPER_CLOUD_TOKEN"]
Flipper.configure do |config|
config.default do
self.new(local_adapter: config.adapter)
else
warn "Missing FLIPPER_CLOUD_TOKEN environment variable. Disabling Flipper::Cloud."
Flipper.new(config.adapter)
end
end
end
Expand Down
29 changes: 0 additions & 29 deletions lib/flipper/cloud/engine.rb

This file was deleted.

1 change: 1 addition & 0 deletions lib/flipper/cloud/routes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Default routes loaded by Flipper::Cloud::Engine
Rails.application.routes.draw do
if ENV["FLIPPER_CLOUD_TOKEN"] && ENV["FLIPPER_CLOUD_SYNC_SECRET"]
require 'flipper/cloud'
config = Rails.application.config.flipper

cloud_app = Flipper::Cloud.app(nil,
Expand Down
22 changes: 19 additions & 3 deletions lib/flipper/railtie.rb → lib/flipper/engine.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
module Flipper
class Railtie < Rails::Railtie
class Engine < Rails::Engine
paths["config/routes.rb"] = ["lib/flipper/cloud/routes.rb"]

config.before_configuration do
config.flipper = ActiveSupport::OrderedOptions.new.update(
env_key: ENV.fetch('FLIPPER_ENV_KEY', 'flipper'),
memoize: ENV.fetch('FLIPPER_MEMOIZE', 'true').casecmp('true').zero?,
preload: ENV.fetch('FLIPPER_PRELOAD', 'true').casecmp('true').zero?,
instrumenter: ENV.fetch('FLIPPER_INSTRUMENTER', 'ActiveSupport::Notifications').constantize,
log: ENV.fetch('FLIPPER_LOG', 'true').casecmp('true').zero?
log: ENV.fetch('FLIPPER_LOG', 'true').casecmp('true').zero?,
cloud_path: "_flipper"
)
end

Expand All @@ -17,9 +20,18 @@ class Railtie < Rails::Railtie
end

initializer "flipper.default", before: :load_config_initializers do |app|
require 'flipper/cloud' if cloud?

Flipper.configure do |config|
config.default do
Flipper.new(config.adapter, instrumenter: app.config.flipper.instrumenter)
if cloud?
Flipper::Cloud.new(
local_adapter: config.adapter,
instrumenter: app.config.flipper.instrumenter
)
else
Flipper.new(config.adapter, instrumenter: app.config.flipper.instrumenter)
end
end
end
end
Expand All @@ -43,5 +55,9 @@ class Railtie < Rails::Railtie
}
end
end

def cloud?
!!ENV["FLIPPER_CLOUD_TOKEN"]
end
end
end
6 changes: 5 additions & 1 deletion lib/flipper/metadata.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
module Flipper
METADATA = {
'changelog_uri' => 'https://github.com/jnunemaker/flipper/blob/main/Changelog.md',
"documentation_uri" => "https://www.flippercloud.io/docs",
"homepage_uri" => "https://www.flippercloud.io",
"source_code_uri" => "https://github.com/jnunemaker/flipper",
"bug_tracker_uri" => "https://github.com/jnunemaker/flipper/issues",
"changelog_uri" => "https://github.com/jnunemaker/flipper/blob/main/Changelog.md",
}.freeze
end
5 changes: 3 additions & 2 deletions spec/flipper/adapters/mongo_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@

load 'flipper/adapters/mongo.rb'

ENV["MONGO_URL"] ||= "mongodb://127.0.0.1:27017/testing"
expect(Flipper.adapter.adapter).to be_a(Flipper::Adapters::Mongo)
with_env "MONGO_URL" => ENV.fetch("MONGO_URL", "mongodb://127.0.0.1:27017/testing") do
expect(Flipper.adapter.adapter).to be_a(Flipper::Adapters::Mongo)
end
end
end
Loading

0 comments on commit f25e1af

Please sign in to comment.