Module: SimpleRecord
- Defined in:
- lib/simple_record/password.rb,
lib/simple_record.rb,
lib/simple_record/json.rb,
lib/simple_record/stats.rb,
lib/simple_record/errors.rb,
lib/simple_record/logging.rb,
lib/simple_record/sharding.rb,
lib/simple_record/callbacks.rb,
lib/simple_record/encryptor.rb,
lib/simple_record/active_sdb.rb,
lib/simple_record/attributes.rb,
lib/simple_record/validations.rb,
lib/simple_record/translations.rb,
lib/simple_record/results_array.rb
Overview
This module defines all the methods that perform data translations for storage and retrieval.
Defined Under Namespace
Modules: Attributes, Callbacks, Callbacks3, Encryptor, Json, Logging, Password, Sharding, Translations, Validations Classes: ActiveSdb, Activerecordtosdb_subrecord_array, Base, Error, PasswordHashed, RecordNotFound, RecordNotSaved, RemoteNil, ResultsArray, SimpleRecordError, SimpleRecord_errors, Stats
Constant Summary collapse
- @@options =
{}
- @@stats =
SimpleRecord::Stats.new
- @@logging =
false
- @@s3 =
nil
- @@auto_close_s3 =
false
- @@logger =
Logger.new(STDOUT)
Class Attribute Summary collapse
-
.aws_access_key ⇒ Object
Returns the value of attribute aws_access_key.
-
.aws_secret_key ⇒ Object
Returns the value of attribute aws_secret_key.
Class Method Summary collapse
-
.close_connection ⇒ Object
Call this to close the connection to SimpleDB.
- .close_usage_log(type) ⇒ Object
-
.disable_logging ⇒ Object
Deprecated.
-
.enable_logging ⇒ Object
Deprecated.
-
.establish_connection(aws_access_key = nil, aws_secret_key = nil, options = {}) ⇒ Object
Create a new handle to an Sdb account.
-
.log_usage(types = {}) ⇒ Object
This can be used to log queries and what not to a file.
- .logger ⇒ Object
-
.logging? ⇒ Boolean
Deprecated.
- .options ⇒ Object
- .s3 ⇒ Object
-
.s3=(s3) ⇒ Object
If you’d like to specify the s3 connection to use for LOBs, you can pass it in here.
- .stats ⇒ Object
- .usage_logging_options ⇒ Object
Class Attribute Details
.aws_access_key ⇒ Object
Returns the value of attribute aws_access_key.
63 64 65 |
# File 'lib/simple_record.rb', line 63 def aws_access_key @aws_access_key end |
.aws_secret_key ⇒ Object
Returns the value of attribute aws_secret_key.
63 64 65 |
# File 'lib/simple_record.rb', line 63 def aws_secret_key @aws_secret_key end |
Class Method Details
.close_connection ⇒ Object
Call this to close the connection to SimpleDB. If you’re using this in Rails with per_thread connection mode, you should do this in an after_filter for each request.
153 154 155 156 |
# File 'lib/simple_record.rb', line 153 def close_connection() SimpleRecord::ActiveSdb.close_connection @@s3.close_connection if @@auto_close_s3 end |
.close_usage_log(type) ⇒ Object
98 99 100 101 |
# File 'lib/simple_record.rb', line 98 def close_usage_log(type) return unless @usage_logging_options[type] @usage_logging_options[type][:file].close if @usage_logging_options[type][:file] end |
.disable_logging ⇒ Object
Deprecated
72 73 74 |
# File 'lib/simple_record.rb', line 72 def disable_logging @@logging = false end |
.enable_logging ⇒ Object
Deprecated
66 67 68 69 |
# File 'lib/simple_record.rb', line 66 def enable_logging @@logging = true @@logger.level = Logger::DEBUG end |
.establish_connection(aws_access_key = nil, aws_secret_key = nil, options = {}) ⇒ Object
Create a new handle to an Sdb account. All handles share the same per process or per thread HTTP connection to Amazon Sdb. Each handle is for a specific account. The params
are passed through as-is to Aws::SdbInterface.new Params:
{ :server => 'sdb.amazonaws.com' # Amazon service host: 'sdb.amazonaws.com'(default)
:port => 443 # Amazon service port: 80(default) or 443
:protocol => 'https' # Amazon service protocol: 'http'(default) or 'https'
:signature_version => '0' # The signature version : '0' or '1'(default)
:connection_mode => :default # options are
:default (will use best known safe (as in won't need explicit close) option, may change in the future)
:per_request (opens and closes a connection on every request to SDB)
:single (one thread across entire app)
:per_thread (one connection per thread)
:pool (uses a connection pool with a maximum number of connections - NOT IMPLEMENTED YET)
:logger => Logger Object # Logger instance: logs to STDOUT if omitted
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/simple_record.rb', line 127 def establish_connection(aws_access_key=nil, aws_secret_key=nil, ={}) @aws_access_key = aws_access_key @aws_secret_key = aws_secret_key @@options.merge!() #puts 'SimpleRecord.establish_connection with options: ' + @@options.inspect SimpleRecord::ActiveSdb.establish_connection(aws_access_key, aws_secret_key, @@options) if [:connection_mode] == :per_thread @@auto_close_s3 = true # todo: should we init this only when needed? end s3_ops = {:connection_mode=>[:connection_mode] || :default} @@s3 = Aws::S3.new(SimpleRecord.aws_access_key, SimpleRecord.aws_secret_key, s3_ops) if [:created_col] SimpleRecord::Base.has_dates [:created_col] end if [:updated_col] SimpleRecord::Base.has_dates [:updated_col] end end |
.log_usage(types = {}) ⇒ Object
This can be used to log queries and what not to a file. Params: :select=>:format=>“csv”
88 89 90 91 92 93 94 95 96 |
# File 'lib/simple_record.rb', line 88 def log_usage(types={}) @usage_logging_options = {} unless @usage_logging_options return if types.nil? types.each_pair do |type, | [:lines_between_flushes] = 100 unless [:lines_between_flushes] @usage_logging_options[type] = end #puts 'SimpleRecord.usage_logging_options=' + SimpleRecord.usage_logging_options.inspect end |
.logger ⇒ Object
81 82 83 |
# File 'lib/simple_record.rb', line 81 def logger @@logger end |
.logging? ⇒ Boolean
Deprecated
77 78 79 |
# File 'lib/simple_record.rb', line 77 def logging? @@logging end |
.options ⇒ Object
169 170 171 |
# File 'lib/simple_record.rb', line 169 def @@options end |
.s3 ⇒ Object
165 166 167 |
# File 'lib/simple_record.rb', line 165 def s3 @@s3 end |
.s3=(s3) ⇒ Object
If you’d like to specify the s3 connection to use for LOBs, you can pass it in here. We recommend that this connection matches the type of connection you’re using for SimpleDB, at least if you’re using per_thread connection mode.
161 162 163 |
# File 'lib/simple_record.rb', line 161 def s3=(s3) @@s3 = s3 end |
.stats ⇒ Object
107 108 109 |
# File 'lib/simple_record.rb', line 107 def stats @@stats end |
.usage_logging_options ⇒ Object
103 104 105 |
# File 'lib/simple_record.rb', line 103 def @usage_logging_options end |