Module: Resto::Property
- Included in:
- Integer, String, Time
- Defined in:
- lib/resto/property.rb,
lib/resto/property/time.rb,
lib/resto/property/string.rb,
lib/resto/property/handler.rb,
lib/resto/property/integer.rb
Defined Under Namespace
Classes: Handler, Integer, String, Time
Instance Method Summary
collapse
Instance Method Details
#attribute_key ⇒ Object
24
25
26
|
# File 'lib/resto/property.rb', line 24
def attribute_key
@name
end
|
#attribute_key_as_string ⇒ Object
28
29
30
|
# File 'lib/resto/property.rb', line 28
def attribute_key_as_string
@name.to_s
end
|
#initialize(name, options = {}) ⇒ Object
12
13
14
15
16
17
18
|
# File 'lib/resto/property.rb', line 12
def initialize(name, options={})
raise ':name must be a symbol' unless name.is_a?(Symbol)
@name = name
@remote_name = options.fetch(:remote_name) { name }
@validations = []
end
|
#remote_key ⇒ Object
20
21
22
|
# File 'lib/resto/property.rb', line 20
def remote_key
@remote_name.to_s
end
|
#validate(resource, attribute_key) ⇒ Object
44
45
46
47
48
|
# File 'lib/resto/property.rb', line 44
def validate(resource, attribute_key)
@validations.each do |validate|
validate.attribute_value(resource, attribute_key)
end
end
|
#validate_inclusion ⇒ Object
36
37
38
|
# File 'lib/resto/property.rb', line 36
def validate_inclusion
Validate::Inclusion.new.tap { |validation| @validations.push(validation) }
end
|
#validate_length ⇒ Object
40
41
42
|
# File 'lib/resto/property.rb', line 40
def validate_length
Validate::Length.new.tap { |validation| @validations.push(validation) }
end
|
#validate_presence ⇒ Object
32
33
34
|
# File 'lib/resto/property.rb', line 32
def validate_presence
Validate::Presence.new.tap { |validation| @validations.push(validation) }
end
|