Class: Statinize::Statinizer
- Inherits:
-
Object
- Object
- Statinize::Statinizer
show all
- Includes:
- DSL
- Defined in:
- lib/statinize/statinizer.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from DSL
#attribute, #before, #force, #validate, #with
Constructor Details
#initialize(klass) ⇒ Statinizer
Returns a new instance of Statinizer.
11
12
13
14
15
|
# File 'lib/statinize/statinizer.rb', line 11
def initialize(klass)
@klass = klass
@force = config.force
@before_callbacks = []
end
|
Instance Attribute Details
#before_callbacks ⇒ Object
Returns the value of attribute before_callbacks.
5
6
7
|
# File 'lib/statinize/statinizer.rb', line 5
def before_callbacks
@before_callbacks
end
|
#klass ⇒ Object
Returns the value of attribute klass.
5
6
7
|
# File 'lib/statinize/statinizer.rb', line 5
def klass
@klass
end
|
Class Method Details
7
8
9
|
# File 'lib/statinize/statinizer.rb', line 7
def self.configure(&block)
Configuration.configure(&block)
end
|
Instance Method Details
#add_attribute(attribute) ⇒ Object
25
26
27
|
# File 'lib/statinize/statinizer.rb', line 25
def add_attribute(attribute)
attributes.add(attribute) unless attribute? attribute
end
|
#attribute?(attribute) ⇒ Boolean
39
40
41
|
# File 'lib/statinize/statinizer.rb', line 39
def attribute?(attribute)
attributes.map(&:name).include? attribute.name
end
|
#attributes ⇒ Object
29
30
31
|
# File 'lib/statinize/statinizer.rb', line 29
def attributes
@attributes ||= Set.new
end
|
#check_validators_exist! ⇒ Object
43
44
45
|
# File 'lib/statinize/statinizer.rb', line 43
def check_validators_exist!
raise NoSuchValidatorError unless all_validators_defined?
end
|
#config ⇒ Object
17
18
19
|
# File 'lib/statinize/statinizer.rb', line 17
def config
@config ||= Configuration.instance
end
|
#force? ⇒ Boolean
21
22
23
|
# File 'lib/statinize/statinizer.rb', line 21
def force?
@force
end
|
#run_before_callbacks(instance) ⇒ Object
33
34
35
36
37
|
# File 'lib/statinize/statinizer.rb', line 33
def run_before_callbacks(instance)
before_callbacks.each do |callback|
instance.instance_exec(&callback) if callback.is_a? Proc
end
end
|