From c40583eccc91c86c78d57a82f681155c73a3f27c Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Tue, 29 Dec 2015 17:41:41 +0000 Subject: [PATCH] Initial files --- .gitignore | 31 +++++++++++++++++++++++++++++++ Gemfile | 13 +++++++++++++ app.rb | 22 ++++++++++++++++++++++ helpers.rb | 15 +++++++++++++++ rakefile | 8 ++++++++ 5 files changed, 89 insertions(+) create mode 100644 .gitignore create mode 100644 Gemfile create mode 100644 app.rb create mode 100644 helpers.rb create mode 100644 rakefile diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a28186a --- /dev/null +++ b/.gitignore @@ -0,0 +1,31 @@ +*.gem +*.rbc +/.config +/coverage/ +/InstalledFiles +/pkg/ +/spec/reports/ +/spec/examples.txt +/test/tmp/ +/test/version_tmp/ +/tmp/ + +## Documentation cache and generated files: +/.yardoc/ +/_yardoc/ +/doc/ +/rdoc/ + +## Environment normalization: +/.bundle/ +/vendor/bundle +/lib/bundler/man/ + +# for a library or gem, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +Gemfile.lock +.ruby-version +.ruby-gemset + +# unless supporting rvm < 1.11.0 or doing something fancy, ignore this: +.rvmrc diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..92c908e --- /dev/null +++ b/Gemfile @@ -0,0 +1,13 @@ +# A sample Gemfile +source "https://rubygems.org" + +gem 'sinatra' +gem 'rake' + +group :test, :development do + gem 'rspec' +end + +group :test do + gem 'rack-test' +end \ No newline at end of file diff --git a/app.rb b/app.rb new file mode 100644 index 0000000..9485a28 --- /dev/null +++ b/app.rb @@ -0,0 +1,22 @@ +# app.rb +ENV['RACK_ENV'] ||= 'development' + +require 'bundler' +Bundler.require :default, ENV['RACK_ENV'].to_sym + +require_relative 'helpers' +# require_relative 'routes/secrets' +# require_relative 'routes/sessions' + +class SimpleApp < Sinatra::Base + + set :root, File.dirname(__FILE__) + + enable :sessions + + helpers Sinatra::SampleApp::Helpers + + # register Sinatra::SampleApp::Routing::Sessions + # register Sinatra::SampleApp::Routing::Secrets + +end diff --git a/helpers.rb b/helpers.rb new file mode 100644 index 0000000..a0de50d --- /dev/null +++ b/helpers.rb @@ -0,0 +1,15 @@ +module Sinatra + module SampleApp + module Helpers + + def require_logged_in + redirect('/sessions/new') unless is_authenticated? + end + + def is_authenticated? + return !!session[:user_id] + end + + end + end +end diff --git a/rakefile b/rakefile new file mode 100644 index 0000000..89a8265 --- /dev/null +++ b/rakefile @@ -0,0 +1,8 @@ +# rakefile +require 'rspec/core/rake_task' + +RSpec::Core::RakeTask.new :specs do |task| + task.pattern = Dir['spec/**/*_spec.rb'] +end + +task :default => ['specs'] -- 2.34.1