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.
11 12 13 |
# File 'app/models/dbhero/dataclip.rb', line 11 def q_result @q_result end |
Instance Method Details
#csv_string ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'app/models/dbhero/dataclip.rb', line 44 def csv_string query_result csv_string = CSV.generate(force_quotes: true, col_sep: Dbhero.csv_delimiter) do |csv| csv << @q_result.columns @q_result.rows.each { |row| csv << row } end csv_string end |
#description_without_title ⇒ Object
25 26 27 |
# File 'app/models/dbhero/dataclip.rb', line 25 def description_without_title description.split("\n")[1..-1].join("\n") end |
#query_result ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'app/models/dbhero/dataclip.rb', line 33 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
13 14 15 |
# File 'app/models/dbhero/dataclip.rb', line 13 def set_token self.token = SecureRandom.uuid unless self.token end |
#title ⇒ Object
21 22 23 |
# File 'app/models/dbhero/dataclip.rb', line 21 def title description.split("\n")[0] end |
#to_param ⇒ Object
17 18 19 |
# File 'app/models/dbhero/dataclip.rb', line 17 def to_param self.token end |
#total_rows ⇒ Object
29 30 31 |
# File 'app/models/dbhero/dataclip.rb', line 29 def total_rows @total_rows ||= @q_result.rows.length end |