module Subledger::Store::Api::Create

Public Instance Methods

create(creatable) click to toggle source
# File lib/subledger/store/api/roles/create.rb, line 5
def create creatable
  unless creatable.id.nil?
    raise CreateError, 'cannot create an object with an :id'
  end

  path = Path.for_collection :anchor => creatable

  begin
    json_body = http.post do |req|
                  req.url    path
                  req.body = creatable.post_hash
                end.body
  rescue Exception => e
    raise CreateError, "Cannot create #{creatable}: #{e}"
  end

  new_or_initialize json_body, creatable
end