Sha256: 4cfc4fd060e6587e93d7d2808e1db58f40ff25ebf8c0f3dbed45efeb0fb49e8f

Contents?: true

Size: 858 Bytes

Versions: 22

Compression:

Stored size: 858 Bytes

Contents

module DataCatalog
  
  class Source

    include MongoMapper::Document

    # == Attributes

    key :title,       String
    key :description, String
    key :url,         String
    key :raw,         Hash
    key :_keywords,   Array
    timestamps!

    # == Indices

    ensure_index :url

    # == Associations

    many :usages,
      :class_name  => 'DataCatalog::Usage',
      :foreign_key => :source_id

    many :categorizations,
      :class_name  => 'DataCatalog::Categorization',
      :foreign_key => :source_id

    def categories
      categorizations.map(&:category)
    end

    # == Validations

    validates_presence_of :title
    validates_presence_of :url
    
    # == Callbacks
    
    before_save :update_keywords
    def update_keywords
      self._keywords = DataCatalog::Search.process([title, description])
    end

  end

end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
sinatra_resource-0.4.1 examples/datacatalog/models/source.rb
sinatra_resource-0.4.0 examples/datacatalog/models/source.rb