Class: SimpleMDM::App
Class Method Summary collapse
Instance Method Summary collapse
- #binary=(val) ⇒ Object
- #build(hash = nil) ⇒ Object
- #destroy ⇒ Object
- #name=(val) ⇒ Object
- #save ⇒ Object
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
60 61 62 63 64 65 66 |
# File 'lib/simplemdm/app.rb', line 60 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 |
#name=(val) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/simplemdm/app.rb', line 30 def name=(val) if val != self.name @dirty = true end self['name'] = val end |
#save ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/simplemdm/app.rb', line 38 def save if @dirty || new? params = {} params[:name] = self.name params[:binary] = @binary_file unless @binary_file.nil? 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) end @dirty = false @binary_file = nil end self end |