datastax_rails 1.0.12 → 1.0.13

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.
data/lib/blankslate.rb CHANGED
@@ -67,7 +67,7 @@ module Kernel
67
67
  end
68
68
 
69
69
  ######################################################################
70
- # Same as above, except in Object.
70
+ # @see Kernel
71
71
  class Object
72
72
  class << self
73
73
  alias_method :blank_slate_method_added, :method_added
@@ -152,13 +152,18 @@ module DatastaxRails #:nodoc:
152
152
  # by ID. SOLR only supports a consistency level of ONE. See the documentation for
153
153
  # SearchMethods#consistency for a more detailed explanation.
154
154
  #
155
- # The overall default consistency for a given model can be overridden by adding a method
156
- # to the model like so:
155
+ # The overall default consistency for a given model can be overridden by setting the
156
+ # +default_consistency+ property.
157
157
  #
158
- # def default_consistency
159
- # :local_quorum
158
+ # class Model < DatastaxRails::Base
159
+ # self.default_consistency = :local_quorum
160
160
  # end
161
161
  #
162
+ # The default consistency for all models can be selected by setting the property on
163
+ # DatastaxRails::Base.
164
+ #
165
+ # DatastaxRails::Base.default_consistency = :one
166
+ #
162
167
  # == Conditions
163
168
  #
164
169
  # Conditions are specified as a hash representing key/value pairs that will eventually be passed to SOLR or as
@@ -314,6 +319,9 @@ module DatastaxRails #:nodoc:
314
319
  # Stores the configuration information
315
320
  class_attribute :config
316
321
 
322
+ class_attribute :default_consistency
323
+ self.default_consistency = :quorum
324
+
317
325
  class_attribute :models
318
326
  self.models = []
319
327
 
@@ -3,7 +3,7 @@ module DatastaxRails
3
3
  class Base
4
4
  # Base initialize that sets the default consistency.
5
5
  def initialize(klass, *args)
6
- @consistency = klass.respond_to?(:default_consistency) ? klass.default_consistency.to_s.upcase : DatastaxRails::Cql::Consistency::QUORUM
6
+ @consistency = klass.default_consistency.to_s.upcase
7
7
  end
8
8
 
9
9
  # Abstract. Should be overridden by subclasses
@@ -2,10 +2,6 @@ module DatastaxRails
2
2
  module Persistence
3
3
  extend ActiveSupport::Concern
4
4
 
5
- included do
6
- attr_accessor :ds_consistency_level
7
- end
8
-
9
5
  module ClassMethods
10
6
  # Removes one or more records with corresponding keys. Last parameter can be a hash
11
7
  # specifying the consistency level.
@@ -77,6 +73,13 @@ module DatastaxRails
77
73
  end
78
74
  end
79
75
 
76
+ # Instantiates a new object without calling +initialize+.
77
+ #
78
+ # @param [String] key the primary key for the record
79
+ # @param [Hash] attributes a hash containing the columns to set on the record
80
+ # @param [Array] selected_attributes an array containing the attributes that were originally selected from cassandra
81
+ # to build this object. Used so that we can avoid lazy-loading attributes that don't exist.
82
+ # @return [DatastaxRails::Base] a model with the given attributes
80
83
  def instantiate(key, attributes, selected_attributes = [])
81
84
  allocate.tap do |object|
82
85
  object.instance_variable_set("@loaded_attributes", {}.with_indifferent_access)
@@ -88,6 +91,12 @@ module DatastaxRails
88
91
  end
89
92
  end
90
93
 
94
+ # Encodes the attributes in preparation for storing in cassandra. Calls the coders on the various type classes
95
+ # to do the heavy lifting.
96
+ #
97
+ # @param [Hash] attributes a hash containing the attributes to be encoded for storage
98
+ # @param [String] schema_version the schema version to set in Cassandra. Not currently used.
99
+ # @return [Hash] a new hash with attributes encoded for storage
91
100
  def encode_attributes(attributes, schema_version)
92
101
  encoded = {"schema_version" => schema_version.to_s}
93
102
  attributes.each do |column_name, value|
@@ -3,7 +3,12 @@ require 'active_support/core_ext/object/inclusion'
3
3
 
4
4
  module DatastaxRails
5
5
  # This is shamelessly ripped from Active Record 3.1
6
- # = DatastaxRails Reflection
6
+ #
7
+ # Reflection enables interrogation of DatastaxRails classes and objects
8
+ # about their associations and aggregations. This information can,
9
+ # for example, be used in a form builder that takes an DatastaxRails object
10
+ # and creates input fields for all of the attributes depending on their type
11
+ # and displays the associations to other objects.
7
12
  module Reflection # :nodoc:
8
13
  extend ActiveSupport::Concern
9
14
 
@@ -12,11 +17,6 @@ module DatastaxRails
12
17
  self.reflections = {}
13
18
  end
14
19
 
15
- # Reflection enables interrogation of DatastaxRails classes and objects
16
- # about their associations and aggregations. This information can,
17
- # for example, be used in a form builder that takes an DatastaxRails object
18
- # and creates input fields for all of the attributes depending on their type
19
- # and displays the associations to other objects.
20
20
  module ClassMethods
21
21
  def create_reflection(macro, name, options, datastax_rails)
22
22
  klass = options[:through] ? ThroughReflection : AssociationReflection
@@ -1,4 +1,4 @@
1
1
  module DatastaxRails
2
2
  # The current version of the gem
3
- VERSION = "1.0.12"
3
+ VERSION = "1.0.13"
4
4
  end
@@ -15,7 +15,6 @@ module DatastaxRails
15
15
  autoload :Collection
16
16
  autoload :Connection
17
17
  autoload :Cql
18
- autoload :Cursor
19
18
  autoload :Identity
20
19
  autoload :Migrations
21
20
  autoload :Persistence
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe DatastaxRails::Cql::Select do
4
4
  before(:each) do
5
- @model_class = mock("Model Class", :column_family => 'users')
5
+ @model_class = mock("Model Class", :column_family => 'users', :default_consistency => DatastaxRails::Cql::Consistency::QUORUM)
6
6
  end
7
7
 
8
8
  it "should generate valid CQL" do
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe DatastaxRails::Cql::Update do
4
4
  before(:each) do
5
- @model_class = mock("Model Class", :column_family => 'users')
5
+ @model_class = mock("Model Class", :column_family => 'users', :default_consistency => DatastaxRails::Cql::Consistency::QUORUM)
6
6
  end
7
7
 
8
8
  it "should generate valid CQL" do