Sha256: 2d2f2fb4a7945358158e86288ba2f3c02bb1f40da0050a8a6e0e52b3317fd122

Contents?: true

Size: 848 Bytes

Versions: 3

Compression:

Stored size: 848 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

3 entries across 3 versions & 1 rubygems

Version Path
sinatra_resource-0.4.24 examples/datacatalog/models/source.rb
sinatra_resource-0.4.23 examples/datacatalog/models/source.rb
sinatra_resource-0.4.22 examples/datacatalog/models/source.rb