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
103
104
105
106
107
108
109
|
# File 'app/models/account.rb', line 103
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
42
43
44
45
46
47
48
49
50
|
# File 'app/models/account.rb', line 42
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
52
53
54
55
56
|
# File 'app/models/account.rb', line 52
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
61
62
63
64
65
66
67
68
69
70
71
|
# File 'app/models/account.rb', line 61
def create
if create_user &&
create_person &&
create_profile &&
connect_user_to_person &&
connect_person_to_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
|
#person ⇒ Object
23
24
25
26
27
28
29
30
31
|
# File 'app/models/account.rb', line 23
def person
return @person if @person
@person = if user.person
user.person
else
user.person = Person.new(name: user.name)
end
@person
end
|
#profile ⇒ Object
33
34
35
|
# File 'app/models/account.rb', line 33
def profile
@profile ||= person.profile || Collection.new(title: profile_title, resource_type: "Profile")
end
|
#respond_to_missing?(*args) ⇒ Boolean
111
112
113
|
# File 'app/models/account.rb', line 111
def respond_to_missing?(*args)
super || user.respond_to?(*args)
end
|
#update_with_password(initial_params, *options) ⇒ Object
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'app/models/account.rb', line 88
def update_with_password(initial_params, *options)
params = normalize_update_params(initial_params)
extract_user_and_person_attributes_for_update(params)
if user.update_with_password(user_attributes, *options) &&
user.person.update(person_attributes) &&
sync_profile_title_to_name(person_attributes)
true
else
collect_errors
false
end
end
|