Module: DigitalOpera::Document::ClassMethods

Defined in:
lib/digital_opera/document.rb

Instance Method Summary collapse

Instance Method Details

#field(name, options = {}) ⇒ Field

Defines all the fields that are accessible on the Document For each field that is defined, a getter and setter will be added as an instance method to the Document.

Examples:

Define a field.

field :score, :type => Integer, :default => 0

Parameters:

  • name (Symbol)

    The name of the field.

  • options (Hash) (defaults to: {})

    The options to pass to the field.

Returns:

  • (Field)

    The generated field



31
32
33
34
35
36
37
38
# File 'lib/digital_opera/document.rb', line 31

def field(name, options = {})
  named = name.to_s
  added = add_field(named, options)
  descendants.each do |subclass|
    subclass.add_field(named, options)
  end
  added
end