This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def call(env) | |
request = Rack::Request.new(env) | |
# env["REQUEST_METHOD"] | |
verb = request.request_method #=> GET, POST, PUT, etc. | |
# env["REQUEST_METHOD"] == "POST" | |
request.post? | |
# env["PATH_INFO"] | |
path = request.path_info | |
# env["rack.session"] | |
request.session # access to the session object, if using the |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "rack/handler/puma" | |
class AnotherRackApp | |
def call(env) | |
http_verb = env["REQUEST_METHOD"] | |
path = env["PATH_INFO"] | |
status = 200 | |
headers = {"Content-Type" => "text/html"} | |
body = ["got #{http_verb} <b>request</b> from <strong>#{path}</strong> path"] | |
[status, headers, body] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
run ->(env) { [200, {}, ["I respond to all #{env["REQUEST_METHOD"]} request"]] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "rack" | |
app = Proc.new { |env| [200, {}, ["I respond to all request"]] } | |
Rack::Handler::WEBrick.run app, Port: 9292 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MarkRuby | |
def div(text = "", options = {}, &block)) | |
html_tag(:div, text = "", options = {}, &block) | |
end | |
def body(text = "", options = {}, &block)) | |
html_tag(:body, text = "", options = {}, &block) | |
end | |
def html(text = "", options = {}, &block)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MarkRuby | |
def initialize(&block) | |
@curent_indentation = 0 | |
@html = "" | |
html(&block) | |
end | |
def method_missing(method_name, *args, &block) | |
text = args.shift if args[0].is_a? String | |
html_tag(method_name, text, *args, &block) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<body id="body_id"_> | |
<div id="container"> | |
<ul class="content"> | |
<li class="active">Item 1</li> | |
<li>Item 2</li> | |
</ul> | |
</div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mark_ruby do | |
body id: :body_id do | |
div id: :container do | |
ul class: :content do | |
li "Item 1", class: :active | |
li "Item 2" | |
end | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe Array do | |
describe "includes_subset?" do | |
it "finds subsets" do | |
a = [1,2,3,4,5] | |
b = [1,2] | |
expect(a.includes_subset?(b)).to eq(true) | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person < ActiveRecord::Base | |
validates :email_confirmation, presence: true | |
validates :name, length: { minimum: 2 } | |
validates :bio, length: { maximum: 1000, | |
too_long: "%{count} characters is the maximum allowed" } | |
end |