class DigitalOpera::Document::Fields::Standard
Attributes
Defines the behaviour for defined fields in the document. Set readers for the instance variables.
Defines the behaviour for defined fields in the document. Set readers for the instance variables.
Defines the behaviour for defined fields in the document. Set readers for the instance variables.
Defines the behaviour for defined fields in the document. Set readers for the instance variables.
Public Class Methods
Create the new field with a name and optional additional options.
@example Create the new field.
Field.new(:name, :type => String)
@param [ Hash ] options The field options.
@option options [ Class ] :type The class of the field. @option options [ Object
] :default The default value for the field. @option options [ String ] :label The field’s label.
@since 3.0.0
# File lib/digital_opera/document/fields/standard.rb, line 43 def initialize(name, options = {}) @name = name @options = options @label = options[:label] @default_val = options[:default] # @todo: Durran, change API in 4.0 to take the class as a parameter. # This is here temporarily to address #2529 without changing the # constructor signature. if default_val.respond_to?(:call) define_default_method(options[:klass]) end end
Public Instance Methods
Evaluate the default value and return it. Will handle the serialization, proc calls, and duplication if necessary.
@example Evaluate the default value.
field.eval_default(document)
@param [ Document
] doc The document the field belongs to.
@return [ Object
] The serialized default value.
@since 2.1.8
# File lib/digital_opera/document/fields/standard.rb, line 23 def eval_default(doc) if fields = Threaded.selection(doc.criteria_instance_id) evaluated_default(doc) if included?(fields) else evaluated_default(doc) end end
Does the field pre-process its default value?
@example Does the field pre-process the default?
field.pre_processed?
@return [ true, false ] If the field’s default is pre-processed.
@since 3.0.0
# File lib/digital_opera/document/fields/standard.rb, line 65 def pre_processed? @pre_processed ||= (options[:pre_processed] || (default_val && !default_val.is_a?(::Proc))) end
Get the type of this field - inferred from the class name.
@example Get the type.
field.type
@return [ Class ] The name of the class.
@since 2.1.0
# File lib/digital_opera/document/fields/standard.rb, line 78 def type @type ||= options[:type] || Object end