Class: Dbhero::Dataclip
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Dbhero::Dataclip
- Defined in:
- app/models/dbhero/dataclip.rb
Instance Attribute Summary collapse
-
#q_result ⇒ Object
readonly
Returns the value of attribute q_result.
Instance Method Summary collapse
- #csv_string ⇒ Object
- #description_without_title ⇒ Object
- #query_result ⇒ Object
- #set_token ⇒ Object
- #title ⇒ Object
- #to_param ⇒ Object
- #total_rows ⇒ Object
Instance Attribute Details
#q_result ⇒ Object (readonly)
Returns the value of attribute q_result.
9 10 11 |
# File 'app/models/dbhero/dataclip.rb', line 9 def q_result @q_result end |
Instance Method Details
#csv_string ⇒ Object
42 43 44 45 46 47 48 |
# File 'app/models/dbhero/dataclip.rb', line 42 def csv_string query_result csv = '' csv << "#{@q_result.columns.join(',')}\n" @q_result.rows.each { |row| csv << "#{row.join(',')}\n" } csv end |
#description_without_title ⇒ Object
23 24 25 |
# File 'app/models/dbhero/dataclip.rb', line 23 def description_without_title description.split("\n")[1..-1].join("\n") end |
#query_result ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'app/models/dbhero/dataclip.rb', line 31 def query_result Dataclip.transaction do begin @q_result ||= ActiveRecord::Base.connection.select_all(self.raw_query) rescue => e self.errors.add(:base, e.) end raise ActiveRecord::Rollback end end |
#set_token ⇒ Object
11 12 13 |
# File 'app/models/dbhero/dataclip.rb', line 11 def set_token self.token = SecureRandom.uuid unless self.token end |
#title ⇒ Object
19 20 21 |
# File 'app/models/dbhero/dataclip.rb', line 19 def title description.split("\n")[0] end |
#to_param ⇒ Object
15 16 17 |
# File 'app/models/dbhero/dataclip.rb', line 15 def to_param self.token end |
#total_rows ⇒ Object
27 28 29 |
# File 'app/models/dbhero/dataclip.rb', line 27 def total_rows @total_rows ||= @q_result.rows.length end |