active-list 4.2.4 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/VERSION +1 -1
  3. data/{lib → app}/assets/images/active-list.png +0 -0
  4. data/app/assets/images/active-list.svg +415 -0
  5. data/{lib/assets/javascripts/active-list.jquery.js → app/assets/javascripts/active_list.jquery.js} +2 -2
  6. data/app/assets/stylesheets/active_list.css.scss +7 -0
  7. data/{lib/active-list/compass/stylesheets/active-list/_background.scss → app/assets/stylesheets/active_list/background.scss} +10 -8
  8. data/{lib/active-list/compass/stylesheets/active-list/_minimal.scss → app/assets/stylesheets/active_list/minimal.scss} +16 -16
  9. data/{lib/active-list/compass/stylesheets/active-list/_theme.scss → app/assets/stylesheets/active_list/theme.scss} +37 -37
  10. data/lib/active-list.rb +1 -37
  11. data/lib/active_list.rb +43 -0
  12. data/lib/active_list/action_pack.rb +46 -0
  13. data/lib/active_list/definition.rb +17 -0
  14. data/lib/active_list/definition/abstract_column.rb +54 -0
  15. data/lib/active_list/definition/action_column.rb +76 -0
  16. data/lib/active_list/definition/association_column.rb +80 -0
  17. data/lib/active_list/definition/attribute_column.rb +58 -0
  18. data/lib/active_list/definition/check_box_column.rb +17 -0
  19. data/lib/active_list/definition/data_column.rb +88 -0
  20. data/lib/active_list/definition/empty_column.rb +10 -0
  21. data/lib/active_list/definition/field_column.rb +20 -0
  22. data/lib/active_list/definition/status_column.rb +10 -0
  23. data/lib/active_list/definition/table.rb +159 -0
  24. data/lib/active_list/definition/text_field_column.rb +10 -0
  25. data/lib/active_list/exporters.rb +28 -0
  26. data/lib/active_list/exporters/abstract_exporter.rb +55 -0
  27. data/lib/active_list/exporters/csv_exporter.rb +32 -0
  28. data/lib/active_list/exporters/excel_csv_exporter.rb +38 -0
  29. data/lib/active_list/exporters/open_document_spreadsheet_exporter.rb +82 -0
  30. data/lib/active_list/generator.rb +122 -0
  31. data/lib/active_list/generator/finder.rb +150 -0
  32. data/lib/active_list/helpers.rb +33 -0
  33. data/lib/{active-list → active_list}/rails/engine.rb +3 -2
  34. data/lib/active_list/renderers.rb +25 -0
  35. data/lib/active_list/renderers/abstract_renderer.rb +29 -0
  36. data/lib/active_list/renderers/simple_renderer.rb +356 -0
  37. metadata +74 -55
  38. data/lib/active-list/action_pack.rb +0 -48
  39. data/lib/active-list/columns/action_column.rb +0 -83
  40. data/lib/active-list/columns/data_column.rb +0 -151
  41. data/lib/active-list/columns/field_column.rb +0 -29
  42. data/lib/active-list/compass/stylesheets/_active-list.scss +0 -7
  43. data/lib/active-list/definition.rb +0 -103
  44. data/lib/active-list/exporters.rb +0 -71
  45. data/lib/active-list/exporters/csv_exporter.rb +0 -30
  46. data/lib/active-list/exporters/excel_csv_exporter.rb +0 -36
  47. data/lib/active-list/exporters/open_document_spreadsheet_exporter.rb +0 -81
  48. data/lib/active-list/finder.rb +0 -134
  49. data/lib/active-list/generator.rb +0 -88
  50. data/lib/active-list/renderers.rb +0 -28
  51. data/lib/active-list/renderers/simple_renderer.rb +0 -335
  52. data/lib/assets/stylesheets/active-list.css.scss +0 -7
@@ -1,29 +0,0 @@
1
- module ActiveList
2
-
3
- class Table
4
-
5
- # Add a new method in Table which permit to define text_field columns
6
- def text_field(name, options={})
7
- @columns << TextFieldColumn.new(self, name, options)
8
- end
9
-
10
- # Add a new method in Table which permit to define check_box columns
11
- def check_box(name, options={})
12
- @columns << CheckBoxColumn.new(self, name, options)
13
- end
14
-
15
- end
16
-
17
- class FieldColumn < Column
18
- def header_code
19
- "#{@table.model.name}.human_attribute_name('#{@name}')"
20
- end
21
- end
22
-
23
- class TextFieldColumn < FieldColumn
24
- end
25
-
26
- class CheckBoxColumn < FieldColumn
27
- end
28
-
29
- end
@@ -1,7 +0,0 @@
1
- @import "active-list/minimal";
2
- @import "active-list/background";
3
- @import "active-list/theme";
4
-
5
- .active-list[data-list-source], .active-list {
6
- @include active-list-theme;
7
- }
@@ -1,103 +0,0 @@
1
- module ActiveList
2
-
3
- class Table
4
- attr_reader :name, :model, :options, :id, :columns, :parameters
5
-
6
- @@current_id = 0
7
-
8
- def initialize(name, model = nil, options = {})
9
- @name = name
10
- @model = model || name.to_s.classify.constantize
11
- @options = options
12
- @paginate = !(@options[:pagination]==:none || @options[:paginate].is_a?(FalseClass))
13
- @options[:renderer] ||= :simple_renderer
14
- @options[:per_page] = 20 if @options[:per_page].to_i <= 0
15
- @options[:page] = 1 if @options[:page].to_i <= 0
16
- @columns = []
17
- @current_id = 0
18
- @id = @@current_id.to_s(36).to_sym
19
- @@current_id += 1
20
- @parameters = {:sort=>:to_s, :dir=>:to_s}
21
- @parameters.merge!(:page=>:to_i, :per_page=>:to_i) if self.paginate?
22
- end
23
-
24
- def new_id
25
- id = @current_id.to_s(36).to_sym
26
- @current_id += 1
27
- return id
28
- end
29
-
30
- def model_columns
31
- @model.columns
32
- end
33
-
34
- def sortable_columns
35
- @columns.select{|c| c.sortable?}
36
- end
37
-
38
- def exportable_columns
39
- @columns.select{|c| c.exportable?}
40
- end
41
-
42
- def paginate?
43
- @paginate
44
- end
45
-
46
- def load_default_columns
47
- for column in self.model_columns
48
- reflections = @model.reflections.values.select{|r| r.macro == :belongs_to and r.foreign_key.to_s == column.name.to_s}
49
- if reflections.size == 1
50
- reflection = reflections.first
51
- columns = reflection.class_name.constantize.columns.collect{ |c| c.name.to_s }
52
- self.column([:label, :name, :code, :number].detect{ |l| columns.include?(l.to_s) }, :through => reflection.name, :url => true)
53
- else
54
- self.column(column.name)
55
- end
56
- end
57
- return true
58
- end
59
-
60
- end
61
-
62
-
63
- class Column
64
- attr_accessor :name, :options, :table
65
- attr_reader :id
66
-
67
- def initialize(table, name, options={})
68
- @table = table
69
- @name = name
70
- @options = options
71
- @column = @table.model.columns.detect{|c| c.name.to_s == @name.to_s }
72
- @id = @table.new_id
73
- end
74
-
75
- def header_code
76
- raise NotImplementedError.new("#{self.class.name}#header_code is not implemented.")
77
- end
78
-
79
- def sortable?
80
- false
81
- end
82
-
83
- def exportable?
84
- false
85
- end
86
-
87
- # Unique identifier of the column in the application
88
- def unique_id
89
- "#{@table.name}-#{@id}"
90
- end
91
-
92
- # Uncommon but simple identifier for CSS class uses
93
- def simple_id
94
- "_#{@table.id}_#{@id}"
95
- end
96
-
97
- end
98
-
99
- end
100
-
101
- require "active-list/columns/data_column"
102
- require "active-list/columns/action_column"
103
- require "active-list/columns/field_column"
@@ -1,71 +0,0 @@
1
- require 'active_support/core_ext/module/attribute_accessors'
2
-
3
- module ActiveList
4
-
5
- mattr_reader :exporters
6
- @@exporters = {}
7
-
8
- def self.register_exporter(name, exporter)
9
- raise ArgumentError.new("ActiveList::Exporter expected (got #{exporter.name}/#{exporter.ancestors.inspect})") unless exporter.ancestors.include? ActiveList::Exporter
10
- @@exporters[name] = exporter.new(name)
11
- end
12
-
13
- class Exporter
14
- attr_reader :name
15
-
16
- def initialize(name)
17
- @name = name
18
- end
19
-
20
- def file_extension
21
- "txt"
22
- end
23
-
24
- def mime_type
25
- Mime::TEXT
26
- end
27
-
28
- # Not used
29
- # def condition
30
- # "not request.xhr? and params[:format] == '#{name}'"
31
- # end
32
-
33
- def send_data_code(table)
34
- raise NotImplementedError.new("#{self.class.name}#format_data_code is not implemented.")
35
- end
36
-
37
- def columns_headers(table, options={})
38
- headers, columns = [], table.exportable_columns
39
- for column in columns
40
- datum = column.header_code
41
- headers << (options[:encoding] ? datum+".to_s.encode('#{options[:encoding]}')" : datum)
42
- end
43
- return headers
44
- end
45
-
46
- def columns_to_array(table, nature, options={})
47
- columns = table.exportable_columns
48
-
49
- array = []
50
- record = options[:record]||'rekord'
51
- for column in columns
52
- if column.is_a? ActiveList::Column
53
- if nature==:header
54
- datum = column.header_code
55
- else
56
- datum = column.exporting_datum_code(record)
57
- end
58
- array << (options[:encoding] ? datum+".to_s.encode('#{options[:encoding]}')" : datum)
59
- end
60
- end
61
- return array
62
- end
63
-
64
- end
65
-
66
- end
67
-
68
-
69
- require "active-list/exporters/open_document_spreadsheet_exporter"
70
- require "active-list/exporters/csv_exporter"
71
- require "active-list/exporters/excel_csv_exporter"
@@ -1,30 +0,0 @@
1
- module ActiveList
2
-
3
- class CsvExporter < ActiveList::Exporter
4
-
5
- def file_extension
6
- "csv"
7
- end
8
-
9
- def mime_type
10
- Mime::CSV
11
- end
12
-
13
- def send_data_code(table)
14
- record = "r"
15
- code = table.select_data_code(:paginate => false)
16
- code += "data = ActiveList::CSV.generate do |csv|\n"
17
- code += " csv << [#{columns_to_array(table, :header).join(', ')}]\n"
18
- code += " for #{record} in #{table.records_variable_name}\n"
19
- code += " csv << [#{columns_to_array(table, :body, :record=>record).join(', ')}]\n"
20
- code += " end\n"
21
- code += "end\n"
22
- code += "send_data(data, :type=>#{self.mime_type.to_s.inspect}, :disposition=>'inline', :filename=>#{table.model.name}.model_name.human.gsub(/[^a-z0-9]/i,'_')+'.#{self.file_extension}')\n"
23
- return code
24
- end
25
-
26
- end
27
-
28
- end
29
-
30
- ActiveList.register_exporter(:csv, ActiveList::CsvExporter)
@@ -1,36 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- # Register XCSV format unless is already set
4
- Mime::Type.register("text/csv", :xcsv) unless defined? Mime::XCSV
5
-
6
- module ActiveList
7
-
8
- class ExcelCsvExporter < ActiveList::CsvExporter
9
-
10
- def file_extension
11
- "csv"
12
- end
13
-
14
- def mime_type
15
- Mime::XCSV
16
- end
17
-
18
- def send_data_code(table)
19
- record = "r"
20
- code = table.select_data_code(:paginate => false)
21
- encoding = "CP1252"
22
- code << "data = ActiveList::CSV.generate(:col_sep => ';') do |csv|\n"
23
- code << " csv << [#{columns_to_array(table, :header, :encoding => encoding).join(', ')}]\n"
24
- code << " for #{record} in #{table.records_variable_name}\n"
25
- code << " csv << [#{columns_to_array(table, :body, :record =>record, :encoding => encoding).join(', ')}]\n"
26
- code << " end\n"
27
- code << "end\n"
28
- code << "send_data(data, :type => #{self.mime_type.to_s.inspect}, :disposition => 'inline', :filename => #{table.model.name}.model_name.human.gsub(/[^a-z0-9]/i,'_')+'.#{self.file_extension}')\n"
29
- return code
30
- end
31
-
32
- end
33
-
34
- end
35
-
36
- ActiveList.register_exporter(:xcsv, ActiveList::ExcelCsvExporter)
@@ -1,81 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- # Register ODS format unless is already set
4
- Mime::Type.register("application/vnd.oasis.opendocument.spreadsheet", :ods) unless defined? Mime::ODS
5
-
6
- module ActiveList
7
-
8
- class OpenDocumentSpreadsheetExporter < ActiveList::Exporter
9
-
10
- DATE_ELEMENTS = {
11
- "m" => "<number:month number:style=\"long\"/>",
12
- "d" => "<number:day number:style=\"long\"/>",
13
- "Y" => "<number:year/>"
14
- }
15
-
16
-
17
- def file_extension
18
- "ods"
19
- end
20
-
21
- def mime_type
22
- Mime::ODS
23
- end
24
-
25
- def send_data_code(table)
26
- xml_escape = "to_s.gsub('&', '&amp;').gsub('\\'', '&apos;').gsub('<', '&lt;').gsub('>', '&gt;')"
27
- xml_escape << ".force_encoding('US-ASCII')" if xml_escape.respond_to?(:force_encoding)
28
- record = "r"
29
- code = table.select_data_code(:paginate => false)
30
- code << "name = #{table.model.name}.model_name.human.gsub(/[^a-z0-9]/i,'_')\n"
31
- code << "temporary_dir = ::Rails.root.join('tmp', 'active-list')\n"
32
- code << "FileUtils.mkdir_p(temporary_dir)\n"
33
- code << "file = temporary_dir.join(name+rand.to_s+'.#{self.file_extension}')\n"
34
- code << "Zip::ZipOutputStream.open(file) do |zile|\n"
35
- # MimeType in first place
36
- code << " zile.put_next_entry('mimetype', nil, nil, Zip::ZipEntry::STORED)\n"
37
- code << " zile << '#{self.mime_type}'\n"
38
-
39
- # Manifest
40
- code << " zile.put_next_entry('META-INF/manifest.xml')\n"
41
- code << " zile << ('<?xml version=\"1.0\" encoding=\"UTF-8\"?><manifest:manifest xmlns:manifest=\"urn:oasis:names:tc:opendocument:xmlns:manifest:1.0\"><manifest:file-entry manifest:media-type=\"#{self.mime_type}\" manifest:full-path=\"/\"/><manifest:file-entry manifest:media-type=\"text/xml\" manifest:full-path=\"content.xml\"/></manifest:manifest>')\n"
42
- code << " zile.put_next_entry('content.xml')\n"
43
-
44
- code << " zile << ('<?xml version=\"1.0\" encoding=\"UTF-8\"?><office:document-content xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\" xmlns:style=\"urn:oasis:names:tc:opendocument:xmlns:style:1.0\" xmlns:text=\"urn:oasis:names:tc:opendocument:xmlns:text:1.0\" xmlns:table=\"urn:oasis:names:tc:opendocument:xmlns:table:1.0\" xmlns:draw=\"urn:oasis:names:tc:opendocument:xmlns:drawing:1.0\" xmlns:fo=\"urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:meta=\"urn:oasis:names:tc:opendocument:xmlns:meta:1.0\" xmlns:number=\"urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0\" xmlns:presentation=\"urn:oasis:names:tc:opendocument:xmlns:presentation:1.0\" xmlns:svg=\"urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0\" xmlns:chart=\"urn:oasis:names:tc:opendocument:xmlns:chart:1.0\" xmlns:dr3d=\"urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0\" xmlns:math=\"http://www.w3.org/1998/Math/MathML\" xmlns:form=\"urn:oasis:names:tc:opendocument:xmlns:form:1.0\" xmlns:script=\"urn:oasis:names:tc:opendocument:xmlns:script:1.0\" xmlns:ooo=\"http://openoffice.org/2004/office\" xmlns:ooow=\"http://openoffice.org/2004/writer\" xmlns:oooc=\"http://openoffice.org/2004/calc\" xmlns:dom=\"http://www.w3.org/2001/xml-events\" xmlns:xforms=\"http://www.w3.org/2002/xforms\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:field=\"urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:field:1.0\" office:version=\"1.1\"><office:scripts/>')\n"
45
- # Styles
46
- code << " zile << ('<office:automatic-styles>"+
47
- "<style:style style:name=\"co1\" style:family=\"table-column\"><style:table-column-properties fo:break-before=\"auto\" style:use-optimal-column-width=\"true\"/></style:style>"+
48
- "<style:style style:name=\"header\" style:family=\"table-cell\"><style:text-properties fo:font-weight=\"bold\" style:font-weight-asian=\"bold\" style:font-weight-complex=\"bold\"/></style:style>"+
49
- "<number:date-style style:name=\"K4D\" number:automatic-order=\"true\"><number:text>"+::I18n.translate("date.formats.default").gsub(/\%./){|x| "</number:text>"+DATE_ELEMENTS[x[1..1]]+"<number:text>"} +"</number:text></number:date-style><style:style style:name=\"ce1\" style:family=\"table-cell\" style:data-style-name=\"K4D\"/>"+
50
- "</office:automatic-styles>')\n"
51
-
52
- # Tables
53
- code << " zile << ('<office:body><office:spreadsheet><table:table table:name=\"'+#{table.model.name}.model_name.human.#{xml_escape}+'\">')\n"
54
- code << " zile << ('<table:table-column table:number-columns-repeated=\"#{table.exportable_columns.size}\"/>')\n"
55
- code << " zile << ('<table:table-header-rows><table:table-row>"+columns_headers(table).collect{|h| "<table:table-cell table:style-name=\"header\" office:value-type=\"string\"><text:p>'+(#{h}).#{xml_escape}+'</text:p></table:table-cell>"}.join+"</table:table-row></table:table-header-rows>')\n"
56
- code << " for #{record} in #{table.records_variable_name}\n"
57
- code << " zile << ('<table:table-row>"+table.exportable_columns.collect do |column|
58
- "<table:table-cell"+(if column.numeric? or column.datatype==:decimal
59
- " office:value-type=\"float\" office:value=\"'+(#{column.datum_code(record)}).#{xml_escape}+'\""
60
- elsif column.datatype==:boolean
61
- " office:value-type=\"boolean\" office:boolean-value=\"'+(#{column.datum_code(record)}).#{xml_escape}+'\""
62
- elsif column.datatype==:date
63
- " office:value-type=\"date\" table:style-name=\"ce1\" office:date-value=\"'+(#{column.datum_code(record)}).#{xml_escape}+'\""
64
- else
65
- " office:value-type=\"string\""
66
- end)+"><text:p>'+("+column.exporting_datum_code(record, true)+").#{xml_escape}+'</text:p></table:table-cell>"
67
- end.join+"</table:table-row>')\n"
68
- code << " end\n"
69
- code << " zile << ('</table:table></office:spreadsheet></office:body></office:document-content>')\n"
70
- code << "end\n"
71
- code << "send_file(file, :stream=>false, :type=>#{self.mime_type.to_s.inspect}, :disposition=>'inline', :filename=>name+'.#{self.file_extension}')\n"
72
- code << "File.delete(file)\n" # Removes tmp files before they explode the disk
73
- # raise code
74
- return code
75
- end
76
-
77
- end
78
-
79
- end
80
-
81
- ActiveList.register_exporter(:ods, ActiveList::OpenDocumentSpreadsheetExporter)
@@ -1,134 +0,0 @@
1
- module ActiveList
2
-
3
- # Manage data query
4
- class Table
5
-
6
- # Generate select code for the table taking all parameters in account
7
- def select_data_code(options = {})
8
- paginate = (options.has_key?(:paginate) ? options[:paginate] : self.paginate?)
9
- # Check order
10
- unless self.options.keys.include?(:order)
11
- columns = self.table_columns
12
- if columns.size > 0
13
- self.options[:order] = columns[0].name.to_s # self.model.connection.quote_column_name(columns[0].name.to_s)
14
- else
15
- # raise ArgumentError.new("Option :order is needed for the list :#{self.name}")
16
- self.options[:order] = "id DESC"
17
- end
18
- end
19
-
20
- # Find data
21
- query_code = "#{self.model.name}"
22
- query_code << ".select(#{self.select_code})" if self.select_code
23
- query_code << ".where(#{self.conditions_code})" unless self.options[:conditions].blank?
24
- query_code << ".joins(#{self.options[:joins].inspect})" unless self.options[:joins].blank?
25
- query_code << ".includes(#{self.includes_hash.inspect})" unless self.includes_hash.empty?
26
-
27
- code = ""
28
- code << "#{self.records_variable_name}_count = #{query_code}.count\n"
29
- if paginate
30
- code << "#{self.records_variable_name}_limit = (list_params[:per_page]||25).to_i\n"
31
- code << "#{self.records_variable_name}_page = (list_params[:page]||1).to_i\n"
32
- code << "#{self.records_variable_name}_page = 1 if #{self.records_variable_name}_page < 1\n"
33
- code << "#{self.records_variable_name}_offset = (#{self.records_variable_name}_page-1)*#{self.records_variable_name}_limit\n"
34
- code << "#{self.records_variable_name}_last = (#{self.records_variable_name}_count.to_f/#{self.records_variable_name}_limit).ceil.to_i\n"
35
- code << "#{self.records_variable_name}_last = 1 if #{self.records_variable_name}_last < 1\n"
36
- code << "return #{self.view_method_name}(options.merge(:page=>1)) if 1 > #{self.records_variable_name}_page\n"
37
- code << "return #{self.view_method_name}(options.merge(:page=>#{self.records_variable_name}_last)) if #{self.records_variable_name}_page > #{self.records_variable_name}_last\n"
38
- end
39
- code << "#{self.records_variable_name} = #{query_code}"
40
- if paginate
41
- code << ".offset(#{self.records_variable_name}_offset)"
42
- code << ".limit(#{self.records_variable_name}_limit)"
43
- end
44
- code << ".reorder(order)||{}\n"
45
- return code
46
- end
47
-
48
- protected
49
-
50
- # Compute includes Hash
51
- def includes_hash
52
- hash = {}
53
- for column in self.columns
54
- if through = column.options[:through]
55
- through = [through] unless through.is_a? Array
56
- h = hash
57
- for x in through
58
- h[x] = {} unless h[x].is_a? Hash
59
- h = h[x]
60
- end
61
- end
62
- end
63
- return hash
64
- end
65
-
66
-
67
- # Generate the code from a conditions option
68
- def conditions_code
69
- conditions = self.options[:conditions]
70
- code = ''
71
- case conditions
72
- when Array
73
- case conditions[0]
74
- when String # SQL
75
- code += '["'+conditions[0].to_s+'"'
76
- code += ', '+conditions[1..-1].collect{|p| sanitize_condition(p)}.join(', ') if conditions.size>1
77
- code += ']'
78
- when Symbol # Method
79
- code += conditions[0].to_s+'('
80
- code += conditions[1..-1].collect{|p| sanitize_condition(p)}.join(', ') if conditions.size>1
81
- code += ')'
82
- else
83
- raise ArgumentError.new("First element of an Array can only be String or Symbol.")
84
- end
85
- when Hash # SQL
86
- code += '{'+conditions.collect{|key, value| ':'+key.to_s+'=>'+sanitize_condition(value)}.join(',')+'}'
87
- when Symbol # Method
88
- code += conditions.to_s+"(options)"
89
- when String
90
- code += "("+conditions.gsub(/\s*\n\s*/,';')+")"
91
- else
92
- raise ArgumentError.new("Unsupported type for conditions: #{conditions.inspect}")
93
- end
94
- return code
95
- end
96
-
97
- def select_code
98
- return nil unless self.options[:distinct] or self.options[:select]
99
- code = ""
100
- code << "DISTINCT " if self.options[:distinct]
101
- code << "#{self.model.table_name}.*"
102
- if self.options[:select]
103
- code << self.options[:select].collect{|k, v| ", #{k[0].to_s+'.'+k[1].to_s} AS #{v}" }.join
104
- end
105
- return "'"+code+"'"
106
- end
107
-
108
-
109
- def sanitize_condition(value)
110
- if value.is_a? Array
111
- if value.size==1 and value[0].is_a? String
112
- value[0].to_s
113
- else
114
- value.inspect
115
- end
116
- elsif value.is_a? String
117
- '"'+value.gsub('"','\"')+'"'
118
- elsif [Date, DateTime].include? value.class
119
- '"'+value.to_formatted_s(:db)+'"'
120
- elsif value.is_a? NilClass
121
- 'nil'
122
- else
123
- value.to_s
124
- end
125
- end
126
-
127
-
128
- end
129
-
130
-
131
- end
132
-
133
-
134
-