Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added task.rb and singleton logger

  • Loading branch information...
commit ddbfc27399d5156ff2bb51f712b916f0b5dd5c8e 1 parent 35d9817
@mynameisrufus mynameisrufus authored
View
1  .gitignore
@@ -21,3 +21,4 @@ pkg/*
## PROJECT::SPECIFIC
config/database.example.yml
log/
+views/
View
60 Gemfile.lock
@@ -0,0 +1,60 @@
+PATH
+ remote: .
+ specs:
+ cassify (0.0.1)
+ activerecord (>= 3.0.0)
+ activesupport (>= 3.0.0)
+ builder
+ crypt-isaac
+ devise
+ pg
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ activemodel (3.0.3)
+ activesupport (= 3.0.3)
+ builder (~> 2.1.2)
+ i18n (~> 0.4)
+ activerecord (3.0.3)
+ activemodel (= 3.0.3)
+ activesupport (= 3.0.3)
+ arel (~> 2.0.2)
+ tzinfo (~> 0.3.23)
+ activesupport (3.0.3)
+ arel (2.0.7)
+ bcrypt-ruby (2.1.4)
+ builder (2.1.2)
+ crypt-isaac (0.9.1)
+ devise (1.1.5)
+ bcrypt-ruby (~> 2.1.2)
+ warden (~> 1.0.2)
+ diff-lcs (1.1.2)
+ i18n (0.5.0)
+ pg (0.10.1)
+ rack (1.2.1)
+ rspec (2.3.0)
+ rspec-core (~> 2.3.0)
+ rspec-expectations (~> 2.3.0)
+ rspec-mocks (~> 2.3.0)
+ rspec-core (2.3.1)
+ rspec-expectations (2.3.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.3.0)
+ tzinfo (0.3.24)
+ warden (1.0.3)
+ rack (>= 1.0.0)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ activerecord (>= 3.0.0)
+ activesupport (>= 3.0.0)
+ builder
+ bundler (>= 1.0.0)
+ cassify!
+ crypt-isaac
+ devise
+ pg
+ rspec (>= 2.0.0)
View
3  README.markdown
@@ -10,3 +10,6 @@ Not working
* make it work with a separate database if specified
* plug-in authenticator architecture
+## Spec
+
+[http://www.jasig.org/cas/protocol](CAS Spec)
View
23 Rakefile
@@ -1,3 +1,24 @@
+$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
+
+require 'cassify/tasks'
require 'bundler'
Bundler::GemHelper.install_tasks
-Dir['tasks/**/*.rake'].each { |rake| load rake }
+
+require 'rspec/core/rake_task'
+desc 'Run Cassify unit tests.'
+RSpec::Core::RakeTask.new('spec') do |t|
+ t.rspec_opts = ['--colour', '--format nested']
+ t.pattern = 'spec/**/*_spec.rb'
+end
+
+namespace :cassify do
+ desc 'run CAS migrations'
+ task 'migrate' do
+ Cassify::Tasks.migrate
+ end
+
+ desc 'install cas views'
+ task 'sinatra' do
+ Cassify::Tasks.install_views("views")
+ end
+end
View
7 lib/cassify.rb
@@ -1,7 +1,14 @@
+require 'active_record'
+require 'logger'
+require 'fileutils'
+
require 'cassify/cas'
require 'cassify/model'
require 'cassify/utils'
+require 'cassify/logger'
module Cassify
# Your code goes here...
end
+
+Logger.new(ENV['CAS_ENV'] || "test")
View
24 lib/cassify/logger.rb
@@ -0,0 +1,24 @@
+module Cassify
+ class Logger
+ include Singleton
+
+ def intialize(env)
+ FileUtils.mkdir_p log_dir
+ @logfile = File.join(log_dir, "#{env}.log")
+ @log = Logger.new @logfile
+ end
+
+ def self.logfile
+ @logfile
+ end
+
+ def self.log
+ @log
+ end
+
+ private
+ def log_dir
+ File.join(Dir.pwd, 'log')
+ end
+ end
+end
View
34 lib/cassify/tasks.rb
@@ -0,0 +1,34 @@
+require 'cassify'
+
+module Cassify
+ class Tasks
+ class << self
+ def migrate
+ database_config = File.join('config', 'database.yml')
+
+ unless File.exists? database_config
+ raise "config/database.yml could not be found"
+ end
+
+ begin
+ cas_database_config = YAML.load_file(database_config)
+ ActiveRecord::Base.establish_connection(cas_database_config.fetch(ENV['CAS_ENV']))
+ ActiveRecord::Base.logger = Cassify::Logger.log
+ ActiveRecord::Migration.verbose = true
+ ActiveRecord::Migrator.migrate("db/migrate")
+ rescue Exception => e
+ STDERR.puts e
+ STDERR.puts "do you have a cas database group in your database.yml and specified CAS_ENV?"
+ end
+ end
+
+ def install_views(view_path)
+ source = File.join(File.dirname(__FILE__), 'views')
+ destination = File.join(Dir.pwd, view_path)
+ STDERR.puts "\ncopying views from: #{source} to: #{destination}.....\n\n"
+ FileUtils.cp_r source, destination
+ STDERR.puts "done\n"
+ end
+ end
+ end
+end
View
3  spec/spec_helper.rb
@@ -10,10 +10,7 @@
require 'rspec/autorun'
require 'cassify'
-$LOG = Logger.new(STDOUT)
ActiveRecord::Base.configurations = YAML.load_file(File.join("config", "database.yml"))
ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations.fetch(ENV['CAS_ENV']))
-FileUtils.mkdir_p "#{Dir.pwd}/log"
-logfile = "#{Dir.pwd}/log/database.log"
ActiveRecord::Base.logger = Logger.new(File.open(logfile, 'w'))
View
16 tasks/migrate.rake
@@ -1,16 +0,0 @@
-require 'active_record'
-require 'fileutils'
-require 'logger'
-
-namespace :db do
- desc "run CAS migrations"
- task :migrate do |t|
- ActiveRecord::Base.configurations = YAML.load_file(File.join(ENV['DATABASE_CONFIG'], "database.yml"))
- ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations.fetch(ENV['CAS_ENV']))
-
- logfile = "#{Dir.pwd}/log/cas.log"
- ActiveRecord::Base.logger = Logger.new(File.open(logfile, 'w'))
- ActiveRecord::Migration.verbose = true
- ActiveRecord::Migrator.migrate("db/migrate")
- end
-end
View
10 tasks/spec.rake
@@ -1,10 +0,0 @@
-#begin
- require 'rspec/core/rake_task'
- desc 'Run RSpecs to confirm that all functionality is working as expected'
- RSpec::Core::RakeTask.new('spec') do |t|
- t.rspec_opts = ['--colour', '--format nested']
- t.pattern = 'spec/**/*_spec.rb'
- end
-#rescue LoadError
-# puts "Hiding spec tasks because RSpec is not available"
-#end
Please sign in to comment.
Something went wrong with that request. Please try again.