class Phantomblaster::Models::Script
Attributes
id[R]
last_saved_at[R]
name[R]
source[R]
Public Class Methods
all()
click to toggle source
# File lib/phantomblaster/models/script.rb, line 14 def self.all data = Phantomblaster::Client.get('/scripts') data.map { |params| new(params) } end
find(id)
click to toggle source
# File lib/phantomblaster/models/script.rb, line 4 def self.find(id) data = Phantomblaster::Client.get("/script/by-id/json/#{id}", withoutText: false) new(data) end
find_by_name(name)
click to toggle source
# File lib/phantomblaster/models/script.rb, line 9 def self.find_by_name(name) data = Phantomblaster::Client.get("/script/by-name/json/#{name}", withoutText: false) new(data) end
new(params)
click to toggle source
# File lib/phantomblaster/models/script.rb, line 31 def initialize(params) @id = params['id'] @name = params['name'] @source = params['source'] @last_saved_at = params['lastSaveDate'] @text = params['text'].to_s end
upload(name)
click to toggle source
# File lib/phantomblaster/models/script.rb, line 19 def self.upload(name) pathname = Pathname.new("#{Phantomblaster.configuration.scripts_dir}/#{name}") raise MissingFileError, "#{pathname.realdirpath} not found" unless pathname.file? text = pathname.open(&:read) Phantomblaster::Client.post("/script/#{name}", text: text, insertOnly: false, source: :phantomblaster) end
Public Instance Methods
text()
click to toggle source
# File lib/phantomblaster/models/script.rb, line 39 def text @text ||= self.class.find(id).instance_variable_get(:@text) end