Class: EventBright::Discount

Inherits:
ApiObject show all
Defined in:
lib/eventbright/api_objects/discount.rb

Instance Attribute Summary

Attributes inherited from ApiObject

#attributes, #collections, #dirty, #dirty_collections, #dirty_relations, #id, #owner, #relations

Instance Method Summary collapse

Methods inherited from ApiObject

#after_load, #after_update, #api_hash, #attribute_get, #attribute_set, #before_save, #clean!, #dirty?, #get_hash, #init, #init_with_hash, #inspect, #load, #load!, #loaded?, #nested_hash, #preinit, #prep_api_hash, #save, #to_s, #updatable_hash, #update_hash

Methods included from ApiObjectClassMethods

#collection, #collections, #has, #ignores, #plural_name, #readable, #readable_date, #reformats, #relations, #remap, #renames, #requires, #singlet_name, #updatable, #updatable_date

Methods included from ApiObjectRelationships

#collection_clean!, #collection_dirty!, #collection_dirty?, #collection_get, #collection_set, #collections_save, #load_collections_with_hash, #load_relations_with_hash, #relation_clean!, #relation_dirty!, #relation_dirty?, #relation_get, #relation_set, #relations_save, #unnest_child_response

Constructor Details

#initialize(event = nil, hash = {}) ⇒ Discount

Tickets can’t live outside events, so we override standard owner to be event.

Raises:

  • (ArgumentError)


15
16
17
18
19
20
21
22
# File 'lib/eventbright/api_objects/discount.rb', line 15

def initialize(event = nil, hash = {})
  preinit
  raise ArgumentError unless event.is_a? EventBright::Event
  @id = hash.delete(:id)
  @event = event
  @owner = event.owner
  init_with_hash(hash, true)
end

Instance Method Details

#after_attribute_setObject



41
42
43
# File 'lib/eventbright/api_objects/discount.rb', line 41

def after_attribute_set
  @event.dirty_discounts! unless @event.nil?
end

#after_newObject



33
34
35
# File 'lib/eventbright/api_objects/discount.rb', line 33

def after_new
  @event.dirty_discounts!
end

#after_saveObject



37
38
39
# File 'lib/eventbright/api_objects/discount.rb', line 37

def after_save
  @event.dirty_discounts!
end

#amount_off=(val, no_dirty = false) ⇒ Object



45
46
47
48
# File 'lib/eventbright/api_objects/discount.rb', line 45

def amount_off=(val, no_dirty = false)
  attribute_set(:amount_off, val, no_dirty)
  attribute_set(:percent_off, "", no_dirty)
end

#discount_id=(val, no_dirty = false) ⇒ Object



24
25
26
# File 'lib/eventbright/api_objects/discount.rb', line 24

def discount_id=(val, no_dirty = false)
  self.id = val
end

#new_hashObject



28
29
30
# File 'lib/eventbright/api_objects/discount.rb', line 28

def new_hash
  {:event_id => @event.id}
end

#percent_off=(val, no_dirty = false) ⇒ Object



50
51
52
53
# File 'lib/eventbright/api_objects/discount.rb', line 50

def percent_off=(val, no_dirty = false)
  attribute_set(:percent_off, val, no_dirty)
  attribute_set(:amount_off, "", no_dirty)
end