tynn 1.0.0.rc3 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8e2fe7081578c608775773d67ab5e4dc92a33414
4
- data.tar.gz: 96e869a9ec51ed45ab5baf116cd8126c32c4b597
3
+ metadata.gz: d821049145b6aac7727124929f21acbc7596502a
4
+ data.tar.gz: 9766f2492ecba5bc81cf6630d517d3f3a1245d48
5
5
  SHA512:
6
- metadata.gz: dd4c49a2f298af29cefebca3650c488ab2bbb527299f700e9a72964e01a4fc1352fa7da6ef2264b25be24cedaaf6272ac53b5a603619da19c3d24a1b207235e4
7
- data.tar.gz: 4ba63a68c74cbc71463b0e010ae985b8dab7d34d55e2043f1ed776774c8de93b4e07a33d7b08724fb1bacfd9e3156fa70bde9a37fe0912c214ecff1c159f6779
6
+ metadata.gz: b39573bfd1b8d61d9963a74f51dd27ba04da957f834f34fd08a8d0c0ec6038e8a33a6e03d4f99083592238171f0c305a18e2c32545658cbccddb377892aeea8b
7
+ data.tar.gz: 5aa36b7ab17f017c45028c43f0ecacaa0614e5ff040ebff7fb47ca6f46d8a64075395e3f6b74e3cefe48c6fa38b36dca99aa5ce3736694484131d603224f85c5
data/README.md CHANGED
@@ -48,6 +48,6 @@ Contributing
48
48
  You can install the gems globally, but we recommend [gs][gs] (or
49
49
  [gst][gst] if you're using chruby) to keep things isolated.
50
50
 
51
- [syro]: https://github.com/soveran/syro
51
+ [syro]: http://soveran.github.io/syro/
52
52
  [gs]: https://github.com/soveran/gs
53
53
  [gst]: https://github.com/tonchis/gst
@@ -1,6 +1,25 @@
1
1
  class Tynn
2
+ # Public: Adds method for HTTP's +HEAD+ and +OPTIONS+.
3
+ #
4
+ # Examples
5
+ #
6
+ # require "tynn"
7
+ # require "tynn/all_methods"
8
+ #
9
+ # Tynn.helpers(Tynn::AllMethods)
10
+ #
2
11
  module AllMethods
3
12
  module InstanceMethods
13
+ # Public: Executes the given block if the request method is +HEAD+.
14
+ #
15
+ # Examples
16
+ #
17
+ # Tynn.define do
18
+ # head do
19
+ # res.status = 201
20
+ # end
21
+ # end
22
+ #
4
23
  def head
5
24
  if root? && req.head?
6
25
  yield
@@ -9,6 +28,16 @@ class Tynn
9
28
  end
10
29
  end
11
30
 
31
+ # Public: Executes the given block if the request method is +OPTIONS+.
32
+ #
33
+ # Examples
34
+ #
35
+ # Tynn.define do
36
+ # options do
37
+ # res.status = 405
38
+ # end
39
+ # end
40
+ #
12
41
  def options
13
42
  if root? && req.options?
14
43
  yield
@@ -21,23 +21,69 @@ class Tynn
21
21
  # Tynn.helpers(Tynn::Environment, env: ENV["RACK_ENV"])
22
22
  #
23
23
  module Environment
24
- def self.setup(app, env: ENV["RACK_ENV"]) # :nodoc:
24
+ # Internal: Configures current environment.
25
+ def self.setup(app, env: ENV["RACK_ENV"])
25
26
  app.set(:environment, (env || :development).to_sym)
26
27
  end
27
28
 
28
- module ClassMethods # :nodoc:
29
+ module ClassMethods
30
+ # Public: Returns current environment.
31
+ #
32
+ # Examples
33
+ #
34
+ # Tynn.environment
35
+ # # => :development
36
+ #
37
+ # Tynn.set(:environment, :test)
38
+ #
39
+ # Tynn.environment
40
+ # # => :test
41
+ #
29
42
  def environment
30
43
  return settings[:environment]
31
44
  end
32
45
 
46
+ # Public: Returns +true+ if the current environment is +:development+.
47
+ # Otherwise returns +false+.
48
+ #
49
+ # Examples
50
+ #
51
+ # Tynn.set(:environment, :test)
52
+ # Tynn.development? # => false
53
+ #
54
+ # Tynn.set(:environment, :development)
55
+ # Tynn.development? # => true
56
+ #
33
57
  def development?
34
58
  return environment == :development
35
59
  end
36
60
 
61
+ # Public: Returns +true+ if the current environment is +:test+.
62
+ # Otherwise returns +false+.
63
+ #
64
+ # Examples
65
+ #
66
+ # Tynn.set(:environment, :development)
67
+ # Tynn.test? # => false
68
+ #
69
+ # Tynn.set(:environment, :test)
70
+ # Tynn.test? # => true
71
+ #
37
72
  def test?
38
73
  return environment == :test
39
74
  end
40
75
 
76
+ # Public: Returns +true+ if the current environment is +:production+.
77
+ # Otherwise returns +false+.
78
+ #
79
+ # Examples
80
+ #
81
+ # Tynn.set(:environment, :development)
82
+ # Tynn.production? # => false
83
+ #
84
+ # Tynn.set(:environment, :production)
85
+ # Tynn.production? # => true
86
+ #
41
87
  def production?
42
88
  return environment == :production
43
89
  end
@@ -13,10 +13,10 @@ class Tynn
13
13
  # Tynn.define { }
14
14
  #
15
15
  # app = Tynn::Test.new
16
- # app.get("/", {}, "HTTP_HOST" => "tynn.ru")
16
+ # app.get("/", {}, "HTTP_HOST" => "tynn.xyz")
17
17
  #
18
18
  # app.res.headers["Location"]
19
- # # => "https://tynn.ru/"
19
+ # # => "https://tynn.xyz/"
20
20
  #
21
21
  module ForceSSL
22
22
  # Internal: Sets the HTTPS redirect middleware.
data/lib/tynn/hmote.rb CHANGED
@@ -10,13 +10,13 @@ class Tynn
10
10
  module InstanceMethods
11
11
  include ::HMote::Helpers
12
12
 
13
- def render(template, locals = {}, layout = settings[:layout])
13
+ def render(template, locals = {}, layout = self.class.settings[:layout])
14
14
  res.headers[Rack::CONTENT_TYPE] ||= Syro::Response::DEFAULT
15
15
 
16
16
  res.write(view(template, locals, layout))
17
17
  end
18
18
 
19
- def view(template, locals = {}, layout = settings[:layout])
19
+ def view(template, locals = {}, layout = self.class.settings[:layout])
20
20
  return partial(layout, locals.merge(content: partial(template, locals)))
21
21
  end
22
22
 
@@ -27,7 +27,7 @@ class Tynn
27
27
  private
28
28
 
29
29
  def template_path(template)
30
- return File.join(settings[:views], "#{ template }.mote")
30
+ return File.join(self.class.settings[:views], "#{ template }.mote")
31
31
  end
32
32
  end
33
33
  end
data/lib/tynn/matchers.rb CHANGED
@@ -10,7 +10,7 @@ class Tynn
10
10
  #
11
11
  module Matchers
12
12
  module InstanceMethods
13
- # Public: A catch-all matcher.
13
+ # Public: A catch-all matcher. Always executes the given block.
14
14
  #
15
15
  # Examples
16
16
  #
@@ -24,15 +24,15 @@ class Tynn
24
24
  # end
25
25
  # end
26
26
  #
27
- # :call-seq: default(&block)
28
- #
29
27
  def default
30
28
  yield
31
29
 
32
30
  halt(res.finish)
33
31
  end
34
32
 
35
- # Public: Match if the given +key+ is present in +req.params+.
33
+ # Public: Executes the given block if +key+ is present in +req.params+.
34
+ #
35
+ # key - Any object that responds to +to_s+.
36
36
  #
37
37
  # Examples
38
38
  #
@@ -44,12 +44,10 @@ class Tynn
44
44
  # end
45
45
  #
46
46
  # default do
47
- # res.write("missing user param")
47
+ # res.write("missing [user] param")
48
48
  # end
49
49
  # end
50
50
  #
51
- # :call-seq: param(key, &block)
52
- #
53
51
  def param(key)
54
52
  if (v = req[key]) && !v.empty?
55
53
  yield(v)
@@ -31,7 +31,7 @@ class Tynn
31
31
  # - Tynn::ForceSSL
32
32
  #
33
33
  module Protection
34
- # Internal: Configures security related extensions.
34
+ # Internal: Configures security related helpers.
35
35
  def self.setup(app, ssl: false, force_ssl: ssl, hsts: {})
36
36
  app.helpers(Tynn::SecureHeaders)
37
37
 
data/lib/tynn/render.rb CHANGED
@@ -14,18 +14,18 @@ class Tynn
14
14
  end
15
15
 
16
16
  module InstanceMethods
17
- def render(template, locals = {}, layout = settings[:layout])
17
+ def render(template, locals = {}, layout = self.class.settings[:layout])
18
18
  res.headers[Rack::CONTENT_TYPE] ||= Syro::Response::DEFAULT
19
19
 
20
20
  res.write(view(template, locals, layout))
21
21
  end
22
22
 
23
- def view(template, locals = {}, layout = settings[:layout])
23
+ def view(template, locals = {}, layout = self.class.settings[:layout])
24
24
  return partial(layout, locals.merge(content: partial(template, locals)))
25
25
  end
26
26
 
27
27
  def partial(template, locals = {})
28
- return tilt(template_path(template), locals, settings[:engine_opts])
28
+ return tilt(template_path(template), locals, self.class.settings[:engine_opts])
29
29
  end
30
30
 
31
31
  private
@@ -39,8 +39,8 @@ class Tynn
39
39
  end
40
40
 
41
41
  def template_path(template)
42
- dir = settings[:views]
43
- ext = settings[:engine]
42
+ dir = self.class.settings[:views]
43
+ ext = self.class.settings[:engine]
44
44
 
45
45
  return File.join(dir, "#{ template }.#{ ext }")
46
46
  end
data/lib/tynn/request.rb CHANGED
@@ -1,6 +1,53 @@
1
1
  class Tynn
2
- # It provides convenience methods for pulling out information
2
+ # Public: It provides convenience methods for pulling out information
3
3
  # from a request.
4
+ #
5
+ # Examples
6
+ #
7
+ # env = {
8
+ # "REQUEST_METHOD" => "GET"
9
+ # "QUERY_STRING" => "email=me@tynn.xyz"
10
+ # }
11
+ #
12
+ # req = Tynn::Request.new(env)
13
+ #
14
+ # req.get? # => true
15
+ # req.post? # => false
16
+ #
17
+ # req.params # => { "email" => "me@tynn.xyz" }
18
+ # req[:email] # => "me@tynn.xyz"
19
+ #
4
20
  class Request < Rack::Request
21
+ # Public: Returns the value of the +key+ param.
22
+ #
23
+ # key - Any object that responds to +to_s+.
24
+ #
25
+ # Examples
26
+ #
27
+ # req.params
28
+ # # => { "username" => "bob" }
29
+ #
30
+ # req[:username] # => "bob"
31
+ # req["username"] # => "bob"
32
+ #
33
+ # Signature
34
+ #
35
+ # [](key)
36
+ #
37
+ # Inherited by Rack::Request.
38
+
39
+ # Public: Returns a Hash of parameters. Includes data from the query
40
+ # string and the response body.
41
+ #
42
+ # Examples
43
+ #
44
+ # req.params
45
+ # # => { "user" => { "username" => "bob" } }
46
+ #
47
+ # Signature
48
+ #
49
+ # params()
50
+ #
51
+ # Inherited by Rack::Request.
5
52
  end
6
53
  end
data/lib/tynn/response.rb CHANGED
@@ -133,9 +133,9 @@ class Tynn
133
133
  # res["Location"] # => "/path"
134
134
  # res.status # => 302
135
135
  #
136
- # res.redirect("http://tynn.ru", 303)
136
+ # res.redirect("http://tynn.xyz", 303)
137
137
  #
138
- # res["Location"] # => "http://tynn.ru"
138
+ # res["Location"] # => "http://tynn.xyz"
139
139
  # res.status # => 303
140
140
  #
141
141
  # Signature
@@ -28,7 +28,7 @@ class Tynn
28
28
  #
29
29
  # Enables the XSS protection filter built into IE, Chrome and Safari.
30
30
  # This filter is usually enabled by default, the use of this header
31
- # is to re-enable it if it was disabled by the user.
31
+ # is to re-enable it if it was turned off by the user.
32
32
  #
33
33
  module SecureHeaders
34
34
  # Internal: Sets the default HTTP secure headers.
data/lib/tynn/settings.rb CHANGED
@@ -1,5 +1,30 @@
1
1
  class Tynn
2
- module Settings # :nodoc: all
2
+ # Public: It provides a settings API for applications. This helper is
3
+ # included by default.
4
+ #
5
+ # Examples
6
+ #
7
+ # require "tynn"
8
+ #
9
+ # module AppName
10
+ # def self.setup(app, app_name)
11
+ # app.settings[:app_name] = app_name
12
+ # end
13
+ #
14
+ # module ClassMethods
15
+ # def app_name
16
+ # return settings[:app_name]
17
+ # end
18
+ # end
19
+ # end
20
+ #
21
+ # Tynn.helpers(AppName, "MyApp")
22
+ #
23
+ # Tynn.app_name
24
+ # # => "MyApp"
25
+ #
26
+ module Settings
27
+ # Internal: Returns a deep copy of a Hash.
3
28
  def self.deepclone(hash)
4
29
  default_proc, hash.default_proc = hash.default_proc, nil
5
30
 
@@ -8,18 +33,23 @@ class Tynn
8
33
  hash.default_proc = default_proc
9
34
  end
10
35
 
11
- module InstanceMethods # :nodoc: all
12
- def settings
13
- return self.class.settings
14
- end
15
- end
16
-
17
- module ClassMethods # :nodoc: all
36
+ module ClassMethods
37
+ # Internal: Copies settings into the subclass.
38
+ # If a setting is not found, checks parent's settings.
18
39
  def inherited(subclass)
19
40
  subclass.settings.replace(Tynn::Settings.deepclone(settings))
20
41
  subclass.settings.default_proc = proc { |h, k| h[k] = settings[k] }
21
42
  end
22
43
 
44
+ # Returns a Hash with the application settings.
45
+ #
46
+ # Examples
47
+ #
48
+ # Tynn.set(:environment, :development)
49
+ #
50
+ # Tynn.settings
51
+ # # => { :environment => :development }
52
+ #
23
53
  def settings
24
54
  return @settings ||= {}
25
55
  end
data/lib/tynn/version.rb CHANGED
@@ -3,6 +3,6 @@ class Tynn # :nodoc: all
3
3
  MAJOR_VERSION = 1,
4
4
  MINOR_VERSION = 0,
5
5
  PATCH_VERSION = 0,
6
- PRE_VERSION = "rc3"
6
+ PRE_VERSION = nil
7
7
  ].compact.join(".")
8
8
  end
data/lib/tynn.rb CHANGED
@@ -111,7 +111,7 @@ class Tynn
111
111
  set(:default_headers, {})
112
112
 
113
113
  def default_headers # :nodoc:
114
- return Hash[settings[:default_headers]]
114
+ return Hash[self.class.settings[:default_headers]]
115
115
  end
116
116
 
117
117
  def request_class # :nodoc:
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tynn
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.rc3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francesco Rodríguez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-26 00:00:00.000000000 Z
11
+ date: 2015-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -168,9 +168,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
168
168
  version: '0'
169
169
  required_rubygems_version: !ruby/object:Gem::Requirement
170
170
  requirements:
171
- - - ">"
171
+ - - ">="
172
172
  - !ruby/object:Gem::Version
173
- version: 1.3.1
173
+ version: '0'
174
174
  requirements: []
175
175
  rubyforge_project:
176
176
  rubygems_version: 2.4.8