entity_store 0.1.3 → 0.1.6
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/entity_store/event_bus.rb +1 -5
- data/lib/entity_store/external_store.rb +1 -6
- data/lib/entity_store/mongo_entity_store.rb +7 -15
- data/lib/entity_store/version.rb +1 -1
- data/lib/entity_store.rb +20 -19
- data/spec/entity_store/external_store_spec.rb +0 -1
- data/spec/spec_helper.rb +5 -0
- metadata +3 -2
| @@ -47,7 +47,7 @@ module EntityStore | |
| 47 47 | 
             
                  while event_data_objects.count > 0 do 
         | 
| 48 48 | 
             
                    event_data_objects.each do |event_data_object|
         | 
| 49 49 | 
             
                      begin
         | 
| 50 | 
            -
                        event =  | 
| 50 | 
            +
                        event = EntityStore.load_type(event_data_object.type).new(event_data_object.attrs)
         | 
| 51 51 | 
             
                        subscriber.new.send(event.receiver_name, event)
         | 
| 52 52 | 
             
                        logger.info { "replayed #{event.inspect} to #{subscriber.name}##{event.receiver_name}" }
         | 
| 53 53 | 
             
                      rescue => e
         | 
| @@ -57,9 +57,5 @@ module EntityStore | |
| 57 57 | 
             
                    event_data_objects = external_store.get_events(event_data_objects.last.id, type, max_items)
         | 
| 58 58 | 
             
                  end
         | 
| 59 59 | 
             
                end
         | 
| 60 | 
            -
             | 
| 61 | 
            -
                def get_type_constant(type_name)
         | 
| 62 | 
            -
                  type_name.split('::').inject(Object) {|obj, name| obj.const_get(name) }
         | 
| 63 | 
            -
                end
         | 
| 64 60 | 
             
              end
         | 
| 65 61 | 
             
            end
         | 
| @@ -6,12 +6,7 @@ module EntityStore | |
| 6 6 | 
             
                include Mongo
         | 
| 7 7 |  | 
| 8 8 | 
             
                def open_connection
         | 
| 9 | 
            -
                   | 
| 10 | 
            -
                end
         | 
| 11 | 
            -
                
         | 
| 12 | 
            -
                def open_store
         | 
| 13 | 
            -
                  uri  = URI.parse(EntityStore.external_connection_profile)
         | 
| 14 | 
            -
                  Connection.from_uri(EntityStore.external_connection_profile).db(uri.path.gsub(/^\//, ''))
         | 
| 9 | 
            +
                  EntityStore.external_mongo_connection.db(EntityStore.external_db)
         | 
| 15 10 | 
             
                end
         | 
| 16 11 |  | 
| 17 12 | 
             
                def collection
         | 
| @@ -7,17 +7,7 @@ module EntityStore | |
| 7 7 | 
             
                include Hatchet
         | 
| 8 8 |  | 
| 9 9 | 
             
                def open_connection
         | 
| 10 | 
            -
                   | 
| 11 | 
            -
                end
         | 
| 12 | 
            -
             | 
| 13 | 
            -
                def open_store
         | 
| 14 | 
            -
                  uri  = URI.parse(EntityStore.connection_profile)
         | 
| 15 | 
            -
                  connection = Connection.from_uri(EntityStore.connection_profile, :connect_timeout => connect_timeout)
         | 
| 16 | 
            -
                  connection.db(uri.path.gsub(/^\//, ''))
         | 
| 17 | 
            -
                end
         | 
| 18 | 
            -
             | 
| 19 | 
            -
                def connect_timeout
         | 
| 20 | 
            -
                  (ENV['ENTITY_STORE_CONNECT_TIMEOUT'] || '2').to_i
         | 
| 10 | 
            +
                  EntityStore.mongo_connection.db(EntityStore.entity_db)
         | 
| 21 11 | 
             
                end
         | 
| 22 12 |  | 
| 23 13 | 
             
                def entities
         | 
| @@ -72,7 +62,12 @@ module EntityStore | |
| 72 62 | 
             
                # Returns an object of the entity type
         | 
| 73 63 | 
             
                def get_entity(id, raise_exception=false)
         | 
| 74 64 | 
             
                  if attrs = entities.find_one('_id' => BSON::ObjectId.from_string(id))
         | 
| 75 | 
            -
                     | 
| 65 | 
            +
                    begin
         | 
| 66 | 
            +
                      entity = EntityStore.load_type(attrs['_type']).new(attrs['snapshot'] || {'id' => id, 'version' => attrs['version']})
         | 
| 67 | 
            +
                    rescue => e
         | 
| 68 | 
            +
                      logger.error "Error loading type #{attrs['_type']}", e
         | 
| 69 | 
            +
                      raise
         | 
| 70 | 
            +
                    end
         | 
| 76 71 |  | 
| 77 72 | 
             
                    since_version = attrs['snapshot'] ? attrs['snapshot']['version'] : nil
         | 
| 78 73 |  | 
| @@ -115,8 +110,5 @@ module EntityStore | |
| 115 110 | 
             
                  end.select { |e| !e.nil? }
         | 
| 116 111 | 
             
                end
         | 
| 117 112 |  | 
| 118 | 
            -
                # def get_type_constant(type_name)
         | 
| 119 | 
            -
                #   type_name.split('::').inject(Object) {|obj, name| obj.const_get(name) }
         | 
| 120 | 
            -
                # end
         | 
| 121 113 | 
             
              end
         | 
| 122 114 | 
             
            end
         | 
    
        data/lib/entity_store/version.rb
    CHANGED
    
    
    
        data/lib/entity_store.rb
    CHANGED
    
    | @@ -14,25 +14,15 @@ module EntityStore | |
| 14 14 | 
             
              require 'entity_store/attributes'
         | 
| 15 15 |  | 
| 16 16 | 
             
              class << self
         | 
| 17 | 
            -
             | 
| 17 | 
            +
                attr_reader :mongo_connection, :external_mongo_connection, :entity_db, :external_db
         | 
| 18 | 
            +
                attr_accessor :connection_profile, :external_connection_profile
         | 
| 18 19 | 
             
                def setup
         | 
| 19 20 | 
             
                  yield self
         | 
| 20 | 
            -
                end
         | 
| 21 | 
            -
             | 
| 22 | 
            -
                def connection_profile
         | 
| 23 | 
            -
                  @_connection_profile
         | 
| 24 | 
            -
                end
         | 
| 25 | 
            -
             | 
| 26 | 
            -
                def connection_profile=(value)
         | 
| 27 | 
            -
                  @_connection_profile = value
         | 
| 28 | 
            -
                end
         | 
| 29 | 
            -
             | 
| 30 | 
            -
                def external_connection_profile
         | 
| 31 | 
            -
                  @_external_connection_profile
         | 
| 32 | 
            -
                end
         | 
| 33 21 |  | 
| 34 | 
            -
             | 
| 35 | 
            -
                  @ | 
| 22 | 
            +
                  @mongo_connection = open_store(@connection_profile)
         | 
| 23 | 
            +
                  @entity_db = extract_db(@connection_profile)
         | 
| 24 | 
            +
                  @external_mongo_connection = open_store(@external_connection_profile)
         | 
| 25 | 
            +
                  @external_db = extract_db(@external_connection_profile)
         | 
| 36 26 | 
             
                end
         | 
| 37 27 |  | 
| 38 28 | 
             
                def event_subscribers
         | 
| @@ -56,13 +46,24 @@ module EntityStore | |
| 56 46 | 
             
                attr_accessor :type_loader
         | 
| 57 47 |  | 
| 58 48 | 
             
                def load_type(type_name)
         | 
| 59 | 
            -
                  if type_loader
         | 
| 60 | 
            -
                    type_loader.call(type_name)
         | 
| 49 | 
            +
                  if EntityStore.type_loader
         | 
| 50 | 
            +
                    EntityStore.type_loader.call(type_name)
         | 
| 61 51 | 
             
                  else
         | 
| 62 52 | 
             
                    type_name.split('::').inject(Object) {|obj, name| obj.const_get(name) }
         | 
| 63 53 | 
             
                  end
         | 
| 64 54 | 
             
                end
         | 
| 65 | 
            -
              end
         | 
| 66 55 |  | 
| 56 | 
            +
                def open_store(url)
         | 
| 57 | 
            +
                  Mongo::MongoClient.from_uri(url, :connect_timeout => connect_timeout)
         | 
| 58 | 
            +
                end
         | 
| 59 | 
            +
             | 
| 60 | 
            +
                def extract_db(url)
         | 
| 61 | 
            +
                  URI.parse(url).path.gsub(/^\//, '')
         | 
| 62 | 
            +
                end
         | 
| 63 | 
            +
             | 
| 64 | 
            +
                def connect_timeout
         | 
| 65 | 
            +
                  (ENV['ENTITY_STORE_CONNECT_TIMEOUT'] || '2').to_i
         | 
| 66 | 
            +
                end
         | 
| 67 | 
            +
              end
         | 
| 67 68 |  | 
| 68 69 | 
             
            end
         | 
    
        data/spec/spec_helper.rb
    CHANGED
    
    | @@ -20,6 +20,11 @@ end | |
| 20 20 |  | 
| 21 21 | 
             
            include EntityStore
         | 
| 22 22 |  | 
| 23 | 
            +
            EntityStore.setup do |config|
         | 
| 24 | 
            +
              config.connection_profile = "mongodb://localhost/entity_store_test" 
         | 
| 25 | 
            +
              config.external_connection_profile = "mongodb://localhost/external_entity_store_test" 
         | 
| 26 | 
            +
            end
         | 
| 27 | 
            +
             | 
| 23 28 | 
             
            def random_string
         | 
| 24 29 | 
             
              (0...24).map{ ('a'..'z').to_a[rand(26)] }.join
         | 
| 25 30 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: entity_store
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.1. | 
| 4 | 
            +
              version: 0.1.6
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 6 | 
             
            platform: ruby
         | 
| 7 7 | 
             
            authors:
         | 
| @@ -9,7 +9,7 @@ authors: | |
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2012- | 
| 12 | 
            +
            date: 2012-12-31 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: mongo
         | 
| @@ -123,3 +123,4 @@ test_files: | |
| 123 123 | 
             
            - spec/entity_store/store_spec.rb
         | 
| 124 124 | 
             
            - spec/entity_store_spec.rb
         | 
| 125 125 | 
             
            - spec/spec_helper.rb
         | 
| 126 | 
            +
            has_rdoc: 
         |