Skip to content

Commit

Permalink
Merge branch 'master' of http://github.com/mfdavid/rackstep
Browse files Browse the repository at this point in the history
  • Loading branch information
marciofrayze committed Apr 27, 2016
2 parents 3e4cf56 + dd276f6 commit da2f9aa
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 16 deletions.
47 changes: 42 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Main goals are:

[![Travis CI](https://api.travis-ci.org/mfdavid/rackstep.svg)](https://travis-ci.org/mfdavid/rackstep)
[![Code Climate](https://codeclimate.com/github/mfdavid/rackstep/badges/gpa.svg)](https://codeclimate.com/github/mfdavid/rackstep)
[![Coverage](https://codeclimate.com/github/mfdavid/rackstep/badges/coverage.svg)](https://codeclimate.com/github/mfdavid/rackstep)
[![Ich CI](http://inch-ci.org/github/mfdavid/rackstep.png)](http://inch-ci.org/github/mfdavid/rackstep)
[![Gem Version](https://badge.fury.io/rb/rackstep.svg)](https://badge.fury.io/rb/rackstep)
[![Downloads](http://ruby-gem-downloads-badge.herokuapp.com/rackstep?type=total&color=brightgreen)](https://rubygems.org/gems/rackstep)
Expand All @@ -22,11 +23,47 @@ Main goals are:
[![License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://github.com/mfdavid/rackstep/blob/master/LICENSE)
[![Gitter](https://img.shields.io/gitter/room/nwjs/nw.js.svg)](https://gitter.im/mfdavid/rackstep)

[![Twitter](https://img.shields.io/twitter/follow/rackstep.svg?style=social)](https://twitter.com/rackstep)

## A quick introduction to RackStep

[![A quick introduction to RackStep](http://img.youtube.com/vi/MFJut9t5ZLw/0.jpg)](https://www.youtube.com/watch?v=MFJut9t5ZLw "A quick introduction to RackStep.
")

Source code of the presentation:
[github.com/mfdavid/rackstep-presentations](http://github.com/mfdavid/rackstep-presentations)

## Example code

#### Let's create a simple service that returns the current date and time.
```ruby
# app.rb
require 'rackstep'
require 'json'

class App < RackStep::App
add_route('GET', 'time', 'TimeController')
end

class TimeController < RackStep::Controller
def process_request
time_hash = {:time => Time.now}
response.body = time_hash.to_json
end
end
```
```ruby
# config.ru
require_relative 'app.rb'

run App
```
The service will be available at */time* path and will return the current date and time in *json* format.

## Dependancies

RackStep is developed and tested with Ruby 2.3.0. The only hard dependency is
Rack gem itself, but there are a few others recommended gems:
Rack itself, but there are a few recommended gems:
- unicorn: fast rack-compatible server that can be used for production.
- simplecov: a simple way to generate statistics about your unit tests coverage.

Expand All @@ -40,14 +77,14 @@ Install the bundle gem if you don't have it already: gem install bundle
To create a new application, you may clone one of the following repositories as a starting point example:

A full app example:
https://github.com/mfdavid/rackstep-app-template
[github.com/mfdavid/rackstep-app-template](https://github.com/mfdavid/rackstep-app-template)

A minimum app example:
https://github.com/mfdavid/rackstep-minimum-app-template
[github.com/mfdavid/rackstep-minimum-app-template](https://github.com/mfdavid/rackstep-minimum-app-template)

Go into the directory you cloned the project and install the dependancies by running: bundle install

Start the application server using any rack-compatible server. For development I recommend using shotgun or rackup. For production, RackStep full app example is pre-configured to use unicorn.
Start the application server using any rack-compatible server. For development I recommend using shotgun or rackup. For production, RackStep full app template example is pre-configured to use unicorn.


## Running tests
Expand All @@ -60,7 +97,7 @@ Open coverage/index.html to see the results.

## In the wild (who is using it?)

RackStep is still in very early stage of development and testing. Right now there is only one website that was build using it: [Ninirc.com](http://ninirc.com)
RackStep still in very early stage of development and testing. Right now there is only one website that was built using it: [Ninirc.com](http://ninirc.com)


## Author
Expand Down
9 changes: 2 additions & 7 deletions lib/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ class RackStep::Controller
# The Rack::Response object that will be delivered to the user.
attr_accessor :response

# The 'global' app settings will be injected here. This hash variable is
# initialized only once (singleton) and may contain references to things
# that should be initialize only once during the app start (eg: database
# connection).
attr_accessor :settings

def initialize
@response = RackStep::Response.new
@response.body = ''
Expand Down Expand Up @@ -56,7 +50,7 @@ class RackStep::NotFoundController < RackStep::Controller
def process_request
@response.body = '404 - Page not found'
@response.content_type = 'text/plain'
@response.status = 404
@response.status = 404
end

end
Expand All @@ -79,6 +73,7 @@ def render_erb(template_name, erb_template_directory = 'app/public/pages')

end


# A module for controllers to add basic http authentication helper method.
module RackStep::Controller::BasicHttpAuthentication

Expand Down
6 changes: 3 additions & 3 deletions lib/rackstep.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ module RackStep
# This class MUST be extended by the user.
class App

# Will store the received request which will be injected into the user controllers.
# Stores the received request which will then be injected into the user controllers.
attr_reader :request

# Router is a singleton that will store all the registred routes.
# Access the Router, a singleton class that stores all the registred routes.
def router
Router.instance
end
Expand All @@ -29,7 +29,7 @@ def self.call(env)
new(env).process_request
end

# Initialize all instance variables and add a default "not found" route.
# Initialize the request instance variable and add a default "not found" route.
def initialize(env)
@request = Rack::Request.new(env)

Expand Down
2 changes: 1 addition & 1 deletion test/test_invalid_route.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class InvalidRoutesTest < RackStepTest
# Test if the invalid route is returning 404.
def test_invalid_route
# Requesting an invalid page.
request = @requester.get '/justAnInvalidPageRoute'
request = @requester.get '/justAnInvalidServiceRoute'
# The response should be NOT FOUND (404)
assert_equal 404, request.status
end
Expand Down

0 comments on commit da2f9aa

Please sign in to comment.