Permalink
Browse files

Started version 0.0.1 w/ initial commit.

  • Loading branch information...
0 parents commit 7d346e05ae52b0850de0d833285c416e7a8acac9 @panthomakos committed Dec 3, 2010
Showing with 148 additions and 0 deletions.
  1. +2 −0 .document
  2. +5 −0 .gitignore
  3. +4 −0 Gemfile
  4. +19 −0 License.txt
  5. 0 README.markdown
  6. +2 −0 Rakefile
  7. +90 −0 lib/sham.rb
  8. +3 −0 lib/sham/version.rb
  9. +23 −0 sham.gemspec
@@ -0,0 +1,2 @@
+README.markdown
+License.txt
@@ -0,0 +1,5 @@
+pkg/*
+*.gem
+.bundle
+Gemfile.lock
+doc
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in sham.gemspec
+gemspec
@@ -0,0 +1,19 @@
+Copyright (c) 2010 Panayiotis Thomakos
+
+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.
No changes.
@@ -0,0 +1,2 @@
+require 'bundler'
+Bundler::GemHelper.install_tasks
@@ -0,0 +1,90 @@
+module Sham
+ class Core
+ def self.options
+ {}
+ end
+ end
+
+ class Config
+ @@enabled = false
+
+ def self.enable!
+ @@enabled = true
+ end
+
+ def self.enabled?
+ !!@@enabled
+ end
+
+ def self.activate!
+ Sham.constants.each do |klass|
+ matcher = klass.match(/(.*)Sham/)
+ matcher[1].constantize.send(:include, Sham::Methods) unless matcher.blank?
+ end
+ end
+ end
+
+ class Base
+ attr_accessor :klass, :options
+
+ def initialize klass, options = {}
+ @klass = klass
+ @options = options
+ end
+
+ def sham!
+ @klass.sham! @options
+ end
+ end
+
+ def self.string!
+ ActiveSupport::SecureRandom.hex(5)
+ end
+
+ def self.parse! value
+ if value.is_a?(Array)
+ value.map{ |k| parse! k }
+ elsif value.is_a?(Hash)
+ Hash.new value.map{ |k,v| [k, parse!(v)] }
+ elsif value.is_a?(Sham::Base)
+ value.sham!
+ else
+ value
+ end
+ end
+
+ def self.add_options! klass, options = {}, options_string = "options"
+ eval("Sham::#{klass}Sham.#{options_string}").each do |key, value|
+ options[key] = Sham.parse!(value) unless options.has_key?(key)
+ end
+ end
+
+ module Methods
+ def self.included klass
+ klass.class_eval do
+ def self.sham! *args
+ options = (args.extract_options! || {})
+ Sham.add_options! self.name, options
+ klass = (options.delete(:type) || self.name).constantize
+ return klass.create(options) unless args[0] == :build
+ return klass.new(options)
+ end
+
+ def self.sham_alternate! type, *args
+ options = (args.extract_options! || {})
+ Sham.add_options! self.name, options, "self.#{type}_options"
+ klass = (options.delete(:type) || self.name).constantize
+ return klass.create(options) unless args[0] == :build
+ return klass.new(options)
+ end
+ end
+ end
+ end
+end
+
+Sham::Config.enable!
+
+if Sham::Config.enabled?
+ Dir["#{RAILS_ROOT}/sham/*_sham.rb"].each{ |f| require f }
+ Sham::Config.activate!
+end
@@ -0,0 +1,3 @@
+module Sham
+ VERSION = "0.0.1"
+end
@@ -0,0 +1,23 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "sham/version"
+
+Gem::Specification.new do |s|
+ s.name = "sham"
+ s.version = Sham::VERSION
+ s.platform = Gem::Platform::RUBY
+ s.authors = ["Pan Thomakos"]
+ s.email = ["pan.thomakos@gmail.com"]
+ s.homepage = "http://rubygems.org/gems/sham"
+ s.summary = "sham-#{Sham::VERSION}"
+ s.description = %q{Flexible factories for Ruby on Rails testing.}
+
+ s.rubyforge_project = "sham"
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.extra_rdoc_files = ["README.markdown"]
+ s.rdoc_options = ["--charset=UTF-8"]
+ s.require_paths = ["lib"]
+end

0 comments on commit 7d346e0

Please sign in to comment.