goofy 1.0.2

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.
Files changed (85) hide show
  1. checksums.yaml +7 -0
  2. data/.gems +4 -0
  3. data/.gitignore +2 -0
  4. data/CHANGELOG +47 -0
  5. data/CONTRIBUTING +19 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE +23 -0
  8. data/README.md +67 -0
  9. data/app/.rspec +2 -0
  10. data/app/Gemfile +13 -0
  11. data/app/app/controllers/application_controller.rb +3 -0
  12. data/app/app/services/.keep +0 -0
  13. data/app/config.ru +4 -0
  14. data/app/config/environment.rb +9 -0
  15. data/app/config/initializers/.keep +0 -0
  16. data/app/config/routes.rb +7 -0
  17. data/app/config/settings.rb +0 -0
  18. data/app/spec/helpers.rb +2 -0
  19. data/app/spec/helpers/goofy.rb +11 -0
  20. data/app/spec/spec_helper.rb +107 -0
  21. data/benchmark/measure.rb +35 -0
  22. data/bin/check_its_goofy.rb +15 -0
  23. data/bin/goofy +61 -0
  24. data/bin/goofy_generator.rb +357 -0
  25. data/bin/goofy_instance_creator.rb +40 -0
  26. data/examples/config.ru +18 -0
  27. data/examples/measure.rb +17 -0
  28. data/examples/rack-response.ru +21 -0
  29. data/examples/views/home.mote +7 -0
  30. data/examples/views/layout.mote +11 -0
  31. data/goofy.gemspec +26 -0
  32. data/lib/goofy.rb +405 -0
  33. data/lib/goofy/capybara.rb +13 -0
  34. data/lib/goofy/controller.rb +14 -0
  35. data/lib/goofy/controller/base.rb +21 -0
  36. data/lib/goofy/controller/callbacks.rb +19 -0
  37. data/lib/goofy/render.rb +63 -0
  38. data/lib/goofy/router.rb +9 -0
  39. data/lib/goofy/safe.rb +23 -0
  40. data/lib/goofy/safe/csrf.rb +47 -0
  41. data/lib/goofy/safe/secure_headers.rb +40 -0
  42. data/lib/goofy/test.rb +11 -0
  43. data/makefile +4 -0
  44. data/test/accept.rb +32 -0
  45. data/test/captures.rb +162 -0
  46. data/test/composition.rb +69 -0
  47. data/test/controller.rb +29 -0
  48. data/test/cookie.rb +34 -0
  49. data/test/csrf.rb +139 -0
  50. data/test/extension.rb +21 -0
  51. data/test/helper.rb +11 -0
  52. data/test/host.rb +29 -0
  53. data/test/integration.rb +114 -0
  54. data/test/match.rb +86 -0
  55. data/test/middleware.rb +46 -0
  56. data/test/number.rb +36 -0
  57. data/test/on.rb +157 -0
  58. data/test/param.rb +66 -0
  59. data/test/path.rb +86 -0
  60. data/test/plugin.rb +68 -0
  61. data/test/rack.rb +22 -0
  62. data/test/redirect.rb +21 -0
  63. data/test/render.rb +128 -0
  64. data/test/root.rb +83 -0
  65. data/test/run.rb +23 -0
  66. data/test/safe.rb +74 -0
  67. data/test/segment.rb +45 -0
  68. data/test/session.rb +21 -0
  69. data/test/settings.rb +52 -0
  70. data/test/views/about.erb +1 -0
  71. data/test/views/about.str +1 -0
  72. data/test/views/content-yield.erb +1 -0
  73. data/test/views/custom/abs_path.mote +1 -0
  74. data/test/views/frag.mote +1 -0
  75. data/test/views/home.erb +2 -0
  76. data/test/views/home.mote +1 -0
  77. data/test/views/home.str +2 -0
  78. data/test/views/layout-alternative.erb +2 -0
  79. data/test/views/layout-yield.erb +3 -0
  80. data/test/views/layout.erb +2 -0
  81. data/test/views/layout.mote +2 -0
  82. data/test/views/layout.str +2 -0
  83. data/test/views/test.erb +1 -0
  84. data/test/with.rb +42 -0
  85. metadata +271 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7c1a9c1efee6bfe916d95f48592c7edadf1d059d
4
+ data.tar.gz: b3e2c222a1682cc93303040f33643d4acb3a7f65
5
+ SHA512:
6
+ metadata.gz: 783865b05059d08ea9f1daff29d53b4f22d895b3abd94cf1312844c0570f46c06578c0fefce718974b714ba9391b177acba5f9b3b41e30f87396abbdd5c0f9cb
7
+ data.tar.gz: 6a718a4e276abd37c50e3ac0bc67b9fd3918165d9b033c1610ff8b97ef84c0b815e515acbbc1c985223e8843860dd6c38b157a601e35d9bb1a6abbd446784f16
data/.gems ADDED
@@ -0,0 +1,4 @@
1
+ cutest -v 1.2.2
2
+ rack -v 1.6.0
3
+ tilt -v 2.0.1
4
+ rack-test -v 0.6.3
@@ -0,0 +1,2 @@
1
+ /pkg
2
+ webrat.log
@@ -0,0 +1,47 @@
1
+ 3.5.0
2
+
3
+ * Add `not_found` hook for customizing the 404 error.
4
+
5
+ * Remove undocumented `header` matcher.
6
+
7
+ * Depend explicitly on Rack 1.6.x.
8
+
9
+ * Experimental feature: `param` now accepts a second parameter
10
+ with a default value.
11
+
12
+ 3.4.0
13
+
14
+ * Add `Goofy::Safe` plugin. This plugin contains security related
15
+ defaults.
16
+
17
+ 3.3.0
18
+
19
+ * Restrict when to add the default content type.
20
+
21
+ 3.2.0
22
+
23
+ * Return 404 when status is not explicitly set and body is empty.
24
+
25
+ 3.1.1
26
+
27
+ * Add support for custom default layouts.
28
+
29
+ 3.1.0
30
+
31
+ * Do a deep clone of the settings object during inheritance.
32
+ * Start namespacing plugins (i.e. settings[:render]).
33
+ * Use rack/test when doing `require 'Goofy/test'`.
34
+ * Capybara available via `require 'Goofy/capybara'`.
35
+ * Use a default hash for the render plugin.
36
+ * Allow the use of custom Request and Response objects.
37
+
38
+ 3.0.0
39
+
40
+ * Remove Goofy.build. Use subclassing instead.
41
+ * Remove warnings.
42
+ * Use Goofy::Response instead of Rack::Response.
43
+ * Integrate Goofy.plugin and Goofy.settings.
44
+ * Remove Goofy::VERSION.
45
+ * Rename _call to call! (inspired from Sinatra).
46
+ * Fix a memory leak with the caching used in Tilt.
47
+ * Adding syntax highlighting to the README Code blocks
@@ -0,0 +1,19 @@
1
+ This code tries to solve a particular problem with a very simple
2
+ implementation. We try to keep the code to a minimum while making
3
+ it as clear as possible. The design is very likely finished, and
4
+ if some feature is missing it is possible that it was left out on
5
+ purpose. That said, new usage patterns may arise, and when that
6
+ happens we are ready to adapt if necessary.
7
+
8
+ A good first step for contributing is to meet us on IRC and discuss
9
+ ideas. We spend a lot of time on #lesscode at freenode, always ready
10
+ to talk about code and simplicity. If connecting to IRC is not an
11
+ option, you can create an issue explaining the proposed change and
12
+ a use case. We pay a lot of attention to use cases, because our
13
+ goal is to keep the code base simple. Usually the result of a
14
+ conversation is the creation of a different tool.
15
+
16
+ Please don't start the conversation with a pull request. The code
17
+ should come at last, and even though it may help to convey an idea,
18
+ more often than not it draws the attention to a particular
19
+ implementation.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in goofy.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ Copyright (c) 2008-2009 Christian Neukirchen
2
+ Copyright (c) 2010-2015 Michel Martens
3
+ Copyright (c) 2010-2015 Damian Janowski
4
+ Copyright (c) 2010-2015 Cyril David
5
+ Copyright (c) 2013-2015 Francesco Rodríguez
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in
15
+ all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ THE SOFTWARE.
@@ -0,0 +1,67 @@
1
+ # Goofy
2
+
3
+ A microframework for web development heavily based on [Cuba](http://cuba.is)
4
+
5
+ ![Goofy](http://www.coloring-book.info/coloring/Goofy/goofy_12.jpg)
6
+
7
+ ## Description
8
+
9
+ Goofy is a microframework for web heavily based on [Cuba](http://cuba.is).
10
+ Cuba is the fastest ruby microframework at the moment.
11
+ Goofy is fast as [Cuba](http://cuba.is) but more featured and structured.
12
+
13
+ ## Installation
14
+
15
+ $ gem install goofy
16
+
17
+ ## Usage
18
+
19
+ Run:
20
+
21
+ $ goofy help
22
+
23
+ To get nessecary information.
24
+
25
+ ## Controllers
26
+
27
+ Goofy controllers follow SRP(Single Responsibility Principle), in other words each action maps to one controller.
28
+ Goofy controllers use [Prong](https://github.com/EhsanYousefi/Prong) in order to support rails-like callbacks.
29
+ Every method that available in Cuba router is available in Goofy controller like `res.write`.
30
+ Create new Goofy application and generate a controller to get to know Goofy controllers.
31
+
32
+ Services
33
+ --------
34
+ In order to understand Goofy services, take a look at [Wisper](https://github.com/krisleech/wisper) documentation, in other words Goofy uses [Wisper](https://github.com/krisleech/wisper) to decouple core business logic from external concerns in Hexagonal style architectures.
35
+
36
+ ## Router
37
+
38
+ There is no difference between Goofy router and Cuba router expect controller method:
39
+ ```ruby
40
+ # app/controlers/welcome_controller.rb
41
+ class WelcomeController < ApplicationController
42
+ def response
43
+ res.write "Foo Bar"
44
+ end
45
+ end
46
+ ```
47
+ ```ruby
48
+ # config/router.rb
49
+ Goofy.define do
50
+ on get, "welcome" do
51
+ controller WelcomeController
52
+ end
53
+ end
54
+ ```
55
+
56
+ ## Test
57
+
58
+ Goofy uses [Rspec](https://github.com/rspec/rspec) as default test system.
59
+
60
+ ## Contributing
61
+
62
+ Bug reports and pull requests are welcome on GitHub at https://github.com/EhsanYousefi/closet. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
63
+
64
+
65
+ ## License
66
+
67
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -0,0 +1,13 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Microframework for web applications
4
+ gem 'goofy', '~> 1.0.0', :require => ['goofy','goofy/controller']
5
+ # A micro library providing Ruby objects with Publish-Subscribe capabilities
6
+ gem 'wisper'
7
+ # A wonderfully simple way to load your code
8
+ gem 'require_all'
9
+
10
+ group :test, :development do
11
+ # Behaviour Driven Development for Ruby
12
+ gem 'rspec'
13
+ end
@@ -0,0 +1,3 @@
1
+ class ApplicationController < Goofy::Controller
2
+
3
+ end
File without changes
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Goofy
@@ -0,0 +1,9 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ Bundler.require(:default, ENV["RACK_ENV"])
4
+ require "require_all"
5
+ require "goofy"
6
+ require "goofy/controller"
7
+ require_all './config/initializers'
8
+ require_all './app'
9
+ require_relative "routes"
File without changes
@@ -0,0 +1,7 @@
1
+ Goofy.define do
2
+
3
+ # on get, "welcome" do
4
+ # controller WelcomeController
5
+ # end
6
+
7
+ end
File without changes
@@ -0,0 +1,2 @@
1
+ module Helpers
2
+ end
@@ -0,0 +1,11 @@
1
+ module Helpers::Goofy
2
+
3
+ def app
4
+ Goofy
5
+ end
6
+
7
+ def response
8
+ self.last_response
9
+ end
10
+
11
+ end
@@ -0,0 +1,107 @@
1
+ require 'require_all'
2
+ require ::File.expand_path('../../config/environment', __FILE__)
3
+ require 'rack/test'
4
+ # require helpers
5
+ require "helpers"
6
+ require_all './spec/helpers'
7
+
8
+ # This file was generated by the `rspec --init` command. Conventionally, all
9
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
10
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
11
+ # this file to always be loaded, without a need to explicitly require it in any
12
+ # files.
13
+ #
14
+ # Given that it is always loaded, you are encouraged to keep this file as
15
+ # light-weight as possible. Requiring heavyweight dependencies from this file
16
+ # will add to the boot time of your test suite on EVERY test run, even for an
17
+ # individual file that may not need all of that loaded. Instead, consider making
18
+ # a separate helper file that requires the additional dependencies and performs
19
+ # the additional setup, and require it from the spec files that actually need
20
+ # it.
21
+ #
22
+ # The `.rspec` file also contains a few flags that are not defaults but that
23
+ # users commonly want.
24
+ #
25
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
26
+ RSpec.configure do |config|
27
+ # include rack helper methods
28
+ config.include Rack::Test::Methods
29
+ # include goofy helper
30
+ config.include Helpers::Goofy
31
+ # rspec-expectations config goes here. You can use an alternate
32
+ # assertion/expectation library such as wrong or the stdlib/minitest
33
+ # assertions if you prefer.
34
+ config.expect_with :rspec do |expectations|
35
+ # This option will default to `true` in RSpec 4. It makes the `description`
36
+ # and `failure_message` of custom matchers include text for helper methods
37
+ # defined using `chain`, e.g.:
38
+ # be_bigger_than(2).and_smaller_than(4).description
39
+ # # => "be bigger than 2 and smaller than 4"
40
+ # ...rather than:
41
+ # # => "be bigger than 2"
42
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
43
+ end
44
+
45
+ # rspec-mocks config goes here. You can use an alternate test double
46
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
47
+ config.mock_with :rspec do |mocks|
48
+ # Prevents you from mocking or stubbing a method that does not exist on
49
+ # a real object. This is generally recommended, and will default to
50
+ # `true` in RSpec 4.
51
+ mocks.verify_partial_doubles = true
52
+ end
53
+
54
+ # The settings below are suggested to provide a good initial experience
55
+ # with RSpec, but feel free to customize to your heart's content.
56
+ =begin
57
+ # These two settings work together to allow you to limit a spec run
58
+ # to individual examples or groups you care about by tagging them with
59
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
60
+ # get run.
61
+ config.filter_run :focus
62
+ config.run_all_when_everything_filtered = true
63
+
64
+ # Allows RSpec to persist some state between runs in order to support
65
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
66
+ # you configure your source control system to ignore this file.
67
+ config.example_status_persistence_file_path = "spec/examples.txt"
68
+
69
+ # Limits the available syntax to the non-monkey patched syntax that is
70
+ # recommended. For more details, see:
71
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
72
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
73
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
74
+ config.disable_monkey_patching!
75
+
76
+ # This setting enables warnings. It's recommended, but in some cases may
77
+ # be too noisy due to issues in dependencies.
78
+ config.warnings = true
79
+
80
+ # Many RSpec users commonly either run the entire suite or an individual
81
+ # file, and it's useful to allow more verbose output when running an
82
+ # individual spec file.
83
+ if config.files_to_run.one?
84
+ # Use the documentation formatter for detailed output,
85
+ # unless a formatter has already been configured
86
+ # (e.g. via a command-line flag).
87
+ config.default_formatter = 'doc'
88
+ end
89
+
90
+ # Print the 10 slowest examples and example groups at the
91
+ # end of the spec run, to help surface which specs are running
92
+ # particularly slow.
93
+ config.profile_examples = 10
94
+
95
+ # Run specs in random order to surface order dependencies. If you find an
96
+ # order dependency and want to debug it, you can fix the order by providing
97
+ # the seed, which is printed after each run.
98
+ # --seed 1234
99
+ config.order = :random
100
+
101
+ # Seed global randomization in this process using the `--seed` CLI option.
102
+ # Setting this allows you to use `--seed` to deterministically reproduce
103
+ # test failures related to randomization by passing the same `--seed` value
104
+ # as the one that triggered the failure.
105
+ Kernel.srand config.seed
106
+ =end
107
+ end
@@ -0,0 +1,35 @@
1
+ require "benchmark"
2
+ require "../lib/goofy"
3
+ require "../lib/goofy/controller"
4
+
5
+ class HomeController < Goofy::Controller
6
+
7
+ def response
8
+ res.write("wazzup?")
9
+ end
10
+
11
+ end
12
+
13
+ Goofy.define do
14
+ on "c" do
15
+ controller HomeController
16
+ end
17
+ on "w" do
18
+ res.write("wazzup?")
19
+ end
20
+ end
21
+
22
+ Benchmark.bmbm do |x|
23
+
24
+ x.report "with controller" do
25
+ 10000.times do
26
+ Goofy.call({ "PATH_INFO" => "/c", "SCRIPT_NAME" => "/" })
27
+ end
28
+ end
29
+
30
+ x.report "without controller" do
31
+ 10000.times do
32
+ Goofy.call({ "PATH_INFO" => "/w", "SCRIPT_NAME" => "/" })
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,15 @@
1
+ class CheckItsGoofy
2
+ def initialize(path)
3
+ @path = path
4
+ end
5
+
6
+ def execute!
7
+ begin
8
+ file = File.read(@path + '/Gemfile')
9
+ rescue
10
+ return false
11
+ end
12
+ exsits = file.scan /goofy/
13
+ !exsits.empty?
14
+ end
15
+ end
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/env ruby
2
+ require 'fileutils'
3
+ require 'bundler'
4
+ require_relative 'goofy_instance_creator'
5
+ require_relative 'goofy_generator'
6
+ require_relative 'check_its_goofy'
7
+
8
+ command = ARGV[0]
9
+ app_dir = File.dirname(__FILE__).gsub(/bin/, "app")
10
+ current_dir = FileUtils.getwd()
11
+
12
+ case command
13
+ when "new"
14
+ GoofyInstanceCreator.new(ARGV[1], app_dir, current_dir).execute!
15
+
16
+ when "console", "c"
17
+ if ARGV[1..-1].empty?
18
+ exec "racksh"
19
+ else
20
+ if ARGV[-2] == '-e' || ARGV[-2] == '--environment'
21
+ exec "RACK_ENV=#{ARGV.last} racksh"
22
+ else
23
+ puts "Invalid option try: goofy console -e DESIRE_ENVIRONMENT"
24
+ end
25
+ end
26
+
27
+ when "server", "s"
28
+ if ARGV[1..-1].empty?
29
+ exec "shotgun config.ru"
30
+ else
31
+ exec "shotgun #{ARGV[1..-1].join(" ")} config.ru"
32
+ end
33
+
34
+ when "generate", "g"
35
+ unless CheckItsGoofy.new(current_dir).execute!
36
+ puts("This is not a Goofy Application, Try this command inside root folder of a Goofy application.")
37
+ abort
38
+ end
39
+ GoofyGenerator::Base.new(ARGV[1], ARGV[2]).execute!
40
+
41
+ when "help"
42
+ puts "Usage:"
43
+ puts " goofy new APP_PATH"
44
+ puts "Server:(shoutgun)"
45
+ puts " goofy server"
46
+ puts "Console:(racksh)"
47
+ puts " gooy console"
48
+ puts "Generator:"
49
+ puts " Resource:"
50
+ puts " goofy generate resource RESOURCE_PATH"
51
+ puts " Controller:"
52
+ puts " goofy generate controller CONTROLLER_PATH"
53
+ puts " Service:"
54
+ puts " goofy generate service SERVICE_PATH"
55
+ puts " Initializer:"
56
+ puts " goofy generate initializer INITIALIZER_NAME"
57
+ puts "-----------------------------------------------------"
58
+ puts "Good luck :)"
59
+ else
60
+ puts "Invalid command try: goofy help"
61
+ end