Class: Challah::Signup
- Inherits:
-
Object
show all
- Extended by:
- ActiveModel::Naming
- Includes:
- ActiveModel::Conversion
- Defined in:
- lib/challah/signup.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(attributes = {}) ⇒ Signup
Returns a new instance of Signup.
9
10
11
12
13
14
|
# File 'lib/challah/signup.rb', line 9
def initialize(attributes = {})
self.user = Challah.user.new
self.provider = :password
self.attributes = attributes
@errors = []
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *attrs) ⇒ Object
24
25
26
|
# File 'lib/challah/signup.rb', line 24
def method_missing(method, *attrs)
user.send(method, *attrs)
end
|
Instance Attribute Details
#errors ⇒ Object
Returns the value of attribute errors.
6
7
8
|
# File 'lib/challah/signup.rb', line 6
def errors
@errors
end
|
#provider ⇒ Object
Returns the value of attribute provider.
7
8
9
|
# File 'lib/challah/signup.rb', line 7
def provider
@provider
end
|
#user ⇒ Object
Returns the value of attribute user.
7
8
9
|
# File 'lib/challah/signup.rb', line 7
def user
@user
end
|
Class Method Details
.model_name ⇒ Object
71
72
73
|
# File 'lib/challah/signup.rb', line 71
def self.model_name
ActiveModel::Name.new(Challah::Signup, Challah, "Signup")
end
|
Instance Method Details
#attributes=(value) ⇒ Object
16
17
18
19
20
21
22
|
# File 'lib/challah/signup.rb', line 16
def attributes=(value)
return unless Hash === value
value.each do |key, value|
self.send("#{key}=", value)
end
end
|
#password=(value) ⇒ Object
28
29
30
31
|
# File 'lib/challah/signup.rb', line 28
def password=(value)
@provider = :password unless value.to_s.blank?
user.password = value
end
|
#save ⇒ Object
45
46
47
48
49
50
51
|
# File 'lib/challah/signup.rb', line 45
def save
if valid?
user.save
else
false
end
end
|
#valid? ⇒ Boolean
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/challah/signup.rb', line 53
def valid?
@errors = ActiveModel::Errors.new(user)
result = true
unless user.valid?
result = false
user.errors.each { |a, e| @errors.add(a, e) }
end
if !provider or !valid_provider?
result = false
user.errors.each { |a, e| @errors.add(a, e) unless @errors.added?(a, e) }
end
result
end
|
#valid_provider? ⇒ Boolean
33
34
35
|
# File 'lib/challah/signup.rb', line 33
def valid_provider?
user.valid_provider?(provider)
end
|