Class: SimpleMDM::App
Class Method Summary collapse
Instance Method Summary collapse
- #binary=(val) ⇒ Object
- #build(hash = nil) ⇒ Object
- #destroy ⇒ Object
-
#initialize(source_hash = nil, default = nil, &blk) ⇒ App
constructor
overwrite base class.
- #name=(val) ⇒ Object
- #save ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(source_hash = nil, default = nil, &blk) ⇒ App
overwrite base class
5 6 7 8 9 10 11 12 |
# File 'lib/simplemdm/app.rb', line 5 def initialize(source_hash = nil, default = nil, &blk) if source_hash && source_hash.kind_of?(Hash) && binary = source_hash[:binary] self.binary = binary source_hash.delete(:binary) end super(source_hash, detault, &blk) end |
Class Method Details
.all ⇒ Object
21 22 23 24 25 |
# File 'lib/simplemdm/app.rb', line 21 def self.all hash, code = fetch("apps") hash['data'].collect { |d| build d } end |
.find(id) ⇒ Object
27 28 29 30 31 |
# File 'lib/simplemdm/app.rb', line 27 def self.find(id) hash, code = fetch("apps/#{id}") build hash['data'] end |
Instance Method Details
#binary=(val) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/simplemdm/app.rb', line 33 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
14 15 16 17 18 19 |
# File 'lib/simplemdm/app.rb', line 14 def build(hash = nil) @dirty = false @binary_file = nil super end |
#destroy ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/simplemdm/app.rb', line 73 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
40 41 42 43 44 45 46 |
# File 'lib/simplemdm/app.rb', line 40 def name=(val) if val != self.name @dirty = true end self['name'] = val end |
#save ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/simplemdm/app.rb', line 48 def save raise "binary must be set before saving" if new? && @binary_file.nil? if @dirty || new? params = {} params[:name] = self.name unless self.name.nil? params[:binary] = @binary_file if @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 |