/lib/sinatra.fy

http://github.com/bakkdoor/sinatra.fy · Unknown · 75 lines · 57 code · 18 blank · 0 comment · 0 complexity · b24b1c28ea006ca53b50206bbd78e4a4 MD5 · raw file

  1. require("sinatra")
  2. class Sinatra Base {
  3. def self def: name with: block {
  4. metaclass ruby: 'define_method args: [name] with_block: block
  5. Sinatra Delegator delegate(name)
  6. }
  7. def self configure: env with: block {
  8. args = [env] flatten()
  9. configure(env, &block)
  10. }
  11. def self configure: block {
  12. configure(&block)
  13. }
  14. def self wrap: method {
  15. def: "#{method}:" with: |b | { ruby: method with_block: b }
  16. def: "#{method}:do:" with: |a, b| { ruby: method args: [a] with_block: b }
  17. }
  18. def self wrapAll: methods {
  19. methods each: |m| { wrap: m }
  20. }
  21. wrapAll: [
  22. 'get, 'put, 'post, 'delete, 'head, 'patch, 'before, 'after, 'helpers,
  23. 'not_found, 'template, 'layout
  24. ]
  25. def self enable: options {
  26. enable(*options) flatten()
  27. }
  28. def self disable: options {
  29. disable(*options) flatten()
  30. }
  31. def self set: option to: value {
  32. set(option, value)
  33. }
  34. Sinatra Delegator delegate('enable:, 'disable:, 'set:to:,
  35. 'configure:, 'configure:with:)
  36. forwards_unary_ruby_methods
  37. alias_method: 'redirect: for_ruby: 'redirect
  38. alias_method: 'to: for_ruby: 'to
  39. alias_method: 'content_type: for_ruby: 'content_type
  40. def self helpers: block {
  41. helpers(&block)
  42. }
  43. }
  44. class Sinatra Request {
  45. forwards_unary_ruby_methods
  46. }
  47. class Rack Response {
  48. forwards_unary_ruby_methods
  49. alias_method: '[] for_ruby: '[]
  50. alias_method: '[]: for_ruby: '[]=
  51. }
  52. class Rack Request {
  53. forwards_unary_ruby_methods
  54. alias_method: '[] for_ruby: '[]
  55. alias_method: '[]: for_ruby: '[]=
  56. }
  57. enable: 'run