Module: TicketMaster::Provider::Common

Included in:
Base::Comment, Base::Project, Base::Ticket
Defined in:
lib/ticketmaster/common.rb

Overview

Common module contains method definitions common to all or most of the models

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

Automatic extension of class methods on include


21
22
23
# File 'lib/ticketmaster/common.rb', line 21

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

#destroyObject

Delete this project Returns true (success) or false(failure)


67
68
69
70
71
72
73
# File 'lib/ticketmaster/common.rb', line 67

def destroy
  if @system_data and @system_data[:client] and @system_data[:client].respond_to?(:destroy)
    return @system_data[:client].destroy
  else
    raise TicketMaster::Exception.new("#{self.class.name}::#{this_method} method must be implemented by the provider")
  end
end

#initialize(*options) ⇒ Object

The initializer It tries to do a default system for ActiveResource-based api providers


27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/ticketmaster/common.rb', line 27

def initialize(*options)
  @system_data ||= {}
  @cache ||= {}
  first = options.shift
  case first
    when Hash
      super(first.to_hash)
    else
      @system_data[:client] = first
      self.prefix_options ||= @system_data[:client].prefix_options if @system_data[:client].prefix_options
      super(first.attributes)
  end
end

#respond_to?(symbol, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)

75
76
77
78
79
# File 'lib/ticketmaster/common.rb', line 75

def respond_to?(symbol, include_private = false)
  result = super(symbol)
  return true if result or @system_data.nil? or @system_data[:client].nil?
  @system_data[:client].respond_to?(symbol, include_private)
end

#saveObject

Save changes to this project Returns true (success) or false (failure) or nil (no changes)


50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/ticketmaster/common.rb', line 50

def save
  if @system_data and (something = @system_data[:client]) and something.respond_to?(:attributes)
    changes = 0
    something.attributes.each do |k, v|
      if self.send(k) != v
        something.send(k + '=', self.send(k)) 
        changes += 1
      end
    end
    something.save if changes > 0
  else
    raise TicketMaster::Exception.new("#{self.class.name}::#{this_method} method must be implemented by the provider")
  end
end

#update!(*options) ⇒ Object

Update the something and save As opposed to update which just updates the attributes


43
44
45
46
# File 'lib/ticketmaster/common.rb', line 43

def update!(*options)
  update(*options)
  save
end