Class: ThinkingSphinx::ActiveRecord::SQLSource
- Inherits:
-
Riddle::Configuration::SQLSource
- Object
- Riddle::Configuration::SQLSource
- ThinkingSphinx::ActiveRecord::SQLSource
- Includes:
- Core::Settings
- Defined in:
- lib/thinking_sphinx/active_record/sql_source.rb
Defined Under Namespace
Classes: Template
Constant Summary collapse
- OPTIONS =
[:name, :offset, :delta_processor, :delta?, :delta_options, :disable_range?, :group_concat_max_len, :utf8?, :position, :minimal_group_by?, :big_document_ids]
Instance Attribute Summary collapse
-
#associations ⇒ Object
Returns the value of attribute associations.
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#conditions ⇒ Object
Returns the value of attribute conditions.
-
#fields ⇒ Object
Returns the value of attribute fields.
-
#groupings ⇒ Object
Returns the value of attribute groupings.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#polymorphs ⇒ Object
Returns the value of attribute polymorphs.
Instance Method Summary collapse
- #adapter ⇒ Object
- #add_attribute(attribute) ⇒ Object
- #add_field(field) ⇒ Object
- #delta? ⇒ Boolean
- #delta_processor ⇒ Object
- #disable_range? ⇒ Boolean
- #facets ⇒ Object
-
#initialize(model, options = {}) ⇒ SQLSource
constructor
A new instance of SQLSource.
- #offset ⇒ Object
- #primary_key ⇒ Object
- #properties ⇒ Object
- #render ⇒ Object
- #set_database_settings(settings) ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(model, options = {}) ⇒ SQLSource
Returns a new instance of SQLSource.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/thinking_sphinx/active_record/sql_source.rb', line 16 def initialize(model, = {}) @model = model @options = { :utf8? => (database_settings[:encoding].to_s[/^utf8/]) }.merge @fields = [] @attributes = [] @associations = [] @conditions = [] @groupings = [] @polymorphs = [] Template.new(self).apply name = "#{[:name] || model.name.downcase}_#{[:position]}" super name, type apply_defaults! end |
Instance Attribute Details
#associations ⇒ Object
Returns the value of attribute associations.
9 10 11 |
# File 'lib/thinking_sphinx/active_record/sql_source.rb', line 9 def associations @associations end |
#attributes ⇒ Object
Returns the value of attribute attributes.
9 10 11 |
# File 'lib/thinking_sphinx/active_record/sql_source.rb', line 9 def attributes @attributes end |
#conditions ⇒ Object
Returns the value of attribute conditions.
9 10 11 |
# File 'lib/thinking_sphinx/active_record/sql_source.rb', line 9 def conditions @conditions end |
#fields ⇒ Object
Returns the value of attribute fields.
9 10 11 |
# File 'lib/thinking_sphinx/active_record/sql_source.rb', line 9 def fields @fields end |
#groupings ⇒ Object
Returns the value of attribute groupings.
9 10 11 |
# File 'lib/thinking_sphinx/active_record/sql_source.rb', line 9 def groupings @groupings end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
8 9 10 |
# File 'lib/thinking_sphinx/active_record/sql_source.rb', line 8 def model @model end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/thinking_sphinx/active_record/sql_source.rb', line 8 def @options end |
#polymorphs ⇒ Object
Returns the value of attribute polymorphs.
9 10 11 |
# File 'lib/thinking_sphinx/active_record/sql_source.rb', line 9 def polymorphs @polymorphs end |
Instance Method Details
#adapter ⇒ Object
38 39 40 |
# File 'lib/thinking_sphinx/active_record/sql_source.rb', line 38 def adapter @adapter ||= DatabaseAdapters.adapter_for(@model) end |
#add_attribute(attribute) ⇒ Object
42 43 44 45 46 |
# File 'lib/thinking_sphinx/active_record/sql_source.rb', line 42 def add_attribute(attribute) attributes.delete_if { |existing| existing.name == attribute.name } attributes << attribute end |
#add_field(field) ⇒ Object
48 49 50 51 52 |
# File 'lib/thinking_sphinx/active_record/sql_source.rb', line 48 def add_field(field) fields.delete_if { |existing| existing.name == field.name } fields << field end |
#delta? ⇒ Boolean
58 59 60 |
# File 'lib/thinking_sphinx/active_record/sql_source.rb', line 58 def delta? [:delta?] end |
#delta_processor ⇒ Object
54 55 56 |
# File 'lib/thinking_sphinx/active_record/sql_source.rb', line 54 def delta_processor [:delta_processor].try(:new, adapter, @options[:delta_options] || {}) end |
#disable_range? ⇒ Boolean
62 63 64 |
# File 'lib/thinking_sphinx/active_record/sql_source.rb', line 62 def disable_range? [:disable_range?] end |
#facets ⇒ Object
66 67 68 |
# File 'lib/thinking_sphinx/active_record/sql_source.rb', line 66 def facets properties.select(&:facet?) end |
#offset ⇒ Object
70 71 72 |
# File 'lib/thinking_sphinx/active_record/sql_source.rb', line 70 def offset [:offset] end |
#primary_key ⇒ Object
74 75 76 |
# File 'lib/thinking_sphinx/active_record/sql_source.rb', line 74 def primary_key [:primary_key] end |
#properties ⇒ Object
78 79 80 |
# File 'lib/thinking_sphinx/active_record/sql_source.rb', line 78 def properties fields + attributes end |
#render ⇒ Object
82 83 84 85 86 |
# File 'lib/thinking_sphinx/active_record/sql_source.rb', line 82 def render prepare_for_render unless @prepared super end |
#set_database_settings(settings) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/thinking_sphinx/active_record/sql_source.rb', line 88 def set_database_settings(settings) @sql_host ||= settings[:host] || 'localhost' @sql_user ||= settings[:username] || settings[:user] || ENV['USER'] @sql_pass ||= settings[:password].to_s.gsub('#', '\#') @sql_db ||= settings[:database] @sql_port ||= settings[:port] @sql_sock ||= settings[:socket] @mysql_ssl_cert ||= settings[:sslcert] @mysql_ssl_key ||= settings[:sslkey] @mysql_ssl_ca ||= settings[:sslca] end |
#type ⇒ Object
100 101 102 103 104 105 106 107 108 109 |
# File 'lib/thinking_sphinx/active_record/sql_source.rb', line 100 def type @type ||= case adapter when DatabaseAdapters::MySQLAdapter 'mysql' when DatabaseAdapters::PostgreSQLAdapter 'pgsql' else raise UnknownDatabaseAdapter, "Provided type: #{adapter.class.name}" end end |