Class: DigitalOpera::Document::Fields::Standard
- Defined in:
- lib/digital_opera/document/fields/standard.rb
Instance Attribute Summary collapse
-
#default_val ⇒ Object
Defines the behaviour for defined fields in the document.
-
#label ⇒ Object
Defines the behaviour for defined fields in the document.
-
#name ⇒ Object
Defines the behaviour for defined fields in the document.
-
#options ⇒ Object
Defines the behaviour for defined fields in the document.
Instance Method Summary collapse
-
#eval_default(doc) ⇒ Object
Evaluate the default value and return it.
-
#initialize(name, options = {}) ⇒ Standard
constructor
Create the new field with a name and optional additional options.
-
#pre_processed? ⇒ true, false
Does the field pre-process its default value?.
-
#type ⇒ Class
Get the type of this field - inferred from the class name.
Constructor Details
#initialize(name, options = {}) ⇒ Standard
Create the new field with a name and optional additional options.
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/digital_opera/document/fields/standard.rb', line 43 def initialize(name, = {}) @name = name @options = @label = [:label] @default_val = [: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([:klass]) end end |
Instance Attribute Details
#default_val ⇒ Object
Defines the behaviour for defined fields in the document. Set readers for the instance variables.
7 8 9 |
# File 'lib/digital_opera/document/fields/standard.rb', line 7 def default_val @default_val end |
#label ⇒ Object
Defines the behaviour for defined fields in the document. Set readers for the instance variables.
7 8 9 |
# File 'lib/digital_opera/document/fields/standard.rb', line 7 def label @label end |
#name ⇒ Object
Defines the behaviour for defined fields in the document. Set readers for the instance variables.
7 8 9 |
# File 'lib/digital_opera/document/fields/standard.rb', line 7 def name @name end |
#options ⇒ Object
Defines the behaviour for defined fields in the document. Set readers for the instance variables.
7 8 9 |
# File 'lib/digital_opera/document/fields/standard.rb', line 7 def @options end |
Instance Method Details
#eval_default(doc) ⇒ Object
Evaluate the default value and return it. Will handle the serialization, proc calls, and duplication if necessary.
23 24 25 26 27 28 29 |
# 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 |
#pre_processed? ⇒ true, false
Does the field pre-process its default value?
65 66 67 68 |
# File 'lib/digital_opera/document/fields/standard.rb', line 65 def pre_processed? @pre_processed ||= ([:pre_processed] || (default_val && !default_val.is_a?(::Proc))) end |
#type ⇒ Class
Get the type of this field - inferred from the class name.
78 79 80 |
# File 'lib/digital_opera/document/fields/standard.rb', line 78 def type @type ||= [:type] || Object end |