Module: CreateValid

Defined in:
lib/create_valid.rb

Defined Under Namespace

Modules: GlobalHelpers, TestIntegration Classes: Factory, KludgyEvalContext

Constant Summary collapse

MAGIC_METHOD =
/^(build|create)_(valid_)?(.*?)(_with_(.*?))?$/
@@registry =
Hash.new { |h,k| h[k] = [] }
@@sequence =
0

Class Method Summary collapse

Class Method Details

.[](key) ⇒ Object



11
12
13
# File 'lib/create_valid.rb', line 11

def self.[](key)
  @@registry[key.to_s]
end

.next_sequenceObject



7
8
9
# File 'lib/create_valid.rb', line 7

def self.next_sequence
  @@sequence += 1
end

.register(model_name, attributes, &block) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/create_valid.rb', line 15

def self.register(model_name, attributes, &block)
  model_name = model_name.to_s.gsub(' ', '_')
  if attributes
    raise ArgumentError, "attributes must be a hash" unless attributes.is_a?(Hash)
    raise ArgumentError, "attributes xor block required" unless block.nil?
    @@registry[model_name] << attributes
  elsif block
    raise ArgumentError, "attributes xor block required" unless attributes.nil?
    @@registry[model_name] << block
  else
    raise ArgumentError, "attributes xor block required"
  end
end