Skip to content

Commit

Permalink
initial import
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Hunter committed Sep 18, 2008
0 parents commit 9077d69
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 0 deletions.
20 changes: 20 additions & 0 deletions MIT-LICENSE
@@ -0,0 +1,20 @@
Copyright (c) 2008 [name of plugin creator]

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
13 changes: 13 additions & 0 deletions README
@@ -0,0 +1,13 @@
Spark
=======

Introduction goes here.


Example
=======

Example goes here.


Copyright (c) 2008 [name of plugin creator], released under the MIT license
22 changes: 22 additions & 0 deletions Rakefile
@@ -0,0 +1,22 @@
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'

desc 'Default: run unit tests.'
task :default => :test

desc 'Test the spark plugin.'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.pattern = 'test/**/*_test.rb'
t.verbose = true
end

desc 'Generate documentation for the spark plugin.'
Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'Spark'
rdoc.options << '--line-numbers' << '--inline-source'
rdoc.rdoc_files.include('README')
rdoc.rdoc_files.include('lib/**/*.rb')
end
1 change: 1 addition & 0 deletions init.rb
@@ -0,0 +1 @@
require 'spark'
1 change: 1 addition & 0 deletions install.rb
@@ -0,0 +1 @@
# Install hook code here
28 changes: 28 additions & 0 deletions lib/spark.rb
@@ -0,0 +1,28 @@
module Spark
module Mixin
def random_paragraph(count=5,min_sentences=1,max_sentences=5,min_words=3,max_words=10)
sentences = (1..count).inject([]) {|a,_ignore| a << random_sentence(rand(max_sentences)+min_sentences+1,min_words,max_words)}
sentences.join('. ')
end

def random_sentence(count=5,min_words=3,max_words=10)
words = (1..count).inject([]) {|a,_ignore| a << random_word(rand(max_words-min_words+1)+min_words)}
words.join(' ')
end

def random_word(length=6)
chars = 'abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ23456789'
text = ''
length.downto(1) { |i| text << chars[rand(chars.length - 1)].chr }
text
end

def random_email
"#{random_word}@#{random_word}.#{['com','net','org'][rand(3)]}"
end

def random_url
"http://www.google.com/search?source=ig&hl=en&rlz=&=&q=#{random_word}&btnG=Google+Search"
end
end
end
33 changes: 33 additions & 0 deletions tasks/spark_tasks.rake
@@ -0,0 +1,33 @@
SPARK_ROOT = File.join(RAILS_ROOT, "db/spark")
GROUP = ENV['group'] || RAILS_ENV

namespace :db do

desc "Loads spark fixtures then runs spark scripts"
task :spark => ['db:spark:fixtures','db:spark:scripts']

namespace :spark do

desc "Loads all fixtures in db/spark/fixtures"
task :fixtures => [:environment,'db:reset'] do
require 'active_record/fixtures'
ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
SPARK_FIXTURES_ROOT = File.join(SPARK_ROOT,GROUP,'fixtures')
Dir.glob(File.join(SPARK_FIXTURES_ROOT,'*.yml')).each do |file|
file_name = File.basename(file, '.*')
count = begin
res = Fixtures.create_fixtures(SPARK_FIXTURES_ROOT,file_name)
res.size rescue 1 # 1 for the case where the res is the sole record inserted, not a list
end
puts "Loaded #{count} into #{file_name.camelcase}"
end
end

desc 'Runs all spark scripts in db/spark/#{group || RAILS_ENV}/scripts'
task :scripts => [:environment,'db:reset'] do
include Spark::Mixin
Dir.glob(File.join(RAILS_ROOT, "db/spark/#{GROUP}/scripts", '*.{rb}')).each { |script_file| require script_file }
end

end
end
8 changes: 8 additions & 0 deletions test/spark_test.rb
@@ -0,0 +1,8 @@
require 'test/unit'

class ArsenalTest < Test::Unit::TestCase
# Replace this with your real tests.
def test_this_plugin
flunk
end
end

0 comments on commit 9077d69

Please sign in to comment.