Module: Challah::UserProvideable
- Extended by:
- ActiveSupport::Concern
- Included in:
- Userable
- Defined in:
- lib/challah/concerns/user/provideable.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/challah/concerns/user/provideable.rb', line 10
def method_missing(method, *args)
method_name = method.to_s
if method_name =~ /^([a-z]*)_provider\?$/
return provider?($1)
elsif method_name =~ /^([a-z]*)_provider$/
return provider($1)
end
super
end
|
Instance Method Details
#provider(provider_name) ⇒ Object
50
51
52
|
# File 'lib/challah/concerns/user/provideable.rb', line 50
def provider(provider_name)
providers[provider_name.to_sym]
end
|
#provider?(provider_name) ⇒ Boolean
Does this user have the given provider name
46
47
48
|
# File 'lib/challah/concerns/user/provideable.rb', line 46
def provider?(provider_name)
!!provider(provider_name)
end
|
#provider_attributes ⇒ Object
54
55
56
|
# File 'lib/challah/concerns/user/provideable.rb', line 54
def provider_attributes
@provider_attributes ||= Challah.providers.keys.inject({}) { |h, m| h[m] = nil; h }
end
|
#provider_attributes=(value) ⇒ Object
58
59
60
61
62
63
64
65
|
# File 'lib/challah/concerns/user/provideable.rb', line 58
def provider_attributes=(value)
if Hash === value
@provider_attributes = value.keys.inject({}) do |h, m|
h[m.to_sym] = (value[m].respond_to?(:symbolize_keys) ? value[m].symbolize_keys : value[m])
h
end
end
end
|
#providers ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/challah/concerns/user/provideable.rb', line 22
def providers
return @providers if @providers
@providers = {}
attributes = self.class.authorization_model.hashable_attributes
@providers = authorizations.inject({}) do |hash, m|
hash[m.provider.to_sym] = attributes.inject({}) { |p, a| p[a.to_sym] = m.send(a); p }
hash
end
provider_attributes.each do |k, v|
if v.respond_to?(:fetch)
@providers[k] = v
end
end
@providers
end
|
#valid_provider?(provider_name) ⇒ Boolean
67
68
69
70
71
72
73
74
75
|
# File 'lib/challah/concerns/user/provideable.rb', line 67
def valid_provider?(provider_name)
name = provider_name.to_sym
if Challah.providers.keys.include?(name)
Challah.providers[name].valid?(self)
else
false
end
end
|