Class: Account
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
wrapping_class, wrapping_class=
Constructor Details
#initialize(user, attributes = user.attributes) ⇒ Account
Returns a new instance of Account.
16
17
18
19
|
# File 'app/models/account.rb', line 16
def initialize(user, attributes = user.attributes)
@user = user
self.attributes = attributes
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
106
107
108
109
110
111
112
|
# File 'app/models/account.rb', line 106
def method_missing(method_name, *args, &block)
begin
super
rescue NoMethodError
user.send(method_name, *args, &block)
end
end
|
Instance Attribute Details
#user ⇒ Object
Returns the value of attribute user.
21
22
23
|
# File 'app/models/account.rb', line 21
def user
@user
end
|
Class Method Details
.apply_person_attributes ⇒ Object
34
35
36
37
38
39
40
41
42
|
# File 'app/models/account.rb', line 34
def self.apply_person_attributes
Person.editable_attributes.each do |att|
self.person_attribute_names += [att.name.to_s]
attribute(att.name)
att.with_validation_options do |name, opts|
validates(name, opts)
end
end
end
|
.apply_user_attributes ⇒ Object
44
45
46
47
48
|
# File 'app/models/account.rb', line 44
def self.apply_user_attributes
user_attribute_names.each do |attribute_name|
attribute(attribute_name)
end
end
|
Instance Method Details
#create ⇒ Object
Also known as:
save
53
54
55
56
57
58
59
60
61
|
# File 'app/models/account.rb', line 53
def create
if create_user &&
create_person &&
create_profile
true
else
collect_errors
end
end
|
#inspect ⇒ Object
6
7
8
|
# File 'app/models/account.rb', line 6
def inspect
"#<#{self.class} user.id: #{user.id}, user.repository_id: #{user.repository_id}, attributes: #{attributes.inspect}>"
end
|
#is_a?(comparison) ⇒ Boolean
10
11
12
|
# File 'app/models/account.rb', line 10
def is_a?(comparison)
super || user.is_a?(comparison)
end
|
#profile ⇒ Object
25
26
27
|
# File 'app/models/account.rb', line 25
def profile
@profile ||= person.profile || person.build_profile(title: profile_title)
end
|
#respond_to_missing?(*args) ⇒ Boolean
114
115
116
|
# File 'app/models/account.rb', line 114
def respond_to_missing?(*args)
super || user.respond_to?(*args)
end
|
#update_with_password(initial_params, *options) ⇒ Object
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'app/models/account.rb', line 78
def update_with_password(initial_params, *options)
params = normalize_update_params(initial_params)
extract_user_and_person_attributes_for_update(params)
if update_user(*options) &&
update_person &&
update_profile
true
else
collect_errors
false
end
end
|
#update_without_password(initial_params, *options) ⇒ Object
91
92
93
94
95
96
97
98
99
100
101
102
|
# File 'app/models/account.rb', line 91
def update_without_password(initial_params, *options)
params = normalize_update_params(initial_params)
extract_user_and_person_attributes_for_update(params)
if update_user_without_password(*options) &&
update_person &&
update_profile
true
else
collect_errors
false
end
end
|