Sha256: 8a674b19b599f6d0823c60af93e74d3cc7a0f53cd12a2c6476bb7ea5180dac0b

Contents?: true

Size: 844 Bytes

Versions: 1

Compression:

Stored size: 844 Bytes

Contents

require_relative './persistence_base'
require_relative './collection'
module CommonRepositoryModel
  class Area < PersistenceBase

    has_many(
      :collections,
      class_name: 'CommonRepositoryModel::Collection',
      property: :is_member_of_area
    )

    has_metadata(name: "properties",type: ActiveFedora::SimpleDatastream) do |m|
      m.field 'name', :string
    end

    validates :name, presence: true

    delegate_to 'properties', [:name], unique: true

    def self.find_by_name(name)
      find({name_s: name}).first
    end

    def self.find_by_name!(name)
      find({name_s: name.to_s}).first ||
      raise(
        CommonRepositoryModel::ObjectNotFoundError.new(
          "#{self} with name: #{name.to_s} not found"
        )
      )
    end

    # We shouldn't be calling these
    protected :save, :save!
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
common_repository_model-0.0.5 lib/common_repository_model/area.rb