Sha256: d9275ac777c215ba5bf8715877e0f25545e6c44d6cb3b6c52a322d14e329bd2e

Contents?: true

Size: 1.8 KB

Versions: 25

Compression:

Stored size: 1.8 KB

Contents

require 'spiderfw/model/mappers/hash_mapper'

module Spider; module Model
    
    # BaseModel having its data defined in the class.
    # The data must be an array of hashes, and will be handled by the Mappers::HashMapper.
    class InlineModel < BaseModel
        
        class <<self
            
            # Sets model data.
            def data=(val)
                @data = val
            end
            
            # Sets/gets model data.
            def data(val=nil)
                self.data = val if (val)
                d = @data
                if self.translate?
                    Spider::GetText.in_domain(self.app.short_name){
                        @data.each do |k, v|
                            d[k] = _(v)
                        end
                    }
                end
                d
            end
            
            def translate=(val)
                @translate = val
            end
            
            def translate?
                @translate
            end
            
            def mapper
                return Mappers::HashMapper.new(self, self.data)
            end
            
            def get_storage(url='default')
                self.data
            end
            
        end
        
        def mapper
            return self.class.mapper
        end
        
        def ==(val)
            return super unless self.class.primary_keys.length == 1
            pk = self.class.primary_keys.first
            if pk.type == String || pk.type == Symbol
                if val.is_a?(String) || val.is_a?(Symbol)
                    return val.to_s == self.get(pk).to_s
                end
            elsif val.is_a?(pk.type)
                return val == self.get(pk)
            end
            return super
            
        end
        
    end
    
    
end; end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
spiderfw-1.0.1 lib/spiderfw/model/inline_model.rb
spiderfw-1.0.0 lib/spiderfw/model/inline_model.rb
spiderfw-0.6.39 lib/spiderfw/model/inline_model.rb
spiderfw-0.6.38 lib/spiderfw/model/inline_model.rb
spiderfw-0.6.37 lib/spiderfw/model/inline_model.rb
spiderfw-0.6.35 lib/spiderfw/model/inline_model.rb
spiderfw-0.6.34 lib/spiderfw/model/inline_model.rb
spiderfw-0.6.33 lib/spiderfw/model/inline_model.rb
spiderfw-0.6.32 lib/spiderfw/model/inline_model.rb
spiderfw-0.6.31 lib/spiderfw/model/inline_model.rb
spiderfw-0.6.30 lib/spiderfw/model/inline_model.rb
spiderfw-0.6.29 lib/spiderfw/model/inline_model.rb
spiderfw-0.6.28 lib/spiderfw/model/inline_model.rb
spiderfw-0.6.27 lib/spiderfw/model/inline_model.rb
spiderfw-0.6.26 lib/spiderfw/model/inline_model.rb
spiderfw-0.6.26.pre1 lib/spiderfw/model/inline_model.rb
spiderfw-0.6.25 lib/spiderfw/model/inline_model.rb
spiderfw-0.6.24 lib/spiderfw/model/inline_model.rb
spiderfw-0.6.23 lib/spiderfw/model/inline_model.rb
spiderfw-0.6.22 lib/spiderfw/model/inline_model.rb