garcun 0.0.2
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.
- checksums.yaml +7 -0
- data/.gitattributes +17 -0
- data/.gitignore +197 -0
- data/.rspec +2 -0
- data/Gemfile +22 -0
- data/LICENSE +201 -0
- data/README.md +521 -0
- data/Rakefile +47 -0
- data/garcun.gemspec +83 -0
- data/lib/garcon.rb +290 -0
- data/lib/garcon/chef/chef_helpers.rb +343 -0
- data/lib/garcon/chef/coerce/coercer.rb +134 -0
- data/lib/garcon/chef/coerce/coercions/boolean_definitions.rb +34 -0
- data/lib/garcon/chef/coerce/coercions/date_definitions.rb +32 -0
- data/lib/garcon/chef/coerce/coercions/date_time_definitions.rb +32 -0
- data/lib/garcon/chef/coerce/coercions/fixnum_definitions.rb +34 -0
- data/lib/garcon/chef/coerce/coercions/float_definitions.rb +32 -0
- data/lib/garcon/chef/coerce/coercions/hash_definitions.rb +29 -0
- data/lib/garcon/chef/coerce/coercions/integer_definitions.rb +31 -0
- data/lib/garcon/chef/coerce/coercions/string_definitions.rb +45 -0
- data/lib/garcon/chef/coerce/coercions/time_definitions.rb +32 -0
- data/lib/garcon/chef/handler/devreporter.rb +127 -0
- data/lib/garcon/chef/log.rb +64 -0
- data/lib/garcon/chef/node.rb +100 -0
- data/lib/garcon/chef/provider/civilize.rb +209 -0
- data/lib/garcon/chef/provider/development.rb +159 -0
- data/lib/garcon/chef/provider/download.rb +420 -0
- data/lib/garcon/chef/provider/house_keeping.rb +265 -0
- data/lib/garcon/chef/provider/node_cache.rb +31 -0
- data/lib/garcon/chef/provider/partial.rb +183 -0
- data/lib/garcon/chef/provider/recovery.rb +80 -0
- data/lib/garcon/chef/provider/zip_file.rb +271 -0
- data/lib/garcon/chef/resource/attribute.rb +52 -0
- data/lib/garcon/chef/resource/base_dsl.rb +174 -0
- data/lib/garcon/chef/resource/blender.rb +140 -0
- data/lib/garcon/chef/resource/lazy_eval.rb +66 -0
- data/lib/garcon/chef/resource/resource_name.rb +109 -0
- data/lib/garcon/chef/secret_bag.rb +204 -0
- data/lib/garcon/chef/validations.rb +76 -0
- data/lib/garcon/chef_inclusions.rb +151 -0
- data/lib/garcon/configuration.rb +138 -0
- data/lib/garcon/core_ext.rb +39 -0
- data/lib/garcon/core_ext/array.rb +27 -0
- data/lib/garcon/core_ext/binding.rb +64 -0
- data/lib/garcon/core_ext/boolean.rb +66 -0
- data/lib/garcon/core_ext/duration.rb +271 -0
- data/lib/garcon/core_ext/enumerable.rb +34 -0
- data/lib/garcon/core_ext/file.rb +127 -0
- data/lib/garcon/core_ext/filetest.rb +62 -0
- data/lib/garcon/core_ext/hash.rb +279 -0
- data/lib/garcon/core_ext/kernel.rb +159 -0
- data/lib/garcon/core_ext/lazy.rb +222 -0
- data/lib/garcon/core_ext/method_access.rb +243 -0
- data/lib/garcon/core_ext/module.rb +92 -0
- data/lib/garcon/core_ext/nil.rb +53 -0
- data/lib/garcon/core_ext/numeric.rb +44 -0
- data/lib/garcon/core_ext/object.rb +342 -0
- data/lib/garcon/core_ext/pathname.rb +152 -0
- data/lib/garcon/core_ext/process.rb +41 -0
- data/lib/garcon/core_ext/random.rb +497 -0
- data/lib/garcon/core_ext/string.rb +312 -0
- data/lib/garcon/core_ext/struct.rb +49 -0
- data/lib/garcon/core_ext/symbol.rb +170 -0
- data/lib/garcon/core_ext/time.rb +234 -0
- data/lib/garcon/exceptions.rb +101 -0
- data/lib/garcon/inflections.rb +237 -0
- data/lib/garcon/inflections/defaults.rb +79 -0
- data/lib/garcon/inflections/inflections.rb +182 -0
- data/lib/garcon/inflections/rules_collection.rb +37 -0
- data/lib/garcon/secret.rb +271 -0
- data/lib/garcon/stash/format.rb +114 -0
- data/lib/garcon/stash/journal.rb +226 -0
- data/lib/garcon/stash/queue.rb +83 -0
- data/lib/garcon/stash/serializer.rb +86 -0
- data/lib/garcon/stash/store.rb +435 -0
- data/lib/garcon/task.rb +31 -0
- data/lib/garcon/task/atomic.rb +151 -0
- data/lib/garcon/task/atomic_boolean.rb +127 -0
- data/lib/garcon/task/condition.rb +99 -0
- data/lib/garcon/task/copy_on_notify_observer_set.rb +154 -0
- data/lib/garcon/task/copy_on_write_observer_set.rb +153 -0
- data/lib/garcon/task/count_down_latch.rb +92 -0
- data/lib/garcon/task/delay.rb +196 -0
- data/lib/garcon/task/dereferenceable.rb +144 -0
- data/lib/garcon/task/event.rb +119 -0
- data/lib/garcon/task/executor.rb +275 -0
- data/lib/garcon/task/executor_options.rb +59 -0
- data/lib/garcon/task/future.rb +107 -0
- data/lib/garcon/task/immediate_executor.rb +84 -0
- data/lib/garcon/task/ivar.rb +171 -0
- data/lib/garcon/task/lazy_reference.rb +74 -0
- data/lib/garcon/task/monotonic_time.rb +69 -0
- data/lib/garcon/task/obligation.rb +256 -0
- data/lib/garcon/task/observable.rb +101 -0
- data/lib/garcon/task/priority_queue.rb +234 -0
- data/lib/garcon/task/processor_count.rb +128 -0
- data/lib/garcon/task/read_write_lock.rb +304 -0
- data/lib/garcon/task/safe_task_executor.rb +58 -0
- data/lib/garcon/task/single_thread_executor.rb +97 -0
- data/lib/garcon/task/thread_pool/cached.rb +71 -0
- data/lib/garcon/task/thread_pool/executor.rb +294 -0
- data/lib/garcon/task/thread_pool/fixed.rb +61 -0
- data/lib/garcon/task/thread_pool/worker.rb +90 -0
- data/lib/garcon/task/timer.rb +44 -0
- data/lib/garcon/task/timer_set.rb +194 -0
- data/lib/garcon/task/timer_task.rb +377 -0
- data/lib/garcon/task/waitable_list.rb +58 -0
- data/lib/garcon/utility/ansi.rb +199 -0
- data/lib/garcon/utility/at_random.rb +77 -0
- data/lib/garcon/utility/crypto.rb +292 -0
- data/lib/garcon/utility/equalizer.rb +146 -0
- data/lib/garcon/utility/faker/extensions/array.rb +22 -0
- data/lib/garcon/utility/faker/extensions/symbol.rb +9 -0
- data/lib/garcon/utility/faker/faker.rb +164 -0
- data/lib/garcon/utility/faker/faker/company.rb +17 -0
- data/lib/garcon/utility/faker/faker/hacker.rb +30 -0
- data/lib/garcon/utility/faker/faker/version.rb +3 -0
- data/lib/garcon/utility/faker/locales/en-US.yml +83 -0
- data/lib/garcon/utility/faker/locales/en.yml +21 -0
- data/lib/garcon/utility/file_helper.rb +170 -0
- data/lib/garcon/utility/hookers.rb +178 -0
- data/lib/garcon/utility/interpolation.rb +90 -0
- data/lib/garcon/utility/memstash.rb +364 -0
- data/lib/garcon/utility/misc.rb +54 -0
- data/lib/garcon/utility/msg_from_god.rb +62 -0
- data/lib/garcon/utility/retry.rb +238 -0
- data/lib/garcon/utility/timeout.rb +58 -0
- data/lib/garcon/utility/uber/builder.rb +91 -0
- data/lib/garcon/utility/uber/callable.rb +7 -0
- data/lib/garcon/utility/uber/delegates.rb +13 -0
- data/lib/garcon/utility/uber/inheritable_attr.rb +37 -0
- data/lib/garcon/utility/uber/options.rb +101 -0
- data/lib/garcon/utility/uber/uber_version.rb +3 -0
- data/lib/garcon/utility/uber/version.rb +33 -0
- data/lib/garcon/utility/url_helper.rb +100 -0
- data/lib/garcon/utils.rb +29 -0
- data/lib/garcon/version.rb +62 -0
- data/lib/garcun.rb +24 -0
- metadata +680 -0
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
#
|
|
3
|
+
# Author: Stefano Harding <riddopic@gmail.com>
|
|
4
|
+
# License: Apache License, Version 2.0
|
|
5
|
+
# Copyright: (C) 2014-2015 Stefano Harding
|
|
6
|
+
#
|
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
# you may not use this file except in compliance with the License.
|
|
9
|
+
# You may obtain a copy of the License at
|
|
10
|
+
#
|
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
#
|
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
# See the License for the specific language governing permissions and
|
|
17
|
+
# limitations under the License.
|
|
18
|
+
#
|
|
19
|
+
|
|
20
|
+
module Garcon
|
|
21
|
+
# Define equality, equivalence and inspection methods.
|
|
22
|
+
#
|
|
23
|
+
class Equalizer
|
|
24
|
+
|
|
25
|
+
# Initialize an Equalizer with the given keys.
|
|
26
|
+
#
|
|
27
|
+
# Will use the keys with which it is initialized to define #cmp?,
|
|
28
|
+
# #hash, and #inspect
|
|
29
|
+
#
|
|
30
|
+
# @param [String] name
|
|
31
|
+
#
|
|
32
|
+
# @param [Array<Symbol>] keys
|
|
33
|
+
#
|
|
34
|
+
# @return [undefined]
|
|
35
|
+
#
|
|
36
|
+
# @api private
|
|
37
|
+
def initialize(name, keys = [])
|
|
38
|
+
@name = name.dup.freeze
|
|
39
|
+
@keys = keys.dup
|
|
40
|
+
define_methods
|
|
41
|
+
include_comparison_methods
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Append a key and compile the equality methods.
|
|
45
|
+
#
|
|
46
|
+
# @return [Equalizer] self
|
|
47
|
+
#
|
|
48
|
+
# @api private
|
|
49
|
+
def <<(key)
|
|
50
|
+
@keys << key
|
|
51
|
+
self
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
private # P R O P R I E T À P R I V A T A Vietato L'accesso
|
|
55
|
+
|
|
56
|
+
# Define the equalizer methods based on #keys.
|
|
57
|
+
#
|
|
58
|
+
# @return [undefined]
|
|
59
|
+
#
|
|
60
|
+
# @api private
|
|
61
|
+
def define_methods
|
|
62
|
+
define_cmp_method
|
|
63
|
+
define_hash_method
|
|
64
|
+
define_inspect_method
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# Define an #cmp? method based on the instance's values identified by #keys.
|
|
68
|
+
#
|
|
69
|
+
# @return [undefined]
|
|
70
|
+
#
|
|
71
|
+
# @api private
|
|
72
|
+
def define_cmp_method
|
|
73
|
+
keys = @keys
|
|
74
|
+
define_method(:cmp?) do |comparator, other|
|
|
75
|
+
keys.all? { |key| send(key).send(comparator, other.send(key)) }
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# Define a #hash method based on the instance's values identified by #keys.
|
|
80
|
+
#
|
|
81
|
+
# @return [undefined]
|
|
82
|
+
#
|
|
83
|
+
# @api private
|
|
84
|
+
def define_hash_method
|
|
85
|
+
keys = @keys
|
|
86
|
+
define_method(:hash) do
|
|
87
|
+
keys.map { |key| send(key) }.push(self.class).hash
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# Define an inspect method that reports the values of the instance's keys.
|
|
92
|
+
#
|
|
93
|
+
# @return [undefined]
|
|
94
|
+
#
|
|
95
|
+
# @api private
|
|
96
|
+
def define_inspect_method
|
|
97
|
+
name, keys = @name, @keys
|
|
98
|
+
define_method(:inspect) do
|
|
99
|
+
"#<#{name}#{keys.map { |key| " #{key}=#{send(key).inspect}" }.join}>"
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# Include the #eql? and #== methods
|
|
104
|
+
#
|
|
105
|
+
# @return [undefined]
|
|
106
|
+
#
|
|
107
|
+
# @api private
|
|
108
|
+
def include_comparison_methods
|
|
109
|
+
module_eval { include Methods }
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
# The comparison methods
|
|
113
|
+
module Methods
|
|
114
|
+
|
|
115
|
+
# Compare the object with other object for equality.
|
|
116
|
+
#
|
|
117
|
+
# @example
|
|
118
|
+
# object.eql?(other) # => true or false
|
|
119
|
+
#
|
|
120
|
+
# @param [Object] other
|
|
121
|
+
# the other object to compare with
|
|
122
|
+
#
|
|
123
|
+
# @return [Boolean]
|
|
124
|
+
#
|
|
125
|
+
# @api public
|
|
126
|
+
def eql?(other)
|
|
127
|
+
instance_of?(other.class) && cmp?(__method__, other)
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
# Compare the object with other object for equivalency.
|
|
131
|
+
#
|
|
132
|
+
# @example
|
|
133
|
+
# object == other # => true or false
|
|
134
|
+
#
|
|
135
|
+
# @param [Object] other
|
|
136
|
+
# the other object to compare with
|
|
137
|
+
#
|
|
138
|
+
# @return [Boolean]
|
|
139
|
+
#
|
|
140
|
+
# @api public
|
|
141
|
+
def ==(other)
|
|
142
|
+
other.kind_of?(self.class) && cmp?(__method__, other)
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
class Array
|
|
2
|
+
unless self.method_defined? :sample
|
|
3
|
+
def sample(n = nil)
|
|
4
|
+
#based on code from https://github.com/marcandre/backports
|
|
5
|
+
size = self.length
|
|
6
|
+
return self[Kernel.rand(size)] if n.nil?
|
|
7
|
+
|
|
8
|
+
n = n.to_int
|
|
9
|
+
raise ArgumentError, "negative array size" if n < 0
|
|
10
|
+
|
|
11
|
+
n = size if n > size
|
|
12
|
+
|
|
13
|
+
result = Array.new(self)
|
|
14
|
+
n.times do |i|
|
|
15
|
+
r = i + Kernel.rand(size - i)
|
|
16
|
+
result[i], result[r] = result[r], result[i]
|
|
17
|
+
end
|
|
18
|
+
result[n..size] = []
|
|
19
|
+
result
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
mydir = File.expand_path(File.dirname(__FILE__))
|
|
3
|
+
|
|
4
|
+
begin
|
|
5
|
+
require 'psych'
|
|
6
|
+
rescue LoadError
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
require 'i18n'
|
|
10
|
+
require 'set' # Fixes a bug in i18n 0.6.11
|
|
11
|
+
|
|
12
|
+
if I18n.respond_to?(:enforce_available_locales=)
|
|
13
|
+
I18n.enforce_available_locales = true
|
|
14
|
+
end
|
|
15
|
+
I18n.load_path += Dir[File.join(mydir, 'locales', '*.yml')]
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
module Faker
|
|
19
|
+
class Config
|
|
20
|
+
@locale = nil
|
|
21
|
+
|
|
22
|
+
class << self
|
|
23
|
+
attr_writer :locale
|
|
24
|
+
def locale
|
|
25
|
+
@locale || I18n.locale
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
class Base
|
|
31
|
+
Numbers = Array(0..9)
|
|
32
|
+
ULetters = Array('A'..'Z')
|
|
33
|
+
Letters = ULetters + Array('a'..'z')
|
|
34
|
+
|
|
35
|
+
class << self
|
|
36
|
+
## make sure numerify results doesn’t start with a zero
|
|
37
|
+
def numerify(number_string)
|
|
38
|
+
number_string.sub(/#/) { (rand(9)+1).to_s }.gsub(/#/) { rand(10).to_s }
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def letterify(letter_string)
|
|
42
|
+
letter_string.gsub(/\?/) { ULetters.sample }
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def bothify(string)
|
|
46
|
+
letterify(numerify(string))
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Given a regular expression, attempt to generate a string
|
|
50
|
+
# that would match it. This is a rather simple implementation,
|
|
51
|
+
# so don't be shocked if it blows up on you in a spectacular fashion.
|
|
52
|
+
#
|
|
53
|
+
# It does not handle ., *, unbounded ranges such as {1,},
|
|
54
|
+
# extensions such as (?=), character classes, some abbreviations
|
|
55
|
+
# for character classes, and nested parentheses.
|
|
56
|
+
#
|
|
57
|
+
# I told you it was simple. :) It's also probably dog-slow,
|
|
58
|
+
# so you shouldn't use it.
|
|
59
|
+
#
|
|
60
|
+
# It will take a regex like this:
|
|
61
|
+
#
|
|
62
|
+
# /^[A-PR-UWYZ0-9][A-HK-Y0-9][AEHMNPRTVXY0-9]?[ABEHMNPRVWXY0-9]? {1,2}[0-9][ABD-HJLN-UW-Z]{2}$/
|
|
63
|
+
#
|
|
64
|
+
# and generate a string like this:
|
|
65
|
+
#
|
|
66
|
+
# "U3V 3TP"
|
|
67
|
+
#
|
|
68
|
+
def regexify(re)
|
|
69
|
+
re = re.source if re.respond_to?(:source) # Handle either a Regexp or a String that looks like a Regexp
|
|
70
|
+
re.
|
|
71
|
+
gsub(/^\/?\^?/, '').gsub(/\$?\/?$/, ''). # Ditch the anchors
|
|
72
|
+
gsub(/\{(\d+)\}/, '{\1,\1}').gsub(/\?/, '{0,1}'). # All {2} become {2,2} and ? become {0,1}
|
|
73
|
+
gsub(/(\[[^\]]+\])\{(\d+),(\d+)\}/) {|match| $1 * Array(Range.new($2.to_i, $3.to_i)).sample }. # [12]{1,2} becomes [12] or [12][12]
|
|
74
|
+
gsub(/(\([^\)]+\))\{(\d+),(\d+)\}/) {|match| $1 * Array(Range.new($2.to_i, $3.to_i)).sample }. # (12|34){1,2} becomes (12|34) or (12|34)(12|34)
|
|
75
|
+
gsub(/(\\?.)\{(\d+),(\d+)\}/) {|match| $1 * Array(Range.new($2.to_i, $3.to_i)).sample }. # A{1,2} becomes A or AA or \d{3} becomes \d\d\d
|
|
76
|
+
gsub(/\((.*?)\)/) {|match| match.gsub(/[\(\)]/, '').split('|').sample }. # (this|that) becomes 'this' or 'that'
|
|
77
|
+
gsub(/\[([^\]]+)\]/) {|match| match.gsub(/(\w\-\w)/) {|range| Array(Range.new(*range.split('-'))).sample } }. # All A-Z inside of [] become C (or X, or whatever)
|
|
78
|
+
gsub(/\[([^\]]+)\]/) {|match| $1.split('').sample }. # All [ABC] become B (or A or C)
|
|
79
|
+
gsub('\d') {|match| Numbers.sample }.
|
|
80
|
+
gsub('\w') {|match| Letters.sample }
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# Helper for the common approach of grabbing a translation
|
|
84
|
+
# with an array of values and selecting one of them.
|
|
85
|
+
def fetch(key)
|
|
86
|
+
fetched = translate("faker.#{key}")
|
|
87
|
+
fetched = fetched.sample if fetched.respond_to?(:sample)
|
|
88
|
+
if fetched.match(/^\//) and fetched.match(/\/$/) # A regex
|
|
89
|
+
regexify(fetched)
|
|
90
|
+
else
|
|
91
|
+
fetched
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# Load formatted strings from the locale, "parsing" them
|
|
96
|
+
# into method calls that can be used to generate a
|
|
97
|
+
# formatted translation: e.g., "#{first_name} #{last_name}".
|
|
98
|
+
def parse(key)
|
|
99
|
+
fetch(key).scan(/(\(?)#\{([A-Za-z]+\.)?([^\}]+)\}([^#]+)?/).map {|prefix, kls, meth, etc|
|
|
100
|
+
# If the token had a class Prefix (e.g., Name.first_name)
|
|
101
|
+
# grab the constant, otherwise use self
|
|
102
|
+
cls = kls ? Faker.const_get(kls.chop) : self
|
|
103
|
+
|
|
104
|
+
# If an optional leading parentheses is not present, prefix.should == "", otherwise prefix.should == "("
|
|
105
|
+
# In either case the information will be retained for reconstruction of the string.
|
|
106
|
+
text = prefix
|
|
107
|
+
|
|
108
|
+
# If the class has the method, call it, otherwise
|
|
109
|
+
# fetch the transation (i.e., faker.name.first_name)
|
|
110
|
+
text += cls.respond_to?(meth) ? cls.send(meth) : fetch("#{(kls || self).to_s.split('::').last.downcase}.#{meth.downcase}")
|
|
111
|
+
|
|
112
|
+
# And tack on spaces, commas, etc. left over in the string
|
|
113
|
+
text += etc.to_s
|
|
114
|
+
}.join
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# Call I18n.translate with our configured locale if no
|
|
118
|
+
# locale is specified
|
|
119
|
+
def translate(*args)
|
|
120
|
+
opts = args.last.is_a?(Hash) ? args.pop : {}
|
|
121
|
+
opts[:locale] ||= Faker::Config.locale
|
|
122
|
+
opts[:raise] = true
|
|
123
|
+
I18n.translate(*(args.push(opts)))
|
|
124
|
+
rescue I18n::MissingTranslationData
|
|
125
|
+
# Super-simple fallback -- fallback to en if the
|
|
126
|
+
# translation was missing. If the translation isn't
|
|
127
|
+
# in en either, then it will raise again.
|
|
128
|
+
I18n.translate(*(args.push(opts.merge(:locale => :en))))
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def flexible(key)
|
|
132
|
+
@flexible_key = key
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
# You can add whatever you want to the locale file, and it will get caught here.
|
|
136
|
+
# E.g., in your locale file, create a
|
|
137
|
+
# name:
|
|
138
|
+
# girls_name: ["Alice", "Cheryl", "Tatiana"]
|
|
139
|
+
# Then you can call Faker::Name.girls_name and it will act like #first_name
|
|
140
|
+
def method_missing(m, *args, &block)
|
|
141
|
+
super unless @flexible_key
|
|
142
|
+
|
|
143
|
+
# Use the alternate form of translate to get a nil rather than a "missing translation" string
|
|
144
|
+
if translation = translate(:faker)[@flexible_key][m]
|
|
145
|
+
translation.respond_to?(:sample) ? translation.sample : translation
|
|
146
|
+
else
|
|
147
|
+
super
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
# Generates a random value between the interval
|
|
152
|
+
def rand_in_range(from, to)
|
|
153
|
+
from, to = to, from if to < from
|
|
154
|
+
Random.new.rand(from..to)
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
require_relative 'faker/company'
|
|
161
|
+
require_relative 'faker/hacker'
|
|
162
|
+
|
|
163
|
+
require_relative 'extensions/array'
|
|
164
|
+
require_relative 'extensions/symbol'
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module Faker
|
|
2
|
+
class Company < Base
|
|
3
|
+
flexible :company
|
|
4
|
+
|
|
5
|
+
class << self
|
|
6
|
+
# Generate a buzzword-laden catch phrase.
|
|
7
|
+
def catch_phrase
|
|
8
|
+
translate('faker.company.buzzwords').collect {|list| list.sample }.join(' ')
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# When a straight answer won't do, BS to the rescue!
|
|
12
|
+
def bs
|
|
13
|
+
translate('faker.company.bs').collect {|list| list.sample }.join(' ')
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
|
|
2
|
+
module Faker
|
|
3
|
+
class Hacker < Base
|
|
4
|
+
flexible :hacker
|
|
5
|
+
|
|
6
|
+
class << self
|
|
7
|
+
def say_something_smart
|
|
8
|
+
phrases.sample
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def abbreviation; fetch('hacker.abbreviation'); end
|
|
12
|
+
def adjective; fetch('hacker.adjective'); end
|
|
13
|
+
def noun; fetch('hacker.noun'); end
|
|
14
|
+
def verb; fetch('hacker.verb'); end
|
|
15
|
+
def ingverb; fetch('hacker.ingverb'); end
|
|
16
|
+
|
|
17
|
+
def phrases
|
|
18
|
+
[ "If we #{verb} the #{noun}, we can get to the #{abbreviation} #{noun} through the #{adjective} #{abbreviation} #{noun}!",
|
|
19
|
+
"We need to #{verb} the #{adjective} #{abbreviation} #{noun}!",
|
|
20
|
+
"Try to #{verb} the #{abbreviation} #{noun}, maybe it will #{verb} the #{adjective} #{noun}!",
|
|
21
|
+
"You can't #{verb} the #{noun} without #{ingverb} the #{adjective} #{abbreviation} #{noun}!",
|
|
22
|
+
"Use the #{adjective} #{abbreviation} #{noun}, then you can #{verb} the #{adjective} #{noun}!",
|
|
23
|
+
"The #{abbreviation} #{noun} is down, #{verb} the #{adjective} #{noun} so we can #{verb} the #{abbreviation} #{noun}!",
|
|
24
|
+
"#{ingverb} the #{noun} won't do anything, we need to #{verb} the #{adjective} #{abbreviation} #{noun}!",
|
|
25
|
+
"I'll #{verb} the #{adjective} #{abbreviation} #{noun}, that should #{noun} the #{abbreviation} #{noun}!"
|
|
26
|
+
]
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
en-US:
|
|
2
|
+
faker:
|
|
3
|
+
internet:
|
|
4
|
+
domain_suffix: [com, us, biz, info, name, net, org]
|
|
5
|
+
address:
|
|
6
|
+
default_country: [United States, United States of America, USA]
|
|
7
|
+
postcode_by_state:
|
|
8
|
+
AL: '350##'
|
|
9
|
+
AK: '995##'
|
|
10
|
+
AS: '967##'
|
|
11
|
+
AZ: '850##'
|
|
12
|
+
AR: '717##'
|
|
13
|
+
CA: '900##'
|
|
14
|
+
CO: '800##'
|
|
15
|
+
CT: '061##'
|
|
16
|
+
DC: '204##'
|
|
17
|
+
DE: '198##'
|
|
18
|
+
FL: '322##'
|
|
19
|
+
GA: '301##'
|
|
20
|
+
HI: '967##'
|
|
21
|
+
ID: '832##'
|
|
22
|
+
IL: '600##'
|
|
23
|
+
IN: '463##'
|
|
24
|
+
IA: '510##'
|
|
25
|
+
KS: '666##'
|
|
26
|
+
KY: '404##'
|
|
27
|
+
LA: '701##'
|
|
28
|
+
ME: '042##'
|
|
29
|
+
MD: '210##'
|
|
30
|
+
MA: '026##'
|
|
31
|
+
MI: '480##'
|
|
32
|
+
MN: '555##'
|
|
33
|
+
MS: '387##'
|
|
34
|
+
MO: '650##'
|
|
35
|
+
MT: '590##'
|
|
36
|
+
NE: '688##'
|
|
37
|
+
NV: '898##'
|
|
38
|
+
NH: '036##'
|
|
39
|
+
NJ: '076##'
|
|
40
|
+
NM: '880##'
|
|
41
|
+
NY: '122##'
|
|
42
|
+
NC: '288##'
|
|
43
|
+
ND: '586##'
|
|
44
|
+
OH: '444##'
|
|
45
|
+
OK: '730##'
|
|
46
|
+
OR: '979##'
|
|
47
|
+
PA: '186##'
|
|
48
|
+
RI: '029##'
|
|
49
|
+
SC: '299##'
|
|
50
|
+
SD: '577##'
|
|
51
|
+
TN: '383##'
|
|
52
|
+
TX: '798##'
|
|
53
|
+
UT: '847##'
|
|
54
|
+
VT: '050##'
|
|
55
|
+
VA: '222##'
|
|
56
|
+
WA: '990##'
|
|
57
|
+
WV: '247##'
|
|
58
|
+
WI: '549##'
|
|
59
|
+
WY: '831##'
|
|
60
|
+
phone_number:
|
|
61
|
+
area_code: ["201", "202", "203", "205", "206", "207", "208", "209", "210", "212", "213", "214", "215", "216", "217", "218", "219", "224", "225", "227", "228", "229", "231", "234", "239", "240", "248", "251", "252", "253", "254", "256", "260", "262", "267", "269", "270", "276", "281", "283", "301", "302", "303", "304", "305", "307", "308", "309", "310", "312", "313", "314", "315", "316", "317", "318", "319", "320", "321", "323", "330", "331", "334", "336", "337", "339", "347", "351", "352", "360", "361", "386", "401", "402", "404", "405", "406", "407", "408", "409", "410", "412", "413", "414", "415", "417", "419", "423", "424", "425", "434", "435", "440", "443", "445", "464", "469", "470", "475", "478", "479", "480", "484", "501", "502", "503", "504", "505", "507", "508", "509", "510", "512", "513", "515", "516", "517", "518", "520", "530", "540", "541", "551", "557", "559", "561", "562", "563", "564", "567", "570", "571", "573", "574", "580", "585", "586", "601", "602", "603", "605", "606", "607", "608", "609", "610", "612", "614", "615", "616", "617", "618", "619", "620", "623", "626", "630", "631", "636", "641", "646", "650", "651", "660", "661", "662", "667", "678", "682", "701", "702", "703", "704", "706", "707", "708", "712", "713", "714", "715", "716", "717", "718", "719", "720", "724", "727", "731", "732", "734", "737", "740", "754", "757", "760", "763", "765", "770", "772", "773", "774", "775", "781", "785", "786", "801", "802", "803", "804", "805", "806", "808", "810", "812", "813", "814", "815", "816", "817", "818", "828", "830", "831", "832", "835", "843", "845", "847", "848", "850", "856", "857", "858", "859", "860", "862", "863", "864", "865", "870", "872", "878", "901", "903", "904", "906", "907", "908", "909", "910", "912", "913", "914", "915", "916", "917", "918", "919", "920", "925", "928", "931", "936", "937", "940", "941", "947", "949", "952", "954", "956", "959", "970", "971", "972", "973", "975", "978", "979", "980", "984", "985", "989"]
|
|
62
|
+
exchange_code: ["201", "202", "203", "205", "206", "207", "208", "209", "210", "212", "213", "214", "215", "216", "217", "218", "219", "224", "225", "227", "228", "229", "231", "234", "239", "240", "248", "251", "252", "253", "254", "256", "260", "262", "267", "269", "270", "276", "281", "283", "301", "302", "303", "304", "305", "307", "308", "309", "310", "312", "313", "314", "315", "316", "317", "318", "319", "320", "321", "323", "330", "331", "334", "336", "337", "339", "347", "351", "352", "360", "361", "386", "401", "402", "404", "405", "406", "407", "408", "409", "410", "412", "413", "414", "415", "417", "419", "423", "424", "425", "434", "435", "440", "443", "445", "464", "469", "470", "475", "478", "479", "480", "484", "501", "502", "503", "504", "505", "507", "508", "509", "510", "512", "513", "515", "516", "517", "518", "520", "530", "540", "541", "551", "557", "559", "561", "562", "563", "564", "567", "570", "571", "573", "574", "580", "585", "586", "601", "602", "603", "605", "606", "607", "608", "609", "610", "612", "614", "615", "616", "617", "618", "619", "620", "623", "626", "630", "631", "636", "641", "646", "650", "651", "660", "661", "662", "667", "678", "682", "701", "702", "703", "704", "706", "707", "708", "712", "713", "714", "715", "716", "717", "718", "719", "720", "724", "727", "731", "732", "734", "737", "740", "754", "757", "760", "763", "765", "770", "772", "773", "774", "775", "781", "785", "786", "801", "802", "803", "804", "805", "806", "808", "810", "812", "813", "814", "815", "816", "817", "818", "828", "830", "831", "832", "835", "843", "845", "847", "848", "850", "856", "857", "858", "859", "860", "862", "863", "864", "865", "870", "872", "878", "901", "903", "904", "906", "907", "908", "909", "910", "912", "913", "914", "915", "916", "917", "918", "919", "920", "925", "928", "931", "936", "937", "940", "941", "947", "949", "952", "954", "956", "959", "970", "971", "972", "973", "975", "978", "979", "980", "984", "985", "989"]
|
|
63
|
+
formats:
|
|
64
|
+
- "#{PhoneNumber.area_code}-#{PhoneNumber.exchange_code}-#{PhoneNumber.subscriber_number}"
|
|
65
|
+
- "(#{PhoneNumber.area_code}) #{PhoneNumber.exchange_code}-#{PhoneNumber.subscriber_number}"
|
|
66
|
+
- "1-#{PhoneNumber.area_code}-#{PhoneNumber.exchange_code}-#{PhoneNumber.subscriber_number}"
|
|
67
|
+
- "#{PhoneNumber.area_code}.#{PhoneNumber.exchange_code}.#{PhoneNumber.subscriber_number}"
|
|
68
|
+
- "#{PhoneNumber.area_code}-#{PhoneNumber.exchange_code}-#{PhoneNumber.subscriber_number}"
|
|
69
|
+
- "(#{PhoneNumber.area_code}) #{PhoneNumber.exchange_code}-#{PhoneNumber.subscriber_number}"
|
|
70
|
+
- "1-#{PhoneNumber.area_code}-#{PhoneNumber.exchange_code}-#{PhoneNumber.subscriber_number}"
|
|
71
|
+
- "#{PhoneNumber.area_code}.#{PhoneNumber.exchange_code}.#{PhoneNumber.subscriber_number}"
|
|
72
|
+
- "#{PhoneNumber.area_code}-#{PhoneNumber.exchange_code}-#{PhoneNumber.subscriber_number} x#{PhoneNumber.extension}"
|
|
73
|
+
- "(#{PhoneNumber.area_code}) #{PhoneNumber.exchange_code}-#{PhoneNumber.subscriber_number} x#{PhoneNumber.extension}"
|
|
74
|
+
- "1-#{PhoneNumber.area_code}-#{PhoneNumber.exchange_code}-#{PhoneNumber.subscriber_number} x#{PhoneNumber.extension}"
|
|
75
|
+
- "#{PhoneNumber.area_code}.#{PhoneNumber.exchange_code}.#{PhoneNumber.subscriber_number} x#{PhoneNumber.extension}"
|
|
76
|
+
- "#{PhoneNumber.area_code}-#{PhoneNumber.exchange_code}-#{PhoneNumber.subscriber_number} x#{PhoneNumber.extension}"
|
|
77
|
+
- "(#{PhoneNumber.area_code}) #{PhoneNumber.exchange_code}-#{PhoneNumber.subscriber_number} x#{PhoneNumber.extension}"
|
|
78
|
+
- "1-#{PhoneNumber.area_code}-#{PhoneNumber.exchange_code}-#{PhoneNumber.subscriber_number} x#{PhoneNumber.extension}"
|
|
79
|
+
- "#{PhoneNumber.area_code}.#{PhoneNumber.exchange_code}.#{PhoneNumber.subscriber_number} x#{PhoneNumber.extension}"
|
|
80
|
+
- "#{PhoneNumber.area_code}-#{PhoneNumber.exchange_code}-#{PhoneNumber.subscriber_number} x#{PhoneNumber.extension}"
|
|
81
|
+
- "(#{PhoneNumber.area_code}) #{PhoneNumber.exchange_code}-#{PhoneNumber.subscriber_number} x#{PhoneNumber.extension}"
|
|
82
|
+
- "1-#{PhoneNumber.area_code}-#{PhoneNumber.exchange_code}-#{PhoneNumber.subscriber_number} x#{PhoneNumber.extension}"
|
|
83
|
+
- "#{PhoneNumber.area_code}.#{PhoneNumber.exchange_code}.#{PhoneNumber.subscriber_number} x#{PhoneNumber.extension}"
|