gotime-cassandra_object 2.6.1 → 2.6.2
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.
| 
         @@ -20,6 +20,14 @@ module CassandraObject 
     | 
|
| 
       20 
20 
     | 
    
         
             
                  end
         
     | 
| 
       21 
21 
     | 
    
         
             
                end
         
     | 
| 
       22 
22 
     | 
    
         | 
| 
      
 23 
     | 
    
         
            +
                # <tt>reload</tt> the record and clears changed attributes.
         
     | 
| 
      
 24 
     | 
    
         
            +
                def reload
         
     | 
| 
      
 25 
     | 
    
         
            +
                  super.tap do
         
     | 
| 
      
 26 
     | 
    
         
            +
                    @previously_changed.try :clear
         
     | 
| 
      
 27 
     | 
    
         
            +
                    @changed_attributes.clear
         
     | 
| 
      
 28 
     | 
    
         
            +
                  end
         
     | 
| 
      
 29 
     | 
    
         
            +
                end
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
       23 
31 
     | 
    
         
             
                def write_attribute(name, value)
         
     | 
| 
       24 
32 
     | 
    
         
             
                  name = name.to_s
         
     | 
| 
       25 
33 
     | 
    
         
             
                  unless attribute_changed?(name)
         
     | 
| 
         @@ -2,24 +2,41 @@ module CassandraObject 
     | 
|
| 
       2 
2 
     | 
    
         
             
              module Types
         
     | 
| 
       3 
3 
     | 
    
         
             
                class ArrayType < BaseType
         
     | 
| 
       4 
4 
     | 
    
         
             
                  class Proxy < BasicObject
         
     | 
| 
      
 5 
     | 
    
         
            +
                    instance_methods.each { |m| undef_method m }
         
     | 
| 
      
 6 
     | 
    
         
            +
                    
         
     | 
| 
       5 
7 
     | 
    
         
             
                    attr_accessor :record, :name, :array, :options
         
     | 
| 
       6 
8 
     | 
    
         
             
                    def initialize(record, name, array, options)
         
     | 
| 
       7 
9 
     | 
    
         
             
                      @record   = record
         
     | 
| 
       8 
     | 
    
         
            -
                      @name     = name
         
     | 
| 
      
 10 
     | 
    
         
            +
                      @name     = name.to_s
         
     | 
| 
       9 
11 
     | 
    
         
             
                      @array    = array.presence || []
         
     | 
| 
       10 
12 
     | 
    
         
             
                      @options  = options
         
     | 
| 
       11 
13 
     | 
    
         
             
                    end
         
     | 
| 
       12 
14 
     | 
    
         | 
| 
       13 
15 
     | 
    
         
             
                    def <<(obj)
         
     | 
| 
       14 
     | 
    
         
            -
                       
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
                       
     | 
| 
      
 16 
     | 
    
         
            +
                      modifying do
         
     | 
| 
      
 17 
     | 
    
         
            +
                        array << obj
         
     | 
| 
      
 18 
     | 
    
         
            +
                        array.uniq! if options[:unique]
         
     | 
| 
      
 19 
     | 
    
         
            +
                      end
         
     | 
| 
       18 
20 
     | 
    
         
             
                    end
         
     | 
| 
       19 
21 
     | 
    
         | 
| 
       20 
     | 
    
         
            -
                     
     | 
| 
       21 
     | 
    
         
            -
                       
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
      
 22 
     | 
    
         
            +
                    private
         
     | 
| 
      
 23 
     | 
    
         
            +
                      def method_missing(method, *args, &block)
         
     | 
| 
      
 24 
     | 
    
         
            +
                        array.send(method, *args, &block)
         
     | 
| 
      
 25 
     | 
    
         
            +
                      end
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
                      def modifying
         
     | 
| 
      
 28 
     | 
    
         
            +
                        unless record.changed_attributes.include?(name)
         
     | 
| 
      
 29 
     | 
    
         
            +
                          original = array.dup
         
     | 
| 
      
 30 
     | 
    
         
            +
                        end
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
                        yield
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
                        if !record.changed_attributes.key?(name) && original.sort != array.sort
         
     | 
| 
      
 35 
     | 
    
         
            +
                          record.changed_attributes[name] = original
         
     | 
| 
      
 36 
     | 
    
         
            +
                        end
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
                        record.send("#{name}=", array)
         
     | 
| 
      
 39 
     | 
    
         
            +
                      end
         
     | 
| 
       23 
40 
     | 
    
         
             
                  end
         
     | 
| 
       24 
41 
     | 
    
         | 
| 
       25 
42 
     | 
    
         
             
                  def ignore_nil?
         
     | 
    
        data/test/dirty_test.rb
    CHANGED
    
    | 
         @@ -15,4 +15,16 @@ class CassandraObject::DirtyTest < CassandraObject::TestCase 
     | 
|
| 
       15 
15 
     | 
    
         | 
| 
       16 
16 
     | 
    
         
             
                assert !record.changed?
         
     | 
| 
       17 
17 
     | 
    
         
             
              end
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
              test 'reload clears dirty' do
         
     | 
| 
      
 20 
     | 
    
         
            +
                record = TestRecord.create!(name: 'foo')
         
     | 
| 
      
 21 
     | 
    
         
            +
                record = TestRecord.find(record.id)
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                record.name = 'bar'
         
     | 
| 
      
 24 
     | 
    
         
            +
                assert record.changed?
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                record.reload
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                assert !record.changed?
         
     | 
| 
      
 29 
     | 
    
         
            +
              end
         
     | 
| 
       18 
30 
     | 
    
         
             
            end
         
     | 
    
        data/test/test_helper.rb
    CHANGED
    
    | 
         @@ -4,6 +4,11 @@ require 'test/unit' 
     | 
|
| 
       4 
4 
     | 
    
         
             
            require 'cassandra/0.8'
         
     | 
| 
       5 
5 
     | 
    
         
             
            require 'gotime-cassandra_object'
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
      
 7 
     | 
    
         
            +
            CassandraObject::Base.establish_connection(
         
     | 
| 
      
 8 
     | 
    
         
            +
              keyspace: 'place_directory_development',
         
     | 
| 
      
 9 
     | 
    
         
            +
              servers: '127.0.0.1:9160'
         
     | 
| 
      
 10 
     | 
    
         
            +
            )
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
       7 
12 
     | 
    
         
             
            class Issue < CassandraObject::Base
         
     | 
| 
       8 
13 
     | 
    
         
             
              key :uuid
         
     | 
| 
       9 
14 
     | 
    
         
             
              string :description
         
     | 
| 
         @@ -12,11 +17,6 @@ end 
     | 
|
| 
       12 
17 
     | 
    
         
             
            module CassandraObject
         
     | 
| 
       13 
18 
     | 
    
         
             
              class TestCase < ActiveSupport::TestCase
         
     | 
| 
       14 
19 
     | 
    
         
             
                setup do
         
     | 
| 
       15 
     | 
    
         
            -
                  CassandraObject::Base.establish_connection(
         
     | 
| 
       16 
     | 
    
         
            -
                    keyspace: 'place_directory_development',
         
     | 
| 
       17 
     | 
    
         
            -
                    # servers: '192.168.0.100:9160'
         
     | 
| 
       18 
     | 
    
         
            -
                    servers: '127.0.0.1:9160'
         
     | 
| 
       19 
     | 
    
         
            -
                  )
         
     | 
| 
       20 
20 
     | 
    
         
             
                end
         
     | 
| 
       21 
21 
     | 
    
         | 
| 
       22 
22 
     | 
    
         
             
                teardown do
         
     | 
| 
         @@ -29,7 +29,7 @@ module CassandraObject 
     | 
|
| 
       29 
29 
     | 
    
         
             
              end
         
     | 
| 
       30 
30 
     | 
    
         | 
| 
       31 
31 
     | 
    
         
             
              module Types
         
     | 
| 
       32 
     | 
    
         
            -
                class TestCase <  
     | 
| 
      
 32 
     | 
    
         
            +
                class TestCase < CassandraObject::TestCase
         
     | 
| 
       33 
33 
     | 
    
         
             
                  attr_accessor :coder
         
     | 
| 
       34 
34 
     | 
    
         
             
                  setup do
         
     | 
| 
       35 
35 
     | 
    
         
             
                    @coder = self.class.name.sub(/Test$/, '').constantize.new
         
     | 
| 
         @@ -18,19 +18,30 @@ class CassandraObject::Types::ArrayTypeTest < CassandraObject::Types::TestCase 
     | 
|
| 
       18 
18 
     | 
    
         
             
              end
         
     | 
| 
       19 
19 
     | 
    
         | 
| 
       20 
20 
     | 
    
         
             
              class TestIssue < CassandraObject::Base
         
     | 
| 
       21 
     | 
    
         
            -
                 
     | 
| 
       22 
     | 
    
         
            -
                 
     | 
| 
      
 21 
     | 
    
         
            +
                key :uuid
         
     | 
| 
      
 22 
     | 
    
         
            +
                self.column_family = 'Issues'
         
     | 
| 
      
 23 
     | 
    
         
            +
                array :favorite_colors, unique: true
         
     | 
| 
       23 
24 
     | 
    
         
             
              end
         
     | 
| 
       24 
25 
     | 
    
         | 
| 
       25 
     | 
    
         
            -
              test ' 
     | 
| 
       26 
     | 
    
         
            -
                issue = TestIssue.new
         
     | 
| 
       27 
     | 
    
         
            -
                colors = []
         
     | 
| 
       28 
     | 
    
         
            -
                wrapper = coder.wrap(issue, 'favorite_colors', colors)
         
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
                assert_kind_of Array, wrapper
         
     | 
| 
      
 26 
     | 
    
         
            +
              test 'array attribute' do
         
     | 
| 
      
 27 
     | 
    
         
            +
                issue = TestIssue.new favorite_colors: []
         
     | 
| 
       31 
28 
     | 
    
         | 
| 
       32 
     | 
    
         
            -
                 
     | 
| 
       33 
     | 
    
         
            -
                 
     | 
| 
      
 29 
     | 
    
         
            +
                assert_kind_of Array, issue.favorite_colors
         
     | 
| 
      
 30 
     | 
    
         
            +
                issue.favorite_colors << 'red'
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
       34 
32 
     | 
    
         
             
                assert issue.changed?
         
     | 
| 
      
 33 
     | 
    
         
            +
                assert_equal({'favorite_colors' => [nil, ['red']]}, issue.changes)
         
     | 
| 
      
 34 
     | 
    
         
            +
              end
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
              test 'array uniques' do
         
     | 
| 
      
 37 
     | 
    
         
            +
                issue = TestIssue.create! favorite_colors: ['red', 'blue']
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
                issue.favorite_colors << 'red'
         
     | 
| 
      
 40 
     | 
    
         
            +
                assert_equal ['red', 'blue'], issue.favorite_colors
         
     | 
| 
      
 41 
     | 
    
         
            +
                assert !issue.changed?
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
                issue.favorite_colors << 'yellow'
         
     | 
| 
      
 44 
     | 
    
         
            +
                assert_equal ['red', 'blue', 'yellow'], issue.favorite_colors
         
     | 
| 
      
 45 
     | 
    
         
            +
                assert_equal({'favorite_colors' => [['red', 'blue'], ['red', 'blue', 'yellow']]}, issue.changes)
         
     | 
| 
       35 
46 
     | 
    
         
             
              end
         
     | 
| 
       36 
47 
     | 
    
         
             
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: gotime-cassandra_object
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 2.6. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 2.6.2
         
     | 
| 
       5 
5 
     | 
    
         
             
              prerelease: 
         
     | 
| 
       6 
6 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       7 
7 
     | 
    
         
             
            authors:
         
     | 
| 
         @@ -14,7 +14,7 @@ date: 2011-08-29 00:00:00.000000000Z 
     | 
|
| 
       14 
14 
     | 
    
         
             
            dependencies:
         
     | 
| 
       15 
15 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       16 
16 
     | 
    
         
             
              name: activemodel
         
     | 
| 
       17 
     | 
    
         
            -
              requirement: & 
     | 
| 
      
 17 
     | 
    
         
            +
              requirement: &70186041043380 !ruby/object:Gem::Requirement
         
     | 
| 
       18 
18 
     | 
    
         
             
                none: false
         
     | 
| 
       19 
19 
     | 
    
         
             
                requirements:
         
     | 
| 
       20 
20 
     | 
    
         
             
                - - ~>
         
     | 
| 
         @@ -22,10 +22,10 @@ dependencies: 
     | 
|
| 
       22 
22 
     | 
    
         
             
                    version: '3.0'
         
     | 
| 
       23 
23 
     | 
    
         
             
              type: :runtime
         
     | 
| 
       24 
24 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       25 
     | 
    
         
            -
              version_requirements: * 
     | 
| 
      
 25 
     | 
    
         
            +
              version_requirements: *70186041043380
         
     | 
| 
       26 
26 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       27 
27 
     | 
    
         
             
              name: cassandra
         
     | 
| 
       28 
     | 
    
         
            -
              requirement: & 
     | 
| 
      
 28 
     | 
    
         
            +
              requirement: &70186041042820 !ruby/object:Gem::Requirement
         
     | 
| 
       29 
29 
     | 
    
         
             
                none: false
         
     | 
| 
       30 
30 
     | 
    
         
             
                requirements:
         
     | 
| 
       31 
31 
     | 
    
         
             
                - - ~>
         
     | 
| 
         @@ -33,10 +33,10 @@ dependencies: 
     | 
|
| 
       33 
33 
     | 
    
         
             
                    version: 0.12.0
         
     | 
| 
       34 
34 
     | 
    
         
             
              type: :runtime
         
     | 
| 
       35 
35 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       36 
     | 
    
         
            -
              version_requirements: * 
     | 
| 
      
 36 
     | 
    
         
            +
              version_requirements: *70186041042820
         
     | 
| 
       37 
37 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       38 
38 
     | 
    
         
             
              name: bundler
         
     | 
| 
       39 
     | 
    
         
            -
              requirement: & 
     | 
| 
      
 39 
     | 
    
         
            +
              requirement: &70186041042140 !ruby/object:Gem::Requirement
         
     | 
| 
       40 
40 
     | 
    
         
             
                none: false
         
     | 
| 
       41 
41 
     | 
    
         
             
                requirements:
         
     | 
| 
       42 
42 
     | 
    
         
             
                - - ~>
         
     | 
| 
         @@ -44,7 +44,7 @@ dependencies: 
     | 
|
| 
       44 
44 
     | 
    
         
             
                    version: 1.0.0
         
     | 
| 
       45 
45 
     | 
    
         
             
              type: :development
         
     | 
| 
       46 
46 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       47 
     | 
    
         
            -
              version_requirements: * 
     | 
| 
      
 47 
     | 
    
         
            +
              version_requirements: *70186041042140
         
     | 
| 
       48 
48 
     | 
    
         
             
            description: Cassandra ActiveModel
         
     | 
| 
       49 
49 
     | 
    
         
             
            email: gems@gotime.com
         
     | 
| 
       50 
50 
     | 
    
         
             
            executables: []
         
     |