Class: Phantomblaster::Models::Script
- Inherits:
-
Object
- Object
- Phantomblaster::Models::Script
- Defined in:
- lib/phantomblaster/models/script.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#last_saved_at ⇒ Object
readonly
Returns the value of attribute last_saved_at.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(params) ⇒ Script
constructor
A new instance of Script.
- #text ⇒ Object
Constructor Details
#initialize(params) ⇒ Script
Returns a new instance of Script.
31 32 33 34 35 36 37 |
# 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 |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
29 30 31 |
# File 'lib/phantomblaster/models/script.rb', line 29 def id @id end |
#last_saved_at ⇒ Object (readonly)
Returns the value of attribute last_saved_at.
29 30 31 |
# File 'lib/phantomblaster/models/script.rb', line 29 def last_saved_at @last_saved_at end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
29 30 31 |
# File 'lib/phantomblaster/models/script.rb', line 29 def name @name end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
29 30 31 |
# File 'lib/phantomblaster/models/script.rb', line 29 def source @source end |
Class Method Details
.all ⇒ Object
14 15 16 17 |
# File 'lib/phantomblaster/models/script.rb', line 14 def self.all data = Phantomblaster::Client.get('/scripts') data.map { |params| new(params) } end |
.find(id) ⇒ Object
4 5 6 7 |
# 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) ⇒ Object
9 10 11 12 |
# 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 |
.upload(name) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# 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 |
Instance Method Details
#text ⇒ Object
39 40 41 |
# File 'lib/phantomblaster/models/script.rb', line 39 def text @text ||= self.class.find(id).instance_variable_get(:@text) end |