Class: VWorkApp::Base
- Inherits:
-
Object
show all
- Includes:
- ActiveModel::Serializers::JSON, ActiveModel::Serializers::Xml, ActiveModel::Validations
- Defined in:
- lib/vworkapp_ruby/base/base.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(attributes = {}) ⇒ Base
Returns a new instance of Base.
9
10
11
|
# File 'lib/vworkapp_ruby/base/base.rb', line 9
def initialize(attributes = {})
self.attributes = attributes
end
|
Class Method Details
.hattr_accessor(*hattrs) ⇒ Object
31
32
33
34
|
# File 'lib/vworkapp_ruby/base/base.rb', line 31
def self.hattr_accessor(*hattrs)
hattr_reader(*hattrs)
hattr_writer(*hattrs)
end
|
.hattr_reader(*hattrs) ⇒ Object
17
18
19
20
21
22
|
# File 'lib/vworkapp_ruby/base/base.rb', line 17
def self.hattr_reader(*hattrs)
hattrs.each do |hattr|
self.read_hattrs << hattr
attr_reader(hattr.is_a?(Hash) ? hattr.keys.first : hattr)
end
end
|
.hattr_writer(*hattrs) ⇒ Object
24
25
26
27
28
29
|
# File 'lib/vworkapp_ruby/base/base.rb', line 24
def self.hattr_writer(*hattrs)
hattrs.each do |hattr|
self.write_hattrs << hattr
attr_writer(hattr.is_a?(Hash) ? hattr.keys.first : hattr)
end
end
|
.hattrs ⇒ Object
50
51
52
|
# File 'lib/vworkapp_ruby/base/base.rb', line 50
def self.hattrs
read_hattrs + write_hattrs
end
|
.read_hattrs ⇒ Object
43
44
45
|
# File 'lib/vworkapp_ruby/base/base.rb', line 43
def self.read_hattrs
@read_hattrs ||= Set.new
end
|
.write_hattrs ⇒ Object
36
37
38
|
# File 'lib/vworkapp_ruby/base/base.rb', line 36
def self.write_hattrs
@write_hattrs ||= Set.new
end
|
Instance Method Details
#attributes ⇒ Object
61
62
63
|
# File 'lib/vworkapp_ruby/base/base.rb', line 61
def attributes
(hattrs)
end
|
#attributes=(hash) ⇒ Object
73
74
75
|
# File 'lib/vworkapp_ruby/base/base.rb', line 73
def attributes=(hash)
inject_attributes(hattrs, hash)
end
|
#attributes_eql?(other, *test_attrs) ⇒ Boolean
93
94
95
96
97
98
|
# File 'lib/vworkapp_ruby/base/base.rb', line 93
def attributes_eql?(other, *test_attrs)
test_attrs.each do |attribute|
return false unless self.send(attribute.to_sym) == other.send(attribute.to_sym)
end
true
end
|
#hattrs ⇒ Object
53
54
55
|
# File 'lib/vworkapp_ruby/base/base.rb', line 53
def hattrs
self.class.hattrs
end
|
#read_attributes ⇒ Object
65
66
67
|
# File 'lib/vworkapp_ruby/base/base.rb', line 65
def read_attributes
(read_hattrs)
end
|
#read_attributes=(hash) ⇒ Object
81
82
83
|
# File 'lib/vworkapp_ruby/base/base.rb', line 81
def read_attributes=(hash)
inject_attributes(read_hattrs, hash)
end
|
#read_hattrs ⇒ Object
46
47
48
|
# File 'lib/vworkapp_ruby/base/base.rb', line 46
def read_hattrs
self.class.read_hattrs
end
|
#validate_and_raise ⇒ Object
89
90
91
|
# File 'lib/vworkapp_ruby/base/base.rb', line 89
def validate_and_raise
raise Exception.new(self.errors.full_messages.join("\n")) unless valid?
end
|
#write_attributes ⇒ Object
69
70
71
|
# File 'lib/vworkapp_ruby/base/base.rb', line 69
def write_attributes
(write_hattrs)
end
|
#write_attributes=(hash) ⇒ Object
77
78
79
|
# File 'lib/vworkapp_ruby/base/base.rb', line 77
def write_attributes=(hash)
inject_attributes(write_hattrs, hash)
end
|
#write_hattrs ⇒ Object
39
40
41
|
# File 'lib/vworkapp_ruby/base/base.rb', line 39
def write_hattrs
self.class.write_hattrs
end
|