Class: Objection::Base
- Inherits:
-
Object
show all
- Defined in:
- lib/objection.rb
Defined Under Namespace
Classes: ObjectionException, RequiredFieldEmpty, RequiredFieldMadeEmpty, RequiredFieldMissing, UnknownFieldGiven
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(*args) ⇒ Base
Returns a new instance of Base.
22
23
24
25
26
27
28
29
|
# File 'lib/objection.rb', line 22
def initialize(*args)
@values = normalize_input(*args)
check_values!
define_accessors
apply_structures!
check_types!
end
|
Class Method Details
17
18
19
20
|
# File 'lib/objection.rb', line 17
def self.input_types(*args)
@input_types = args[0]
true
end
|
.optionals(*args) ⇒ Object
14
15
16
|
# File 'lib/objection.rb', line 14
def self.optionals(*args)
@optional_fields = args
end
|
.requires(*args) ⇒ Object
11
12
13
|
# File 'lib/objection.rb', line 11
def self.requires(*args)
@required_fields = args
end
|
Instance Method Details
#to_hash ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/objection.rb', line 31
def to_hash
hash = {}
@values.each_pair do |key, value|
if value.is_a?(Array)
hash[key] = value.inject([]) do |items, item|
if item.respond_to?(:to_hash)
items << item.to_hash
else
items << item
end
end
elsif value.respond_to?(:to_hash)
hash[key] = value.to_hash
else
hash[key] = value
end
end
hash
end
|