Class: Cloudsearchable::Field
- Inherits:
-
Object
- Object
- Cloudsearchable::Field
- Defined in:
- lib/cloudsearchable/field.rb
Overview
Represents a single field in a CloudSearch index.
Constant Summary collapse
- FieldTypes =
[:literal, :uint, :text].freeze
- FieldTypeOptionsNames =
Maps the type of field to the name of the options hash when defining the field
{:literal => :literal_options, :uint => :u_int_options, :text => :text_options}.freeze
- FieldTypeOptionsKeys =
Maps from field type to the allowed set of options for the field
{ literal: [:default_value, :facet_enabled, :search_enabled, :result_enabled].freeze, uint: [:default_value].freeze, text: [:default_value, :facet_enabled, :result_enabled].freeze }.freeze
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #define_in_domain(domain_name) ⇒ Object
-
#initialize(name, type, options = {}) ⇒ Field
constructor
A new instance of Field.
- #value_for(record) ⇒ Object
Constructor Details
#initialize(name, type, options = {}) ⇒ Field
Returns a new instance of Field.
23 24 25 26 27 28 29 |
# File 'lib/cloudsearchable/field.rb', line 23 def initialize(name, type, = {}) raise ArgumentError, "Invalid field type '#{type}'" unless FieldTypes.include?(type) @name = name.to_sym @type = type.to_sym @source = [:source] || @name @options = .slice(*FieldTypeOptionsKeys[@type]) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
21 22 23 |
# File 'lib/cloudsearchable/field.rb', line 21 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
21 22 23 |
# File 'lib/cloudsearchable/field.rb', line 21 def @options end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
21 22 23 |
# File 'lib/cloudsearchable/field.rb', line 21 def source @source end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
21 22 23 |
# File 'lib/cloudsearchable/field.rb', line 21 def type @type end |
Instance Method Details
#define_in_domain(domain_name) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/cloudsearchable/field.rb', line 39 def define_in_domain domain_name CloudSearch.client.define_index_field( :domain_name => domain_name, :index_field => definition ) end |
#value_for(record) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/cloudsearchable/field.rb', line 31 def value_for record if @source.respond_to?(:call) record.instance_exec &@source else record.send @source end end |