Class: Rapid::Baps::Responses::Handlers::ItemLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/ury_rapid/baps/responses/handlers/loader.rb

Overview

A method object for loading an Item object into the model

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, id, item, load_state, urls) ⇒ ItemLoader

Returns a new instance of ItemLoader


46
47
48
49
50
51
52
# File 'lib/ury_rapid/baps/responses/handlers/loader.rb', line 46

def initialize(parent, id, item, load_state, urls)
  @parent = parent
  @id = id
  @item = item
  @load_state = load_state
  @urls = urls
end

Class Method Details

.load(*args) ⇒ Object


42
43
44
# File 'lib/ury_rapid/baps/responses/handlers/loader.rb', line 42

def self.load(*args)
  new(*args).run
end

.targets?Boolean

Stop handler loaders from trying to load handlers from this class.

Returns:

  • (Boolean)

38
39
40
# File 'lib/ury_rapid/baps/responses/handlers/loader.rb', line 38

def self.targets?
  false
end

Instance Method Details

#insertObject


67
68
69
# File 'lib/ury_rapid/baps/responses/handlers/loader.rb', line 67

def insert
  @parent.insert(@urls[:insert], @id, @item)
end

#insert_or_killObject


59
60
61
# File 'lib/ury_rapid/baps/responses/handlers/loader.rb', line 59

def insert_or_kill
  @item.nil? ? kill : insert
end

#killObject


63
64
65
# File 'lib/ury_rapid/baps/responses/handlers/loader.rb', line 63

def kill
  @parent.kill_if_exists(@urls[:kill])
end

#runObject


54
55
56
57
# File 'lib/ury_rapid/baps/responses/handlers/loader.rb', line 54

def run
  insert_or_kill if @urls[:insert] || @urls[:kill]
  set_load_state if @urls[:load_state]
end

#set_load_stateObject


71
72
73
# File 'lib/ury_rapid/baps/responses/handlers/loader.rb', line 71

def set_load_state
  @parent.replace(@urls[:load_state], @load_state)
end