Class: SimpleMDM::App
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from Base
Class Method Details
.all ⇒ Object
11 12 13 14 15 |
# File 'lib/simplemdm/app.rb', line 11 def self.all hash, code = fetch("apps") hash['data'].collect { |d| build d } end |
.find(id) ⇒ Object
17 18 19 20 21 |
# File 'lib/simplemdm/app.rb', line 17 def self.find(id) hash, code = fetch("apps/#{id}") build hash['data'] end |
Instance Method Details
#binary=(val) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/simplemdm/app.rb', line 23 def binary=(val) raise "binary must be a File object" unless val.kind_of? File @dirty = true @binary_file = val end |
#build(hash = nil) ⇒ Object
4 5 6 7 8 9 |
# File 'lib/simplemdm/app.rb', line 4 def build(hash = nil) @dirty = false @binary_data = nil super end |
#destroy ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/simplemdm/app.rb', line 51 def destroy raise "You cannot delete an app that hasn't been created yet." if new? hash, code = fetch("apps/#{self.id}", :delete) code == 204 end |
#save ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/simplemdm/app.rb', line 30 def save if (@dirty || new?) && @binary_file params = { binary: @binary_file } if new? hash, code = fetch("apps", :post, params) self.id = hash['data']['id'] self.merge!(hash['data']['attributes']) else hash, code = fetch("apps/#{self.id}", :patch, params) self.merge!(hash['data']['attributes']) end @dirty = false @binary_file = nil end self end |