Module: ActiveRecord::Persistence::ClassMethods

Defined in:
ext/active_record/persistence.rb

Instance Method Summary collapse

Instance Method Details

#rpc(name) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'ext/active_record/persistence.rb', line 6

def rpc(name)
  define_method("#{name}!") do
    req = Net::HTTP::Post.new("/#{self.class.table_name}/#{CGI.escape(id.to_s)}/#{CGI.escape(name.to_s)}")
    self.class.connection.send(:with_raw_connection) do |conn|
      conn.send_request(req) do |response|
        JSON.parse(response.body).each do |k,v|
          if self.class.column_names.include?(k)
            @attributes.write_from_database(k, v)
          end
        end
      end
    end
    true
  end
end