Module: Workbench
- Defined in:
- lib/workbench.rb,
lib/workbench/string_helpers.rb
Defined Under Namespace
Modules: InstanceMethods, StringHelpers
Constant Summary collapse
- COUNTERS =
Hash.new(0)
Class Method Summary collapse
-
.counter(key) ⇒ Object
The counter routine.
- .extended(klass) ⇒ Object
-
.reset_counters! ⇒ Object
Reset all counters.
Instance Method Summary collapse
-
#count_with(name) ⇒ Object
Declare that the next builder method is to count scoped to the following class.
-
#use_class(name) ⇒ Object
Declare that the next builder method is to use the said class.
Class Method Details
.counter(key) ⇒ Object
The counter routine. Provide a key, get back an incrementer.
85 86 87 |
# File 'lib/workbench.rb', line 85 def self.counter(key) COUNTERS[key] += 1 end |
.extended(klass) ⇒ Object
30 31 32 |
# File 'lib/workbench.rb', line 30 def self.extended(klass) klass.send :include, InstanceMethods end |
.reset_counters! ⇒ Object
Reset all counters. It doesn’t happen automatically, you’ll likley want to call this method before or after each test is run
91 92 93 |
# File 'lib/workbench.rb', line 91 def self.reset_counters! COUNTERS.clear end |
Instance Method Details
#count_with(name) ⇒ Object
Declare that the next builder method is to count scoped to the following class
module Builders
extend Workbench
def book_defaults(u, n)
...
end
count_with :Book
def article_defaults(u, n)
...
end
end
new_book # n = 1
new_publication # n = 2
new_book # n = 3
Parameters:
name
-
a Symbol (ie :User) or string (is “Models::User”) that maps to a valid class name.
-
80 81 82 |
# File 'lib/workbench.rb', line 80 def count_with(name) @next_count_with = name end |
#use_class(name) ⇒ Object
Declare that the next builder method is to use the said class
module Builders
extend Workbench
def user_defaults(u)
...
end
use_class :User
def admin_user_defaults(u)
...
end
end
Parameters:
- name
-
Symbol such as :User or string such as “Models::User” are acceptable
-
53 54 55 |
# File 'lib/workbench.rb', line 53 def use_class(name) @next_class = name end |