# File lib/tire/model/persistence/attributes.rb, line 60 def properties @properties ||= [] end
Define property of the model:
class Article include Tire::Model::Persistence property :title, :analyzer => 'snowball' property :published, :type => 'date' property :tags, :analyzer => 'keywords', :default => [] end
You can pass mapping definition for ElasticSearch in the options Hash.
You can define default property values.
# File lib/tire/model/persistence/attributes.rb, line 26 def property(name, options = {}) # Define attribute reader: define_method("#{name}") do instance_variable_get(:"@#{name}") || self.class.property_defaults[name.to_sym] end # Define attribute writer: define_method("#{name}=") do |value| instance_variable_set(:"@#{name}", value) end # Save the property in properties array: properties << name.to_s unless properties.include?(name.to_s) # Define convenience <NAME>? method: define_query_method name.to_sym # ActiveModel compatibility. NEEDED? define_attribute_methods [name.to_sym] # Save property default value (when relevant): unless (default_value = options.delete(:default)).nil? property_defaults[name.to_sym] = default_value end # Save property casting (when relevant): property_types[name.to_sym] = options[:class] if options[:class] # Store mapping for the property: mapping[name] = options self end
# File lib/tire/model/persistence/attributes.rb, line 64 def property_defaults @property_defaults ||= {} end
# File lib/tire/model/persistence/attributes.rb, line 68 def property_types @property_types ||= {} end