Sha256: 9f35573d066c50e2347f717ec448756c2e8e04799c8c81400b106eab582bdcf5
Contents?: true
Size: 853 Bytes
Versions: 4
Compression:
Stored size: 853 Bytes
Contents
module NCore module Create extend ActiveSupport::Concern module ClassMethods def create!(attribs={}, api_creds=nil) obj = create(attribs, api_creds) if obj.errors.any? raise parent::RecordInvalid, obj end obj end # always returns a new object; check .errors? or .valid? to see how it went def create(attribs={}, api_creds=nil) params = {json_root => attribs} parsed, creds = request(:post, url, api_creds, params) new(attribs, creds).send(:load, parsed) end end private def create(attribs={}) params = {json_root => attribs} parsed, @api_creds = request(:post, self.class.url, api_creds, params) load(data: attribs) if parsed[:errors].any? load(parsed) errors.empty? ? self : false end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
ncore-1.2.1 | lib/ncore/methods/create.rb |
ncore-1.2.0 | lib/ncore/methods/create.rb |
ncore-1.1.0 | lib/ncore/methods/create.rb |
ncore-1.0.0 | lib/ncore/methods/create.rb |