Skip to content

Commit 90ec664

Browse files
byRehamMatthew Elwell
andauthored
Example app (#10)
* Release 3.0 Rewrite due to new logic, add Config, Flag and Flags::Collection, Errors objects, implement part of the flags engine when enable_local_evaluation is set to false * Set up gitflow actions, update tests * Implement Flags Engine * Set up rspec, add end to end tests, fixes * Fix checkout with submodules * Use Flagsmith as the namespace, add Flagsmith::Client to instantiate the SDK. * Make all hashes from parsed JSON with symbol keys * Fix issue with support changes of hash arguments for ruby later 3.0 https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/ * Engine::Core test coverage * Use segment priority * Test coverage of SDK * Bump version to 3.0.0 * Small fixes after testing * Make #get_identity_feature_states_dict private, fix FeatureSegment priority * Rename Features::State to FeatureState * Add Github action to publish gem * init example * Update README.md * Remove unused code Co-authored-by: Matthew Elwell <[email protected]>
1 parent 3a1ebce commit 90ec664

File tree

36 files changed

+798
-0
lines changed

36 files changed

+798
-0
lines changed

.rubocop.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ AllCops:
88
SuggestExtensions: false
99
Exclude:
1010
- 'spec/**/*'
11+
- 'example/**/*'

example/.env.development

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Define ENV variables for development environment
2+
DATABASE_URL="sqlite://db/example_development.sqlite"
3+
SERVE_STATIC_ASSETS="true"
4+
WEB_SESSIONS_SECRET="4743628fa58981a0eaf99cc636146f49ceffd0ab6a8423c0e2493e67cd825f67"
5+
FLAGSMITH_ENVIRONMENT_KEY="YOUR_FLAGSMITH_ENVIRONMENT_KEY"

example/.env.test

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Define ENV variables for test environment
2+
DATABASE_URL="sqlite://db/example_test.sqlite"
3+
SERVE_STATIC_ASSETS="true"
4+
WEB_SESSIONS_SECRET="50f1a22a68ccc6d06b48387f4cd4aa63cbaabd2b525c288f0f7a7046b10cc6ac"

example/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/db/*.sqlite
2+
/public/assets*
3+
/tmp
4+
.env.local
5+
.env.*.local

example/.hanamirc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
project=example
2+
test=rspec
3+
template=slim

example/.rspec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--color
2+
--require spec_helper

example/Gemfile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
source 'https://rubygems.org'
2+
3+
gem 'hanami', '~> 1.3'
4+
gem 'hanami-model', '~> 1.3'
5+
gem 'slim'
6+
gem 'sqlite3'
7+
gem "puma", "~> 5.6"
8+
9+
gemspec path: '../'
10+
11+
group :development do
12+
# Code reloading
13+
# See: https://guides.hanamirb.org/projects/code-reloading
14+
gem 'hanami-webconsole'
15+
gem 'shotgun', platforms: :ruby
16+
end
17+
18+
group :test, :development do
19+
gem 'dotenv', '~> 2.4'
20+
end
21+
22+
group :test do
23+
gem 'capybara'
24+
gem 'rspec'
25+
end

example/Gemfile.lock

Lines changed: 269 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,269 @@
1+
PATH
2+
remote: ..
3+
specs:
4+
flagsmith (3.0.0)
5+
faraday
6+
faraday-retry
7+
faraday_middleware
8+
semantic
9+
10+
GEM
11+
remote: https://rubygems.org/
12+
specs:
13+
addressable (2.8.0)
14+
public_suffix (>= 2.0.2, < 5.0)
15+
ast (2.4.2)
16+
better_errors (2.9.1)
17+
coderay (>= 1.0.0)
18+
erubi (>= 1.0.0)
19+
rack (>= 0.9.0)
20+
bigdecimal (1.4.4)
21+
binding_of_caller (0.8.0)
22+
debug_inspector (>= 0.0.1)
23+
capybara (3.32.2)
24+
addressable
25+
mini_mime (>= 0.1.3)
26+
nokogiri (~> 1.8)
27+
rack (>= 1.6.0)
28+
rack-test (>= 0.6.3)
29+
regexp_parser (~> 1.5)
30+
xpath (~> 3.2)
31+
coderay (1.1.3)
32+
concurrent-ruby (1.1.10)
33+
debug_inspector (1.1.0)
34+
diff-lcs (1.5.0)
35+
dotenv (2.7.6)
36+
dry-cli (0.7.0)
37+
dry-configurable (0.11.6)
38+
concurrent-ruby (~> 1.0)
39+
dry-core (~> 0.4, >= 0.4.7)
40+
dry-equalizer (~> 0.2)
41+
dry-container (0.7.2)
42+
concurrent-ruby (~> 1.0)
43+
dry-configurable (~> 0.1, >= 0.1.3)
44+
dry-core (0.4.9)
45+
concurrent-ruby (~> 1.0)
46+
dry-equalizer (0.3.0)
47+
dry-initializer (1.4.1)
48+
dry-logic (0.4.2)
49+
dry-container (~> 0.2, >= 0.2.6)
50+
dry-core (~> 0.2)
51+
dry-equalizer (~> 0.2)
52+
dry-struct (0.3.1)
53+
dry-configurable (~> 0.1)
54+
dry-core (~> 0.3)
55+
dry-equalizer (~> 0.2)
56+
dry-types (~> 0.9, >= 0.9.0)
57+
ice_nine (~> 0.11)
58+
dry-types (0.11.1)
59+
concurrent-ruby (~> 1.0)
60+
dry-configurable (~> 0.1)
61+
dry-container (~> 0.3)
62+
dry-core (~> 0.2, >= 0.2.1)
63+
dry-equalizer (~> 0.2)
64+
dry-logic (~> 0.4, >= 0.4.0)
65+
inflecto (~> 0.0.0, >= 0.0.2)
66+
dry-validation (0.11.0)
67+
concurrent-ruby (~> 1.0)
68+
dry-configurable (~> 0.1, >= 0.1.3)
69+
dry-core (~> 0.2, >= 0.2.1)
70+
dry-equalizer (~> 0.2)
71+
dry-logic (~> 0.4, >= 0.4.0)
72+
dry-types (~> 0.11.0)
73+
erubi (1.10.0)
74+
faraday (1.10.0)
75+
faraday-em_http (~> 1.0)
76+
faraday-em_synchrony (~> 1.0)
77+
faraday-excon (~> 1.1)
78+
faraday-httpclient (~> 1.0)
79+
faraday-multipart (~> 1.0)
80+
faraday-net_http (~> 1.0)
81+
faraday-net_http_persistent (~> 1.0)
82+
faraday-patron (~> 1.0)
83+
faraday-rack (~> 1.0)
84+
faraday-retry (~> 1.0)
85+
ruby2_keywords (>= 0.0.4)
86+
faraday-em_http (1.0.0)
87+
faraday-em_synchrony (1.0.0)
88+
faraday-excon (1.1.0)
89+
faraday-httpclient (1.0.1)
90+
faraday-multipart (1.0.3)
91+
multipart-post (>= 1.2, < 3)
92+
faraday-net_http (1.0.1)
93+
faraday-net_http_persistent (1.2.0)
94+
faraday-patron (1.0.0)
95+
faraday-rack (1.0.0)
96+
faraday-retry (1.0.3)
97+
faraday_middleware (1.2.0)
98+
faraday (~> 1.0)
99+
gem-release (2.2.2)
100+
hanami (1.3.5)
101+
bundler (>= 1.6, < 3)
102+
concurrent-ruby (~> 1.0)
103+
dry-cli (~> 0.5)
104+
hanami-assets (~> 1.3)
105+
hanami-controller (~> 1.3, >= 1.3.3)
106+
hanami-helpers (~> 1.3)
107+
hanami-mailer (~> 1.3)
108+
hanami-router (~> 1.3)
109+
hanami-utils (~> 1.3)
110+
hanami-validations (>= 1.3, < 3)
111+
hanami-view (~> 1.3)
112+
hanami-assets (1.3.5)
113+
hanami-helpers (~> 1.3)
114+
hanami-utils (~> 1.3)
115+
tilt (~> 2.0, >= 2.0.2)
116+
hanami-controller (1.3.3)
117+
hanami-utils (~> 1.3)
118+
rack (~> 2.0)
119+
hanami-helpers (1.3.3)
120+
hanami-utils (~> 1.3)
121+
hanami-mailer (1.3.3)
122+
hanami-utils (~> 1.3)
123+
mail (~> 2.6)
124+
tilt (~> 2.0, >= 2.0.1)
125+
hanami-model (1.3.3)
126+
bigdecimal (~> 1.4)
127+
concurrent-ruby (~> 1.0)
128+
dry-logic (~> 0.4.2, < 0.5)
129+
dry-types (~> 0.11.0)
130+
hanami-utils (~> 1.3)
131+
rom (~> 3.3, >= 3.3.3)
132+
rom-repository (~> 1.4)
133+
rom-sql (~> 1.3, >= 1.3.5)
134+
hanami-router (1.3.2)
135+
hanami-utils (~> 1.3)
136+
http_router (= 0.11.2)
137+
rack (~> 2.0)
138+
hanami-utils (1.3.8)
139+
concurrent-ruby (~> 1.0)
140+
transproc (~> 1.0)
141+
hanami-validations (1.3.8)
142+
dry-configurable (<= 0.12)
143+
dry-logic (~> 0.4.2, < 0.5)
144+
dry-validation (~> 0.11, < 0.12)
145+
hanami-utils (~> 1.3)
146+
hanami-view (1.3.3)
147+
hanami-utils (~> 1.3)
148+
tilt (~> 2.0, >= 2.0.1)
149+
hanami-webconsole (0.1.0)
150+
better_errors (~> 2.4)
151+
binding_of_caller (~> 0.8)
152+
http_router (0.11.2)
153+
rack (>= 1.0.0)
154+
url_mount (~> 0.2.1)
155+
ice_nine (0.11.2)
156+
inflecto (0.0.2)
157+
mail (2.7.1)
158+
mini_mime (>= 0.1.1)
159+
method_source (1.0.0)
160+
mini_mime (1.1.2)
161+
mini_portile2 (2.4.0)
162+
multipart-post (2.1.1)
163+
nio4r (2.5.8)
164+
nokogiri (1.10.10)
165+
mini_portile2 (~> 2.4.0)
166+
parallel (1.20.1)
167+
parser (3.1.2.0)
168+
ast (~> 2.4.1)
169+
pry (0.14.1)
170+
coderay (~> 1.1)
171+
method_source (~> 1.0)
172+
public_suffix (4.0.7)
173+
puma (5.6.4)
174+
nio4r (~> 2.0)
175+
rack (2.2.3)
176+
rack-test (1.1.0)
177+
rack (>= 1.0, < 3)
178+
rainbow (3.1.1)
179+
rake (13.0.6)
180+
regexp_parser (1.8.2)
181+
rexml (3.2.5)
182+
rom (3.3.3)
183+
concurrent-ruby (~> 1.0)
184+
dry-core (~> 0.3)
185+
dry-equalizer (~> 0.2)
186+
dry-initializer (~> 1.3)
187+
dry-types (~> 0.9, >= 0.9.4)
188+
rom-mapper (~> 0.5, >= 0.5.1)
189+
rom-mapper (0.5.1)
190+
dry-core (~> 0.2, >= 0.2.3)
191+
dry-equalizer (~> 0.2)
192+
transproc (~> 1.0)
193+
rom-repository (1.4.0)
194+
dry-core (~> 0.3, >= 0.3.1)
195+
dry-struct (~> 0.3)
196+
rom (~> 3.3)
197+
rom-mapper (~> 0.5)
198+
rom-sql (1.3.5)
199+
dry-core (~> 0.3)
200+
dry-equalizer (~> 0.2)
201+
dry-types (~> 0.11.0)
202+
rom (~> 3.2, >= 3.2.2)
203+
sequel (~> 4.43)
204+
rspec (3.11.0)
205+
rspec-core (~> 3.11.0)
206+
rspec-expectations (~> 3.11.0)
207+
rspec-mocks (~> 3.11.0)
208+
rspec-core (3.11.0)
209+
rspec-support (~> 3.11.0)
210+
rspec-expectations (3.11.0)
211+
diff-lcs (>= 1.2.0, < 2.0)
212+
rspec-support (~> 3.11.0)
213+
rspec-mocks (3.11.1)
214+
diff-lcs (>= 1.2.0, < 2.0)
215+
rspec-support (~> 3.11.0)
216+
rspec-support (3.11.0)
217+
rubocop (1.12.1)
218+
parallel (~> 1.10)
219+
parser (>= 3.0.0.0)
220+
rainbow (>= 2.2.2, < 4.0)
221+
regexp_parser (>= 1.8, < 3.0)
222+
rexml
223+
rubocop-ast (>= 1.2.0, < 2.0)
224+
ruby-progressbar (~> 1.7)
225+
unicode-display_width (>= 1.4.0, < 3.0)
226+
rubocop-ast (1.4.1)
227+
parser (>= 2.7.1.5)
228+
ruby-progressbar (1.11.0)
229+
ruby2_keywords (0.0.5)
230+
semantic (1.6.1)
231+
sequel (4.49.0)
232+
shotgun (0.9.2)
233+
rack (>= 1.0)
234+
slim (4.1.0)
235+
temple (>= 0.7.6, < 0.9)
236+
tilt (>= 2.0.6, < 2.1)
237+
sqlite3 (1.4.2)
238+
temple (0.8.2)
239+
tilt (2.0.10)
240+
transproc (1.1.1)
241+
unicode-display_width (2.1.0)
242+
url_mount (0.2.1)
243+
rack
244+
xpath (3.2.0)
245+
nokogiri (~> 1.8)
246+
247+
PLATFORMS
248+
x86_64-linux
249+
250+
DEPENDENCIES
251+
bundler
252+
capybara
253+
dotenv (~> 2.4)
254+
flagsmith!
255+
gem-release
256+
hanami (~> 1.3)
257+
hanami-model (~> 1.3)
258+
hanami-webconsole
259+
pry
260+
puma (~> 5.6)
261+
rake
262+
rspec
263+
rubocop
264+
shotgun
265+
slim
266+
sqlite3
267+
268+
BUNDLED WITH
269+
2.3.14

example/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Flagsmith Basic Ruby Example
2+
3+
This directory contains a basic Flask application which utilises Flagsmith. To run the example application, you'll
4+
need to go through the following steps:
5+
6+
1. Create an account, organisation and project on [Flagsmith](https://flagsmith.com)
7+
2. Create a feature in the project called "secret_button"
8+
3. Give the feature a value using the json editor as follows:
9+
10+
```json
11+
{"colour": "#ababab"}
12+
```
13+
14+
4. Create a .env.local file from the template located in this directory with the environment key of one of the environments
15+
in flagsmith (This can be found on the 'settings' page accessed from the menu on the left under the chosen environment.)
16+
5. From a terminal window, export those environment variables (either manually or by using `export $(cat .env)`)
17+
6. Install dependencies:
18+
```bash
19+
bundle install
20+
```
21+
7. Run the application:
22+
```
23+
bundle exec hanami server
24+
```
25+
8. Browse to http://localhost:2300
26+
27+
Now you can play around with the 'secret_button' feature in flagsmith, turn it on to show it and edit the colour in the
28+
json value to edit the colour of the button. You can also identify as a given user and then update the settings for the
29+
secret button feature for that user in the flagsmith interface to see the affect that has too.

example/Rakefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require 'rake'
2+
require 'hanami/rake_tasks'
3+
4+
begin
5+
require 'rspec/core/rake_task'
6+
RSpec::Core::RakeTask.new(:spec)
7+
task default: :spec
8+
rescue LoadError
9+
end

0 commit comments

Comments
 (0)