lunetas 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -17,5 +17,8 @@ tmtags
17
17
  coverage
18
18
  rdoc
19
19
  pkg
20
+ *.gemspec
21
+ doc/**
20
22
 
21
23
  ## PROJECT::SPECIFIC
24
+
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.0.1
@@ -0,0 +1,12 @@
1
+ require 'lunetas'
2
+ require 'json'
3
+
4
+ class JaySon
5
+ include Lunetas::Candy
6
+ matches '^/something\.json$'
7
+ set_content_type 'application/json'
8
+
9
+ def get
10
+ { :test => true, 'json' => "Yes, JSON", :amount => 1}.to_json
11
+ end
12
+ end
@@ -1,9 +1,13 @@
1
- require '../lib/lunetas'
1
+ require 'lunetas'
2
2
 
3
3
  class Testing
4
4
  include Lunetas::Candy
5
5
  matches '/hello/(\w+)', :name
6
6
 
7
+ def before
8
+ @name = @name.capitalize
9
+ end
10
+
7
11
  def get
8
12
  "Hello #{@name}! #{params[:chunky]}"
9
13
  end
@@ -97,7 +97,7 @@ module Lunetas::Candy
97
97
  # end
98
98
 
99
99
  def response(object, code = 200)
100
- [code, {'Content-Type' => "application/json"}, [object.to_s]]
100
+ [code, {'Content-Type' => self.class.content_type}, [object.to_s]]
101
101
  end
102
102
 
103
103
  # The following methods should be overwritten by the including class
@@ -140,6 +140,7 @@ module Lunetas::Candy
140
140
 
141
141
  module ClassMethods
142
142
  attr_reader :_url_params
143
+ attr_reader :content_type
143
144
 
144
145
  # Support to be runned as a Rails Metal.
145
146
  # @param [Hash] env the Rack env.
@@ -170,6 +171,7 @@ module Lunetas::Candy
170
171
  # @param [Array<Symbol, String>] url_params the instance variables that will
171
172
  # be set for the captures from the regex.
172
173
  def matches(regex, *url_params)
174
+ @content_type = 'text/html'
173
175
  @_regex = regex
174
176
  unless Regexp === @_regex
175
177
  @_regex = Regexp.new(@_regex)
@@ -177,6 +179,12 @@ module Lunetas::Candy
177
179
  @_url_params = url_params
178
180
  Lunetas::Bag.register(@_regex, self)
179
181
  end
182
+
183
+ # Sets the Content Type for this URL. Defaults to text/html.
184
+ # @param [String] content_type the ContentType for the response.
185
+ def set_content_type(content_type)
186
+ @content_type = content_type
187
+ end
180
188
  end
181
189
 
182
190
  def self.included(receiver)
@@ -59,6 +59,15 @@ describe Lunetas::Candy::InstanceMethods do
59
59
  @instance.bite.last.should == ['Chunky Bacon']
60
60
  end
61
61
 
62
+ it 'should have the default ContentType if not set' do
63
+ @instance.bite[1]["Content-Type"].should == "text/html"
64
+ end
65
+
66
+ it 'should set another ContentType' do
67
+ TestClass.send(:set_content_type, 'text/plain')
68
+ @instance.bite[1]["Content-Type"].should == "text/plain"
69
+ end
70
+
62
71
  %w{post put delete head trace options}.each do |verb|
63
72
  it 'should call to the #{verb} method if called with #{verb.upcase}' do
64
73
  mock_env = mock_env('/just_a_test')
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lunetas
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 0
10
- version: 0.0.0
9
+ - 1
10
+ version: 0.0.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Iv\xC3\xA1n Vald\xC3\xA9s (@ivanvc)"
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-21 00:00:00 -05:00
18
+ date: 2010-08-24 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -93,6 +93,7 @@ files:
93
93
  - Rakefile
94
94
  - VERSION
95
95
  - examples/config.ru
96
+ - examples/jay_son.rb
96
97
  - examples/testing.rb
97
98
  - lib/lunetas.rb
98
99
  - lib/lunetas/bag.rb
@@ -140,4 +141,5 @@ test_files:
140
141
  - spec/lunetas/bag_spec.rb
141
142
  - spec/lunetas/candy_spec.rb
142
143
  - spec/spec_helper.rb
144
+ - examples/jay_son.rb
143
145
  - examples/testing.rb