Module: Imposter

Defined in:
lib/imposter/version.rb,
lib/imposter.rb,
lib/imposter/csz.rb,
lib/imposter/noun.rb,
lib/imposter/verb.rb,
lib/imposter/phone.rb,
lib/imposter/animal.rb,
lib/imposter/mineral.rb,
lib/imposter/vegetable.rb,
lib/generators/imposter.rb,
lib/generators/imposter/install/install_generator.rb,
lib/generators/imposter/gen_models/gen_models_generator.rb

Overview

:nodoc:

Defined Under Namespace

Modules: Generators, VERSION Classes: Animal, CSZ, Mineral, Noun, Phone, Street, Vegetable, Verb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.email_addressObject



95
96
97
# File 'lib/imposter.rb', line 95

def self.email_address
  Faker::Internet.email()
end

.gencsv(filename, cnt, fields, values) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/imposter.rb', line 25

def self.gencsv(filename,cnt,fields,values)
	vl = values	
	l = Array.new
	m = Array.new(cnt,0)
	CSV.open(filename,"w") do |csv|
		csv << fields
		begin
		(1..cnt).each do |i|
			vl.each do |v|
				begin 
					l << eval(v)
				rescue
					puts "Error evaluating " + v.to_s + " in " + filename
				end
			end
			m[i,0] = l
			csv << l
			l.clear
		end
		rescue
			puts "Some format/data error in  " + filename
		end
	end
	return m
end

.genimpostersObject



77
78
79
80
81
82
83
# File 'lib/imposter.rb', line 77

def self.genimposters
	models_dir = Dir.glob(Rails.root.join('test', 'imposter').to_s + "/*.yml")
	models_dir.each do |imposter_yaml|
		getfixtures #reloading each time to get model level data		
		parseyaml(imposter_yaml)
	end	
end

.getfixturesObject



51
52
53
54
55
56
57
58
59
60
# File 'lib/imposter.rb', line 51

def self.getfixtures
	fixtures_dir = Dir.glob("test/fixtures/*.csv")
	#Loading existing CSV structures
	if not fixtures_dir.empty? then
		fixtures_dir.each do |fixture_csv|
			fn = Pathname.new(fixture_csv).basename.to_s.chomp(File.extname(fixture_csv))
			eval("@" + fn + "= CSV.open(fixture_csv,'r').to_a  rescue nil") 
		end	
	end
end

.letterify(letter_string) ⇒ Object



103
104
105
# File 'lib/imposter.rb', line 103

def self.letterify(letter_string)
	letter_string.gsub(/\?/) { ('a'..'z').to_a.rand }
end

.numerify(number_string) ⇒ Object



99
100
101
# File 'lib/imposter.rb', line 99

def self.numerify(number_string)
	number_string.gsub(/#/) { rand(10).to_s }
end

.parseyaml(yamlfilename) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/imposter.rb', line 62

def self.parseyaml(yamlfilename)
	imp_yaml = YAML.load(File.read(yamlfilename))
	mn = imp_yaml.first[0]
	imp_values = imp_yaml[mn]["fields"].values
	imp_fields = imp_yaml[mn]["fields"].keys
	imp_qty = imp_yaml[mn]["quantity"]
	rl = gencsv("test/fixtures/" + mn.pluralize + ".csv",imp_qty,imp_fields, imp_values) 
	eval("@" + mn.pluralize + "= rl")
	yml_fixture_filename = "test/fixtures/#{mn.pluralize}.yml"
	if File.exists?(yml_fixture_filename)
	  puts " ** Deleting YAML fixture file #{yml_fixture_filename}"
	  File.delete(yml_fixture_filename)
  end 
end

.pattern(string) ⇒ Object



107
108
109
# File 'lib/imposter.rb', line 107

def self.pattern(string)
	self.letterify(self.numerify(string))
end

.urlifyObject



91
92
93
# File 'lib/imposter.rb', line 91

def self.urlify
  ('http://www.' + Faker::Internet.domain_name).to_s.downcase
end

Instance Method Details

#announce(message) ⇒ Object



85
86
87
88
89
# File 'lib/imposter.rb', line 85

def announce(message)
  text = "#{@version} #{name}: #{message}"
  length = [0, 75 - text.length].max
  write "== %s %s" % [text, "=" * length]
end