Module: Modelizer

Includes:
Assertions
Defined in:
lib/modelizer.rb,
lib/modelizer/assertions.rb,
lib/modelizer/validations.rb

Defined Under Namespace

Modules: Assertions, ClassMethods, Validations

Constant Summary collapse

VERSION =

Duh.

"2.1.0"
TEST_CLASSES =

Test classes that should be considered abstract when rendering tests for a model template.

[]
@@cache =
{}
@@namespace =
true

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Assertions

#assert_invalid

Class Method Details

.cacheObject



24
# File 'lib/modelizer.rb', line 24

def self.cache; @@cache end

.included(target) ⇒ Object



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

def self.included target
  target.extend ClassMethods
  target.extend Modelizer::Validations
end

.namespace=(ns) ⇒ Object



33
# File 'lib/modelizer.rb', line 33

def self.namespace= ns; @@namespace = ns end

.namespace?Boolean

Returns:

  • (Boolean)


32
# File 'lib/modelizer.rb', line 32

def self.namespace?; @@namespace end

.underscore(classname) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/modelizer.rb', line 35

def self.underscore classname
  classname.gsub(/::/, '_').
    gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
    gsub(/([a-z\d])([A-Z])/,'\1_\2').
    tr("-", "_").
    downcase
end

Instance Method Details

#assign_model_template_attributes(model, attributes) ⇒ Object



43
44
45
46
# File 'lib/modelizer.rb', line 43

def assign_model_template_attributes model, attributes
  model.send :attributes=, attributes, false
  model
end

#valid_model_template_attributes(klass, extras = {}) ⇒ Object



48
49
50
51
52
# File 'lib/modelizer.rb', line 48

def valid_model_template_attributes klass, extras = {}
  defaults, block = ::Modelizer.cache[klass]
  lazy = block && instance_eval(&block)
  [defaults, lazy, extras].compact.inject { |t, s| t.merge s }
end

#valid_model_template_attributes_without(klass, excluded) ⇒ Object



54
55
56
57
58
# File 'lib/modelizer.rb', line 54

def valid_model_template_attributes_without klass, excluded
  valid_model_template_attributes(klass).delete_if do |k, v|
    excluded.include? k
  end
end