Skip to content
This repository has been archived by the owner on Jan 2, 2018. It is now read-only.

Commit

Permalink
added a service generator (thanks @drnic) and bumped the gem version
Browse files Browse the repository at this point in the history
  • Loading branch information
mattetti committed Jun 14, 2012
1 parent 53e5954 commit aece611
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,9 @@
# Weasel Diesel Sinatra Changelog

## 0.3.0

* Added a service generator using thor. `$ thor :service get /foo/bar foo_bar.rb` (Thanks DrNic)

## 0.2.6

* Added a few basic disabled settings for newrelic and airbrake.
Expand Down
11 changes: 10 additions & 1 deletion README.md
Expand Up @@ -42,6 +42,16 @@ While it's a nice feature to have, a lot of developers like to do that
differently and it seems more sensitive to let them pick the way they
like the most.


### Generating a new service

You need to have thor installed for that, you might want to add it yo
your gemfile.

$ thor :service get /foo/bar foo_bar.rb

This command will create a service and a failing test for it.

### Console

$ bundle exec bin/console
Expand Down Expand Up @@ -130,7 +140,6 @@ properly composed:
TestApi.post '/people/:id', :id => 123
```


## Writing a service

TODO see Weasel Diesel for now and the generated service example.
Expand Down
7 changes: 3 additions & 4 deletions bin/wd_sinatra
Expand Up @@ -40,10 +40,9 @@ class WdSinatra < Thor::Group
end

def create_files
copy_file "Rakefile", "#{name}/Rakefile"
copy_file "Gemfile", "#{name}/Gemfile"
copy_file "config.ru", "#{name}/config.ru"
copy_file "Guardfile", "#{name}/Guardfile"
%W{Rakefile Gemfile config.ru Guardfile Thorfile}.each do |filename|
copy_file filename, "#{name}/#{filename}"
end
end

end
Expand Down
2 changes: 1 addition & 1 deletion lib/wd_sinatra/version.rb
@@ -1,5 +1,5 @@
module WD
module Sinatra
VERSION = "0.2.6"
VERSION = "0.3.0"
end
end
59 changes: 59 additions & 0 deletions templates/Thorfile
@@ -0,0 +1,59 @@
# encoding: utf-8
$:.unshift File.expand_path("../lib", __FILE__)
require 'bundler'
require 'active_support/inflector'

class Default < Thor
include Thor::Actions

desc "service VERB URI FILENAME", "Generate scaffolding for a new service"
def service(verb, route, path)
route = route.gsub(/^\//, "") # strip leading forward slash
path_without_suffix = path.gsub(/\.rb$/, "")
create_file(File.join("api", "#{path_without_suffix}.rb")) do
<<-RUBY.gsub(/^\s{6}/, '')
describe_service "#{route}" do |service|
service.formats :json
service.http_verb :#{verb.downcase}
service.disable_auth # on by default
# INPUT
service.param.string :name, :default => 'World', :doc => "The name of the person to greet."
# OUTPUT
service.response do |response|
response.object do |obj|
obj.string :message, :doc => "The greeting message sent back. Defaults to 'World'"
obj.datetime :at, :doc => "The timestamp of when the message was dispatched"
end
end
# DOCUMENTATION
service.documentation do |doc|
doc.overall "This service provides a simple hello world implementation example."
doc.example "<code>curl -I 'http://localhost:9292/hello_world?name=Matt'</code>"
end
# ACTION/IMPLEMENTATION
service.implementation do
halt 501, "Not Implemented, which is a pity, I'm sure"
end
end
RUBY
end

class_name = path_without_suffix.classify.gsub(/::/, '') # strip modules; just want a unique class name for spec
create_file(File.join("test", "integration", "#{path_without_suffix}_test.rb")) do
<<-RUBY.gsub(/^\s{6}/, '')
require 'test_helpers'
class #{class_name}Spec < MiniTest::Spec
it "performs request" do
TestApi.#{verb} "/#{route}", {}
assert_api_response
end
end
RUBY
end
end
end
1 change: 1 addition & 0 deletions templates/test/test_helpers.rb
@@ -1,5 +1,6 @@
ENV['RACK_ENV'] ||= 'test'
require 'test/unit'
require 'minitest/spec'
require 'rack'
require 'rack/test'
require 'json'
Expand Down

4 comments on commit aece611

@aeden
Copy link
Collaborator

@aeden aeden commented on aece611 Jun 20, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, but you forgot to push to rubygems.org :-/

@aeden
Copy link
Collaborator

@aeden aeden commented on aece611 Jun 20, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattetti fwiw, I tried to push the 0.3.0 version but didn't have permissions on rubygems.org

@mattetti
Copy link
Owner Author

@mattetti mattetti commented on aece611 Jun 20, 2012 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattetti
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed now

Please sign in to comment.