Class: PinchHitter::Message::MessageStore

Inherits:
Object
  • Object
show all
Includes:
ContentType, Json, Xml
Defined in:
lib/pinch_hitter/message/message_store.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ContentType

#determine_content_type

Methods included from Json

#json_message, #valid_json?

Methods included from Xml

#xml_message

Constructor Details

#initialize(message_directory) ⇒ MessageStore

Returns a new instance of MessageStore.



13
14
15
# File 'lib/pinch_hitter/message/message_store.rb', line 13

def initialize(message_directory)
  @message_directory = message_directory
end

Instance Attribute Details

#message_directoryObject

Returns the value of attribute message_directory.



11
12
13
# File 'lib/pinch_hitter/message/message_store.rb', line 11

def message_directory
  @message_directory
end

Instance Method Details

#find_filename(file) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/pinch_hitter/message/message_store.rb', line 26

def find_filename(file)
  filename = Dir["#{message_directory}/#{file}*"].first
  unless filename
    fail "Could not find message for '#{file}' in '#{File.expand_path(File.dirname(message_directory))}'"
  end
  filename
end

#load(file, overrides = {}) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/pinch_hitter/message/message_store.rb', line 17

def load(file, overrides={})
  filename = find_filename file
  if filename =~ /xml$/
    xml_message filename, overrides
  else
    json_message filename, overrides
  end
end