Module: Gotcha

Defined in:
lib/gotcha.rb,
lib/gotcha/base.rb,
lib/gotcha/version.rb,
lib/gotcha/form_helpers.rb,
lib/gotcha/controller_helpers.rb

Defined Under Namespace

Modules: ControllerHelpers, FormHelpers Classes: Base

Constant Summary collapse

VERSION =
'0.0.6'

Class Method Summary collapse

Class Method Details

.gotcha_typesObject



39
40
41
# File 'lib/gotcha.rb', line 39

def self.gotcha_types
  @gotcha_types ||= []
end

.randomObject

Get a random Gotcha from the registered types



19
20
21
22
23
# File 'lib/gotcha.rb', line 19

def self.random
  if !@gotcha_types.nil? && type = random_type
    type.new 
  end
end

.random_typeObject



35
36
37
# File 'lib/gotcha.rb', line 35

def self.random_type
  @gotcha_types.respond_to?(:sample) ? @gotcha_types.sample : @gotcha_types[rand(@gotcha_types.size)]
end

.register_type(type) ⇒ Object

Register a Gotcha type



13
14
15
16
# File 'lib/gotcha.rb', line 13

def self.register_type(type)
  @gotcha_types ||= []
  @gotcha_types << type
end

.skip_validation=(val) ⇒ Object

Set whether or not to skip validation



31
32
33
# File 'lib/gotcha.rb', line 31

def self.skip_validation=(val)
  @skip_validation = !!val
end

.skip_validation?Boolean

Whether or not to skip validation

Returns:

  • (Boolean)


26
27
28
# File 'lib/gotcha.rb', line 26

def self.skip_validation?
  @skip_validation || false
end

.unregister_all_typesObject

Remove all gotcha types



8
9
10
# File 'lib/gotcha.rb', line 8

def self.unregister_all_types
  @gotcha_types = []
end