lib/tire/model/persistence/attributes.rb
# 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.
#




You can pass mapping definition for Elasticsearch in the options Hash.

You can define default property values.
You can pass mapping definition for Elasticsearch in the options Hash . You can define default property values .
def property(name, options = {})
            define_method("#{name}") do
              instance_variable_get(:"@#{name}")
            end
            define_method("#{name}=") do |value|
              instance_variable_set(:"@#{name}", value)
            end
            properties << name.to_s unless properties.include?(name.to_s)
            define_query_method      name.to_sym
            define_attribute_methods [name.to_sym]
            unless (default_value = options.delete(:default)).nil?
              property_defaults[name.to_sym] = default_value
            end
            property_types[name.to_sym] = options[:class] if options[:class]
            if options[:class].is_a?(Array)
              property_defaults[name.to_sym] ||= []
            end
            mapping[name] = { :type => 'string' }.merge(options)
            self
          end
def property ( name , options = { } ) define_method ( "#{name}" ) do instance_variable_get ( :" @ #{ name } " ) end define_method ( "#{name}=" ) do | value | instance_variable_set ( :" @ #{ name } " , value ) end properties << name . to_s unless properties . include? ( name . to_s ) define_query_method name . to_sym define_attribute_methods [ name . to_sym ] unless ( default_value = options . delete ( :default ) ) . nil? property_defaults [ name . to_sym ] = default_value end property_types [ name . to_sym ] = options [ :class ] if options [ :class ] if options [ :class ] . is_a? ( Array ) property_defaults [ name . to_sym ] ||= [ ] end mapping [ name ] = { :type => 'string' } . merge ( options ) self end
Define property of the model:
class Article
include Tire::Model::Persistence
Define property of the model : class Article include Tire :: Model :: Persistence
# Define attribute reader: # Define attribute writer: # Save the property in properties array: # Define convenience <NAME>? method: # ActiveModel compatibility. NEEDED? # Save property default value (when relevant): # Save property casting (when relevant): # Define default value for colletions: # Store mapping for the property:
name
<not_specific>
options
<not_specific>