Class: OpenX::Services::Base
- Inherits:
-
Object
- Object
- OpenX::Services::Base
- Extended by:
- Persistance::ClassMethods
- Includes:
- Comparable, Persistance::InstanceMethods
- Defined in:
- lib/openx/services/base.rb
Class Attribute Summary collapse
-
.connection ⇒ Object
Returns the current connection (session).
-
.create ⇒ Object
Returns the value of attribute create.
-
.delete ⇒ Object
Returns the value of attribute delete.
-
.find_all ⇒ Object
Returns the value of attribute find_all.
-
.find_one ⇒ Object
Returns the value of attribute find_one.
-
.translations ⇒ Object
Returns the value of attribute translations.
-
.update ⇒ Object
Returns the value of attribute update.
Class Method Summary collapse
-
.establish_connection(conn) ⇒ Object
Establishes a custom connection.
- .has_one(*things) ⇒ Object
- .openx_accessor(accessor_map) ⇒ Object
-
.remote ⇒ Object
Remote API proxy.
-
.with_connection(temporary) ⇒ Object
Execute a block using a custom connection.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(params = {}) ⇒ Base
constructor
A new instance of Base.
- #new_record? ⇒ Boolean
Methods included from Persistance::ClassMethods
Methods included from Persistance::InstanceMethods
Constructor Details
#initialize(params = {}) ⇒ Base
Returns a new instance of Base.
72 73 74 75 |
# File 'lib/openx/services/base.rb', line 72 def initialize(params = {}) @id = nil params.each { |k,v| send(:"#{k}=", v) } end |
Class Attribute Details
.connection ⇒ Object
Returns the current connection (session)
40 41 42 43 |
# File 'lib/openx/services/base.rb', line 40 def connection @connection = nil unless defined?(@connection) @connection || OpenX::Services.default_connection end |
.create ⇒ Object
Returns the value of attribute create.
11 12 13 |
# File 'lib/openx/services/base.rb', line 11 def create @create end |
.delete ⇒ Object
Returns the value of attribute delete.
11 12 13 |
# File 'lib/openx/services/base.rb', line 11 def delete @delete end |
.find_all ⇒ Object
Returns the value of attribute find_all.
11 12 13 |
# File 'lib/openx/services/base.rb', line 11 def find_all @find_all end |
.find_one ⇒ Object
Returns the value of attribute find_one.
11 12 13 |
# File 'lib/openx/services/base.rb', line 11 def find_one @find_one end |
.translations ⇒ Object
Returns the value of attribute translations.
9 10 11 |
# File 'lib/openx/services/base.rb', line 9 def translations @translations end |
.update ⇒ Object
Returns the value of attribute update.
11 12 13 |
# File 'lib/openx/services/base.rb', line 11 def update @update end |
Class Method Details
.establish_connection(conn) ⇒ Object
18 19 20 21 |
# File 'lib/openx/services/base.rb', line 18 def establish_connection(conn) conn = OpenX::Services.establish_connection(conn) if conn.is_a?(Hash) self.connection = conn end |
.has_one(*things) ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/openx/services/base.rb', line 52 def has_one(*things) things.each do |thing| attr_writer :"#{thing}" define_method(:"#{thing}") do klass = thing.to_s.capitalize.gsub(/_[a-z]/) { |m| m[1].chr.upcase } klass = OpenX::Services.const_get(:"#{klass}") klass.find(send("#{thing}_id")) end end end |
.openx_accessor(accessor_map) ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/openx/services/base.rb', line 63 def openx_accessor(accessor_map) @translations ||= {} @translations = accessor_map.merge(@translations) accessor_map.each do |ruby,openx| attr_accessor :"#{ruby}" end end |
.remote ⇒ Object
Remote API proxy. Example:
OpenX::Services::Agency.remote.call 'ox.addAgency', ...
48 49 50 |
# File 'lib/openx/services/base.rb', line 48 def remote connection.remote end |
.with_connection(temporary) ⇒ Object
Execute a block using a custom connection. Example:
custom_conn = OpenX::Services.establish_connection({ ... })
OpenX::Services::Agency.with_connection(custom_conn) do
OpenX::Services::Agency.find(:all)
end
29 30 31 32 33 34 35 36 37 |
# File 'lib/openx/services/base.rb', line 29 def with_connection(temporary) current = @connection begin establish_connection(temporary) yield ensure establish_connection(current) end end |
Instance Method Details
#<=>(other) ⇒ Object
81 82 83 |
# File 'lib/openx/services/base.rb', line 81 def <=>(other) self.id <=> other.id end |
#new_record? ⇒ Boolean
77 78 79 |
# File 'lib/openx/services/base.rb', line 77 def new_record? @id.nil? end |