Module: Musashi::Publisher

Included in:
Musashi
Defined in:
lib/musashi/publisher.rb

Defined Under Namespace

Modules: WWWFormUrlencoded

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/musashi/publisher.rb', line 8

def method_missing(sym,*args,&block)
  super if block_given?
  match = /(?<field>.+)=$/.match(sym.to_s)
  super if match.nil? or match.size != 2
  field = match[:field] 
  attrs[field] = attributes[field] = args.first
end

Class Method Details

.marshall(format, class_or_module) ⇒ Object



35
36
37
# File 'lib/musashi/publisher.rb', line 35

def self.marshall(format,class_or_module)
  marshalls[format] = class_or_module
end

.marshallsObject



31
32
33
# File 'lib/musashi/publisher.rb', line 31

def self.marshalls
  @@marashalls ||= {}
end

Instance Method Details

#attributesObject



4
5
6
# File 'lib/musashi/publisher.rb', line 4

def attributes
  @attributes ||= {}
end

#post(headers = {}) ⇒ Object



21
22
23
24
# File 'lib/musashi/publisher.rb', line 21

def post(headers={})
  payload, headers = post_or_put_prepare(headers)
  connection.post(connection.path_prefix, payload, headers)
end

#put(headers = {}) ⇒ Object



26
27
28
29
# File 'lib/musashi/publisher.rb', line 26

def put(headers={})
  payload, headers = post_or_put_prepare(headers)
  connection.put(connection.path_prefix, payload, headers)
end

#update_attributes(fields) ⇒ Object



16
17
18
19
# File 'lib/musashi/publisher.rb', line 16

def update_attributes(fields)
  self.attrs.merge!(fields)
  self.attributes.merge!(fields)
end