Skip to content

Commit 130afe0

Browse files
committed
install Featurevisor
1 parent 84da486 commit 130afe0

File tree

4 files changed

+81
-153
lines changed

4 files changed

+81
-153
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ ruby '>= 2.7.0'
44

55
# Add your gems here
66
gem 'rake', '~> 13.0'
7+
gem 'featurevisor', '~> 0.1.1'
78

89
group :development do
910
gem 'rubocop', '~> 1.50'

Gemfile.lock

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
ast (2.4.3)
5+
featurevisor (0.1.1)
6+
json (2.13.2)
7+
language_server-protocol (3.17.0.5)
8+
lint_roller (1.1.0)
9+
parallel (1.27.0)
10+
parser (3.3.9.0)
11+
ast (~> 2.4.1)
12+
racc
13+
prism (1.4.0)
14+
racc (1.8.1)
15+
rainbow (3.1.1)
16+
rake (13.3.0)
17+
regexp_parser (2.11.2)
18+
rubocop (1.80.0)
19+
json (~> 2.3)
20+
language_server-protocol (~> 3.17.0.2)
21+
lint_roller (~> 1.1.0)
22+
parallel (~> 1.10)
23+
parser (>= 3.3.0.2)
24+
rainbow (>= 2.2.2, < 4.0)
25+
regexp_parser (>= 2.9.3, < 3.0)
26+
rubocop-ast (>= 1.46.0, < 2.0)
27+
ruby-progressbar (~> 1.7)
28+
unicode-display_width (>= 2.4.0, < 4.0)
29+
rubocop-ast (1.46.0)
30+
parser (>= 3.3.7.2)
31+
prism (~> 1.4)
32+
ruby-progressbar (1.13.0)
33+
unicode-display_width (3.1.5)
34+
unicode-emoji (~> 4.0, >= 4.0.4)
35+
unicode-emoji (4.0.4)
36+
37+
PLATFORMS
38+
arm64-darwin-24
39+
ruby
40+
41+
DEPENDENCIES
42+
featurevisor (~> 0.1.1)
43+
rake (~> 13.0)
44+
rubocop (~> 1.50)
45+
46+
RUBY VERSION
47+
ruby 3.4.5p51
48+
49+
BUNDLED WITH
50+
2.6.9

README.md

Lines changed: 9 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -1,168 +1,25 @@
1-
# Ruby Hello World Web Server
1+
# featurevisor-example-ruby
22

3-
A simple Ruby web server that demonstrates basic HTTP server concepts with a Hello World response.
4-
5-
## Features
6-
7-
- Lightweight HTTP server built with pure Ruby
8-
- Responds with "Hello World" on the root endpoint
9-
- Request logging and error handling
10-
- Graceful shutdown with Ctrl+C
11-
12-
## Prerequisites
13-
14-
- Ruby 2.7.0 or higher
15-
- Bundler (for managing dependencies)
3+
Example Ruby web server that demonstrates how to use Featurevisor SDK.
164

175
## Installation
186

19-
1. **Clone or download this repository**
20-
```bash
21-
git clone <repository-url>
22-
cd featurevisor-example-ruby
23-
```
24-
25-
2. **Install dependencies**
26-
```bash
27-
bundle install
28-
```
29-
30-
Or use the rake task:
31-
```bash
32-
rake install
33-
```
34-
35-
## Running the Web Server
36-
37-
### Method 1: Using Rake (recommended)
38-
```bash
39-
rake run
40-
```
41-
42-
### Method 2: Direct Ruby execution
43-
```bash
44-
ruby app.rb
45-
```
46-
47-
### Method 3: Start in background
48-
```bash
49-
rake start
50-
```
51-
52-
### Method 4: Make the file executable and run
53-
```bash
54-
chmod +x app.rb
55-
./app.rb
56-
```
57-
58-
## Accessing the Server
59-
60-
Once the server is running, you can access it at:
61-
62-
- **Main endpoint**: http://localhost:3000
63-
64-
## API Endpoints
65-
66-
### GET /
67-
Returns a simple "Hello World" text response.
68-
69-
**Response:**
70-
```
71-
HTTP/1.1 200 OK
72-
Content-Type: text/plain
73-
Content-Length: 11
74-
75-
Hello World
76-
```
77-
78-
## Stopping the Server
79-
80-
- **If running in foreground**: Press `Ctrl+C`
81-
- **If running in background**: Use `rake stop`
82-
83-
## Available Rake Tasks
84-
85-
- `rake run` - Start the web server in foreground
86-
- `rake start` - Start the web server in background
87-
- `rake stop` - Stop the background web server
88-
- `rake check_port` - Check if port 3000 is available
89-
- `rake install` - Install gem dependencies
90-
- `rake lint` - Run RuboCop for code style checking
91-
- `rake clean` - Clean temporary files
92-
93-
## Project Structure
7+
Clone the repository, and run:
948

959
```
96-
featurevisor-example-ruby/
97-
├── app.rb # Main web server application
98-
├── Gemfile # Ruby dependencies
99-
├── Rakefile # Build tasks
100-
├── .gitignore # Git ignore patterns
101-
├── .editorconfig # Editor configuration
102-
├── .ruby-version # Ruby version specification
103-
├── .rubocop.yml # RuboCop configuration
104-
└── README.md # This file
10+
$ bundle install
10511
```
10612

107-
## Development
108-
109-
### Code Style
110-
This project uses RuboCop for code style enforcement. Run it with:
111-
```bash
112-
bundle exec rubocop
113-
```
13+
## Usage
11414

115-
### Port Configuration
116-
The server runs on port 3000 by default. You can change this by modifying the port number in `app.rb` or by creating a new instance with a different port.
15+
Run the server locally, running:
11716

118-
## Troubleshooting
119-
120-
### Port already in use
121-
If you get an "Address already in use" error, check if port 3000 is available:
122-
```bash
123-
rake check_port
12417
```
125-
126-
### Ruby not found
127-
If you get a "ruby: command not found" error, make sure Ruby is installed and in your PATH.
128-
129-
### Bundler not found
130-
Install Bundler with:
131-
```bash
132-
gem install bundler
133-
```
134-
135-
### Permission denied
136-
If you get a permission error when running `./app.rb`, make sure the file is executable:
137-
```bash
138-
chmod +x app.rb
139-
```
140-
141-
## Example Usage
142-
143-
### Starting the server:
144-
```bash
14518
$ rake run
146-
Starting Ruby Hello World Web Server...
147-
Starting Hello World Web Server on port 3000...
148-
Visit http://localhost:3000 in your browser
149-
Press Ctrl+C to stop the server
150-
151-
2024-01-15 10:30:00 - GET /
152-
2024-01-15 10:30:05 - GET /
15319
```
15420

155-
### Testing with curl:
156-
```bash
157-
# Test main endpoint
158-
curl http://localhost:3000/
159-
# Output: Hello World
160-
```
161-
162-
## Contributing
163-
164-
Feel free to modify this basic template to suit your needs. This is a starting point for learning Ruby web development or building more complex web applications.
21+
Open your browser and navigate to `http://localhost:3000`.
16522

166-
## License
23+
## Featurevisor project
16724

168-
This project is open source and available under the [MIT License](LICENSE).
25+
Uses this Featurevisor project to fetch the configuration from: https://github.com/featurevisor/featurevisor-example-cloudflare

app.rb

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,28 @@
44
# This is a basic example to get you started with Ruby web development
55

66
require 'socket'
7+
require 'featurevisor'
8+
require 'net/http'
9+
require 'json'
710

811
class HelloWorldServer
912
def initialize(port = 3000)
1013
@port = port
1114
@server = nil
15+
16+
##
17+
# Initialize Featurevisor
18+
#
19+
datafile_url = "https://featurevisor-example-cloudflare.pages.dev/production/featurevisor-tag-all.json"
20+
21+
# Fetch the datafile
22+
response = Net::HTTP.get(URI(datafile_url))
23+
datafile_content = JSON.parse(response)
24+
25+
# Create Featurevisor instance
26+
@featurevisor = Featurevisor.create_instance(
27+
datafile: datafile_content,
28+
)
1229
end
1330

1431
def start
@@ -59,7 +76,10 @@ def handle_request(client)
5976

6077
def generate_response(method, path)
6178
if path == '/' && method == 'GET'
62-
body = "Hello World"
79+
# Get the feature flag value
80+
feature_flag_value = @featurevisor.is_enabled("my_feature")
81+
82+
body = "Hello World. Feature flag value is: #{feature_flag_value}"
6383
status = '200 OK'
6484
content_type = "text/plain"
6585
else

0 commit comments

Comments
 (0)