Class: Gateway
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Gateway
show all
- Includes:
- Redis::Objects::RMap
- Defined in:
- app/models/gateway.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
# File 'app/models/gateway.rb', line 67
def method_missing(name, *args, &block)
assign = name[-1] == '='
name = name[0, name.length-1] if assign
if name.to_s.starts_with?('setting_')
source = gateway_settings
klass = GatewaySetting
name = name.to_s.gsub('setting_', '')
elsif name.to_s.starts_with?('attachment_')
source = gateway_attachments
klass = GatewayAttachment
name = name.to_s.gsub('attachment_', '')
elsif name.to_s.starts_with?('switch_')
source = gateway_switches
klass = GatewaySwitch
name = name.to_s.gsub('switch_', '')
else
return super
end
if assign
data = source.select{|x| x.keyword == name}.first
if data.blank?
source << klass.new(:keyword => name, :gateway_id => id, :value => args[0])
else
data.value = args[0]
end
else
result = source.select{|x| x.keyword == name}.first.try(:value)
result = false if result.blank? && klass == GatewaySwitch
result
end
end
|
Instance Method Details
#available_attachments ⇒ Object
36
37
38
|
# File 'app/models/gateway.rb', line 36
def available_attachments
librarize(false)::available_attachments
end
|
#available_settings ⇒ Object
32
33
34
|
# File 'app/models/gateway.rb', line 32
def available_settings
librarize(false)::available_settings
end
|
#available_switches ⇒ Object
40
41
42
|
# File 'app/models/gateway.rb', line 40
def available_switches
librarize(false)::available_switches
end
|
#librarize(instantiate = true) ⇒ Object
27
28
29
30
|
# File 'app/models/gateway.rb', line 27
def librarize(instantiate=true)
klass = ("Payzilla::Gateways::"+payzilla.camelize).constantize
return instantiate ? klass.new(self) : klass
end
|
#respond_to?(key, include_private = false) ⇒ Boolean
62
63
64
65
|
# File 'app/models/gateway.rb', line 62
def respond_to?(key, include_private=false)
return true if key.to_s.starts_with?('setting_') || key.to_s.starts_with?('attachment_') || key.to_s.starts_with?('switch_')
super(key, include_private)
end
|
#serialize_options ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'app/models/gateway.rb', line 44
def serialize_options
options = {}
sources = {
"setting" => available_settings,
"attachment" => available_attachments,
"switch" => available_switches
}
sources.each do |prefix, source|
source.each do |element|
keyword = "#{prefix}_#{element}"
options[keyword] = send keyword
end
end
options
end
|