sham 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.document ADDED
@@ -0,0 +1,2 @@
1
+ README.markdown
2
+ License.txt
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
4
+ Gemfile.lock
5
+ doc
data/Gemfile ADDED
@@ -0,0 +1 @@
1
+ source "http://rubygems.org"
data/License.txt ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2010 Panayiotis Thomakos
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.markdown ADDED
File without changes
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/lib/sham.rb ADDED
@@ -0,0 +1,90 @@
1
+ module Sham
2
+ class Core
3
+ def self.options
4
+ {}
5
+ end
6
+ end
7
+
8
+ class Config
9
+ @@enabled = false
10
+
11
+ def self.enable!
12
+ @@enabled = true
13
+ end
14
+
15
+ def self.enabled?
16
+ !!@@enabled
17
+ end
18
+
19
+ def self.activate!
20
+ Sham.constants.each do |klass|
21
+ matcher = klass.match(/(.*)Sham/)
22
+ matcher[1].constantize.send(:include, Sham::Methods) unless matcher.blank?
23
+ end
24
+ end
25
+ end
26
+
27
+ class Base
28
+ attr_accessor :klass, :options
29
+
30
+ def initialize klass, options = {}
31
+ @klass = klass
32
+ @options = options
33
+ end
34
+
35
+ def sham!
36
+ @klass.sham! @options
37
+ end
38
+ end
39
+
40
+ def self.string!
41
+ ActiveSupport::SecureRandom.hex(5)
42
+ end
43
+
44
+ def self.parse! value
45
+ if value.is_a?(Array)
46
+ value.map{ |k| parse! k }
47
+ elsif value.is_a?(Hash)
48
+ Hash.new value.map{ |k,v| [k, parse!(v)] }
49
+ elsif value.is_a?(Sham::Base)
50
+ value.sham!
51
+ else
52
+ value
53
+ end
54
+ end
55
+
56
+ def self.add_options! klass, options = {}, options_string = "options"
57
+ eval("Sham::#{klass}Sham.#{options_string}").each do |key, value|
58
+ options[key] = Sham.parse!(value) unless options.has_key?(key)
59
+ end
60
+ end
61
+
62
+ module Methods
63
+ def self.included klass
64
+ klass.class_eval do
65
+ def self.sham! *args
66
+ options = (args.extract_options! || {})
67
+ Sham.add_options! self.name, options
68
+ klass = (options.delete(:type) || self.name).constantize
69
+ return klass.create(options) unless args[0] == :build
70
+ return klass.new(options)
71
+ end
72
+
73
+ def self.sham_alternate! type, *args
74
+ options = (args.extract_options! || {})
75
+ Sham.add_options! self.name, options, "self.#{type}_options"
76
+ klass = (options.delete(:type) || self.name).constantize
77
+ return klass.create(options) unless args[0] == :build
78
+ return klass.new(options)
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
84
+
85
+ Sham::Config.enable!
86
+
87
+ if Sham::Config.enabled?
88
+ Dir["#{RAILS_ROOT}/sham/*_sham.rb"].each{ |f| require f }
89
+ Sham::Config.activate!
90
+ end
@@ -0,0 +1,3 @@
1
+ module Sham
2
+ VERSION = "0.0.1"
3
+ end
data/sham.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "sham/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "sham"
7
+ s.version = Sham::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Pan Thomakos"]
10
+ s.email = ["pan.thomakos@gmail.com"]
11
+ s.homepage = "http://rubygems.org/gems/sham"
12
+ s.summary = "sham-#{Sham::VERSION}"
13
+ s.description = %q{Flexible factories for Ruby on Rails testing.}
14
+
15
+ s.rubyforge_project = "sham"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.extra_rdoc_files = ["README.markdown"]
21
+ s.rdoc_options = ["--charset=UTF-8"]
22
+ s.require_paths = ["lib"]
23
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sham
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Pan Thomakos
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-12-03 00:00:00 -08:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Flexible factories for Ruby on Rails testing.
23
+ email:
24
+ - pan.thomakos@gmail.com
25
+ executables: []
26
+
27
+ extensions: []
28
+
29
+ extra_rdoc_files:
30
+ - README.markdown
31
+ files:
32
+ - .document
33
+ - .gitignore
34
+ - Gemfile
35
+ - License.txt
36
+ - README.markdown
37
+ - Rakefile
38
+ - lib/sham.rb
39
+ - lib/sham/version.rb
40
+ - sham.gemspec
41
+ has_rdoc: true
42
+ homepage: http://rubygems.org/gems/sham
43
+ licenses: []
44
+
45
+ post_install_message:
46
+ rdoc_options:
47
+ - --charset=UTF-8
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ hash: 3
56
+ segments:
57
+ - 0
58
+ version: "0"
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ hash: 3
65
+ segments:
66
+ - 0
67
+ version: "0"
68
+ requirements: []
69
+
70
+ rubyforge_project: sham
71
+ rubygems_version: 1.3.7
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: sham-0.0.1
75
+ test_files: []
76
+