Skip to content

Commit b43370f

Browse files
committedJul 22, 2020
Fixes and tweaks
- Fix project when running with rollout with logging disabled - Fix usage of `present?` which doesnt exist in plain Ruby - Add development rackup config and instructions on how to run this project
1 parent 1862373 commit b43370f

File tree

11 files changed

+77
-26
lines changed

11 files changed

+77
-26
lines changed
 

‎.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@
99

1010
# rspec failure tracking
1111
.rspec_status
12+
13+
Gemfile.lock

‎.ruby-version

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2.6.6

‎Gemfile

+2
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
44

55
# Specify your gem's dependencies in rollout-ui.gemspec
66
gemspec
7+
8+

‎README.md

+13
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,19 @@ end
8383

8484
Bug reports and pull requests are welcome on GitHub at https://github.com/fetlife/rollout-ui.
8585

86+
To run this project for development in isolation:
87+
88+
```sh
89+
bundle install
90+
bundle exec rerun rackup
91+
```
92+
93+
Alternatively you can also configure which Redis with:
94+
95+
```sh
96+
REDIS_HOST=localhost REDIS_PORT=6379 REDIS_DB=10 be rerun rackup
97+
```
98+
8699
## License
87100

88101
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).

‎config.ru

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Development Rackup config you can run with `bundle exec rerun rackup`
2+
3+
require_relative 'lib/rollout/ui'
4+
require 'redis'
5+
6+
redis_host = ENV.fetch('REDIS_HOST', 'localhost')
7+
redis_port = ENV.fetch('REDIS_PORT', '6379')
8+
redis_db = ENV.fetch('REDIS_DB', '10')
9+
10+
redis = Redis.new(host: redis_host, port: redis_port, db: redis_db)
11+
rollout = Rollout.new(redis, logging: { history_length: 100, global: true })
12+
13+
%i[employees developers subscribers].each do |group|
14+
rollout.define_group(group) { }
15+
end
16+
17+
Rollout::UI.configure do
18+
instance { rollout }
19+
actor { "JohnDoe" }
20+
actor_url { "https://www.youtube.com/watch?v=fbGkxcY7YFU" }
21+
end
22+
23+
run Rollout::UI::Web.new

‎lib/rollout/ui/config.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def get(key, *args, scope: nil)
3939
end
4040

4141
def defined?(key)
42-
@blocks.present? && @blocks.key?(key)
42+
!@blocks.nil? && @blocks.key?(key)
4343
end
4444
end
4545
end

‎lib/rollout/ui/helpers.rb

+12-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def stylesheet_path(name)
1010
end
1111

1212
def index_path
13-
request.script_name
13+
"#{request.script_name}/"
1414
end
1515

1616
def new_feature_path
@@ -32,7 +32,17 @@ def activate_percentage_feature_path(feature_name, percentage)
3232
def current_user
3333
@current_user ||= begin
3434
id = request.session["warden.user.user.key"].try(:[], 0).try(:[], 0)
35-
User.find_by(id: id) if id.present?
35+
User.find_by(id: id) unless id.nil?
36+
end
37+
end
38+
39+
def with_rollout_context(rollout, context)
40+
if rollout.respond_to?(:logging)
41+
rollout.logging.with_context(context) do
42+
yield
43+
end
44+
else
45+
yield
3646
end
3747
end
3848

‎lib/rollout/ui/views/features/partials/event_log.slim

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
- if event.name == "update"
2727
- if event.context && event.context[:actor]
2828
- if config.defined?(:actor_url)
29-
a.underline> href=config.get(:actor_url, event.context[:actor])
29+
a.underline> href=config.get(:actor_url, event.context[:actor]) target='_blank'
3030
= event.context[:actor]
3131
- else
3232
' #{event.context[:actor]}

‎lib/rollout/ui/views/features/show.slim

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
a.text-sm.text-blue-600(href=index_path class='hover:text-blue-700 hover:underline') ← back to overview
1+
a.text-sm.text-blue-600(href=index_path class='hover:text-blue-700 hover:underline')
2+
' ← back to overview
23

34
h2.font-semibold.text-xl.text-gray-500.pt-12
45
= @feature.name
@@ -20,7 +21,7 @@ form.p-6.bg-gray-100.max-w-lg.w-full.text-sm.rounded-sm action=feature_path(@fea
2021
| Groups
2122
span.ml-1.text-gray-400
2223
| (multi-select)
23-
select.block.appearance-none.w-full.bg-white.border.border-gray-300.px-4.py-3.rounded-sm.leading-relaxed(name="groups[]" id='groups' multiple=true size=$rollout.groups.count)
24+
select.block.appearance-none.w-full.bg-white.border.border-gray-300.px-4.py-3.rounded-sm.leading-relaxed(name="groups[]" id='groups' multiple=true size=(@rollout.groups.count + 1))
2425
option.py-1.px-1(value='' selected=(@feature.groups.count == 0))
2526
= '(none)'
2627
- @rollout.groups.each do |group|
@@ -38,9 +39,7 @@ form.p-6.bg-gray-100.max-w-lg.w-full.text-sm.rounded-sm action=feature_path(@fea
3839
value=@feature.percentage
3940
class='hover:border-gray-500'
4041
type='number'
41-
min='0'
42-
max='100'
43-
step='10'
42+
step='0.1'
4443
)
4544

4645
.mb-5

‎lib/rollout/ui/web.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class Web < Sinatra::Base
3838
rollout = config.get(:instance)
3939
actor = config.get(:actor, scope: self)
4040

41-
rollout.logging.with_context(actor: actor) do
41+
with_rollout_context(rollout, actor: actor) do
4242
rollout.with_feature(params[:feature_name]) do |feature|
4343
feature.percentage = params[:percentage].to_f.clamp(0.0, 100.0)
4444
feature.groups = (params[:groups] || []).reject(&:empty?).map(&:to_sym)
@@ -56,7 +56,7 @@ class Web < Sinatra::Base
5656
rollout = config.get(:instance)
5757
actor = config.get(:actor, scope: self)
5858

59-
rollout.logging.with_context(actor: actor) do
59+
with_rollout_context(rollout, actor: actor) do
6060
rollout.with_feature(params[:feature_name]) do |feature|
6161
feature.percentage = params[:percentage].to_f.clamp(0.0, 100.0)
6262
end

‎rollout-ui.gemspec

+16-15
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
1-
2-
lib = File.expand_path("../lib", __FILE__)
1+
lib = File.expand_path('../lib', __FILE__)
32
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4-
require "rollout/ui/version"
3+
require 'rollout/ui/version'
54

65
Gem::Specification.new do |spec|
7-
spec.name = "rollout-ui"
6+
spec.name = 'rollout-ui'
87
spec.version = Rollout::UI::VERSION
9-
spec.authors = ["FetLife"]
10-
spec.email = ["dev@fetlife.com"]
8+
spec.authors = ['FetLife']
9+
spec.email = ['dev@fetlife.com']
1110

1211
spec.summary = %q{}
1312
spec.description = %q{}
14-
spec.homepage = "https://github.com/fetlife/rollout-ui"
15-
spec.license = "MIT"
13+
spec.homepage = 'https://github.com/fetlife/rollout-ui'
14+
spec.license = 'MIT'
1615

1716
# Specify which files should be added to the gem when it is released.
1817
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
1918
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
2019
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
2120
end
22-
spec.bindir = "exe"
21+
spec.bindir = 'exe'
2322
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24-
spec.require_paths = ["lib"]
23+
spec.require_paths = ['lib']
2524

26-
spec.add_dependency "rollout", "~> 2.5"
27-
spec.add_dependency "sinatra", "~> 2.0"
25+
spec.add_dependency 'rollout', '~> 2.5'
26+
spec.add_dependency 'sinatra', '~> 2.0'
27+
spec.add_dependency 'slim', '~> 4.0'
2828

29-
spec.add_development_dependency "bundler", "~> 1.17"
30-
spec.add_development_dependency "rake", "~> 10.0"
31-
spec.add_development_dependency "rspec", "~> 3.0"
29+
spec.add_development_dependency 'bundler', '~> 1.17'
30+
spec.add_development_dependency 'rake', '~> 10.0'
31+
spec.add_development_dependency 'rspec', '~> 3.0'
32+
spec.add_development_dependency 'rerun', '~> 0.13'
3233
end

0 commit comments

Comments
 (0)
Please sign in to comment.