--- !ruby/object:RI::ClassDescription 
attributes: 
- !ruby/object:RI::Attribute 
  comment: 
  name: default
  rw: R
- !ruby/object:RI::Attribute 
  comment: 
  name: instance_variable_name
  rw: R
- !ruby/object:RI::Attribute 
  comment: 
  name: max
  rw: R
- !ruby/object:RI::Attribute 
  comment: 
  name: min
  rw: R
- !ruby/object:RI::Attribute 
  comment: 
  name: model
  rw: R
- !ruby/object:RI::Attribute 
  comment: 
  name: name
  rw: R
- !ruby/object:RI::Attribute 
  comment: 
  name: options
  rw: R
- !ruby/object:RI::Attribute 
  comment: 
  name: precision
  rw: R
- !ruby/object:RI::Attribute 
  comment: 
  name: primitive
  rw: R
- !ruby/object:RI::Attribute 
  comment: 
  name: reader_visibility
  rw: R
- !ruby/object:RI::Attribute 
  comment: 
  name: repository_name
  rw: R
- !ruby/object:RI::Attribute 
  comment: 
  name: scale
  rw: R
- !ruby/object:RI::Attribute 
  comment: 
  name: type
  rw: R
- !ruby/object:RI::Attribute 
  comment: 
  name: writer_visibility
  rw: R
class_methods: 
- !ruby/object:RI::MethodSummary 
  name: new
comment: 
- !ruby/struct:SM::Flow::H 
  level: 1
  text: Quick Links
- !ruby/object:SM::Flow::LIST 
  contents: 
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: Setup and Configuration - DataMapper
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: Finders and CRUD -
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: Properties - DataMapper::Property
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: FAQ[link:/files/FAQ.html]
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: Contact Us
  - !ruby/object:SM::Flow::LIST 
    contents: 
    - !ruby/struct:SM::Flow::LI 
      label: "*"
      body: Website - http://www.datamapper.org
    - !ruby/struct:SM::Flow::LI 
      label: "*"
      body: Bug Reports - http://datamapper.lighthouseapp.com
    - !ruby/struct:SM::Flow::LI 
      label: "*"
      body: IRC Channel - <tt>##datamapper</tt> on irc.freenode.net
    - !ruby/struct:SM::Flow::LI 
      label: "*"
      body: Mailing List - http://groups.google.com/group/datamapper/
    type: :BULLET
  type: :BULLET
- !ruby/struct:SM::Flow::H 
  level: 1
  text: Properties
- !ruby/struct:SM::Flow::P 
  body: Properties for a model are not derived from a database structure, but instead explicitly declared inside your model class definitions. These properties then map (or, if using automigrate, generate) fields in your repository/database.
- !ruby/struct:SM::Flow::P 
  body: "If you are coming to DataMapper from another ORM framework, such as ActiveRecord, this may be a fundamental difference in thinking to you. However, there are several advantages to defining your properties in your models:"
- !ruby/object:SM::Flow::LIST 
  contents: 
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: "information about your model is centralized in one place: rather than having to dig out migrations, xml or other configuration files."
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: "use of mixins can be applied to model properties: better code reuse"
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: having information centralized in your models, encourages you and the developers on your team to take a model-centric view of development.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: it provides the ability to use Ruby's access control functions.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: and, because DataMapper only cares about properties explicitly defined
  type: :BULLET
- !ruby/struct:SM::Flow::P 
  body: in
- !ruby/struct:SM::Flow::VERB 
  body: "  your models, DataMapper plays well with legacy databases, and shares\n  databases easily with other applications.\n"
- !ruby/struct:SM::Flow::H 
  level: 2
  text: Declaring Properties
- !ruby/struct:SM::Flow::P 
  body: Inside your class, you call the property method for each property you want to add. The only two required arguments are the name and type, everything else is optional.
- !ruby/struct:SM::Flow::VERB 
  body: "  class Post\n    include DataMapper::Resource\n\n    property :title,   String,  :nullable =&gt; false  # Cannot be null\n    property :publish, Boolean, :default =&gt; false   # Default value for new records is false\n  end\n"
- !ruby/struct:SM::Flow::P 
  body: "By default, DataMapper supports the following primitive (Ruby) types also called core types:"
- !ruby/object:SM::Flow::LIST 
  contents: 
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: Boolean
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: String (default length is 50)
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: Text (limit of 65k characters by default)
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: Float
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: Integer
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: BigDecimal
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: DateTime
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: Date
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: Time
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: Object (marshalled out during serialization)
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: Class (datastore primitive is the same as String. Used for Inheritance)
  type: :BULLET
- !ruby/struct:SM::Flow::P 
  body: Other types are known as custom types.
- !ruby/struct:SM::Flow::P 
  body: For more information about available Types, see DataMapper::Type
- !ruby/struct:SM::Flow::H 
  level: 2
  text: Limiting Access
- !ruby/struct:SM::Flow::P 
  body: Property access control is uses the same terminology Ruby does. Properties are public by default, but can also be declared private or protected as needed (via the :accessor option).
- !ruby/struct:SM::Flow::VERB 
  body: " class Post\n  include DataMapper::Resource\n\n   property :title, String, :accessor =&gt; :private    # Both reader and writer are private\n   property :body,  Text,   :accessor =&gt; :protected  # Both reader and writer are protected\n end\n"
- !ruby/struct:SM::Flow::P 
  body: Access control is also analogous to Ruby attribute readers and writers, and can be declared using :reader and :writer, in addition to :accessor.
- !ruby/struct:SM::Flow::VERB 
  body: " class Post\n   include DataMapper::Resource\n\n   property :title, String, :writer =&gt; :private    # Only writer is private\n   property :tags,  String, :reader =&gt; :protected  # Only reader is protected\n end\n"
- !ruby/struct:SM::Flow::H 
  level: 2
  text: Overriding Accessors
- !ruby/struct:SM::Flow::P 
  body: "The reader/writer for any property can be overridden in the same manner that Ruby attr readers/writers can be. After the property is defined, just add your custom reader or writer:"
- !ruby/struct:SM::Flow::VERB 
  body: " class Post\n   include DataMapper::Resource\n\n   property :title, String\n\n   def title=(new_title)\n     raise ArgumentError if new_title != 'Luke is Awesome'\n     @title = new_title\n   end\n end\n"
- !ruby/struct:SM::Flow::H 
  level: 2
  text: Lazy Loading
- !ruby/struct:SM::Flow::P 
  body: "By default, some properties are not loaded when an object is fetched in DataMapper. These lazily loaded properties are fetched on demand when their accessor is called for the first time (as it is often unnecessary to instantiate -every- property -every- time an object is loaded). For instance, DataMapper::Types::Text fields are lazy loading by default, although you can over-ride this behavior if you wish:"
- !ruby/struct:SM::Flow::P 
  body: "Example:"
- !ruby/struct:SM::Flow::VERB 
  body: " class Post\n   include DataMapper::Resource\n\n   property :title, String  # Loads normally\n   property :body,  Text    # Is lazily loaded by default\n end\n"
- !ruby/struct:SM::Flow::P 
  body: If you want to over-ride the lazy loading on any field you can set it to a context or false to disable it with the :lazy option. Contexts allow multipule lazy properties to be loaded at one time. If you set :lazy to true, it is placed in the :default context
- !ruby/struct:SM::Flow::VERB 
  body: " class Post\n   include DataMapper::Resource\n\n   property :title,   String                                    # Loads normally\n   property :body,    Text,   :lazy =&gt; false                    # The default is now over-ridden\n   property :comment, String, :lazy =&gt; [ :detailed ]            # Loads in the :detailed context\n   property :author,  String, :lazy =&gt; [ :summary, :detailed ]  # Loads in :summary &amp; :detailed context\n end\n"
- !ruby/struct:SM::Flow::P 
  body: Delaying the request for lazy-loaded attributes even applies to objects accessed through associations. In a sense, DataMapper anticipates that you will likely be iterating over objects in associations and rolls all of the load commands for lazy-loaded properties into one request from the database.
- !ruby/struct:SM::Flow::P 
  body: "Example:"
- !ruby/struct:SM::Flow::VERB 
  body: "  Widget.get(1).components\n    # loads when the post object is pulled from database, by default\n\n  Widget.get(1).components.first.body\n    # loads the values for the body property on all objects in the\n    # association, rather than just this one.\n\n  Widget.get(1).components.first.comment\n    # loads both comment and author for all objects in the association\n    # since they are both in the :detailed context\n"
- !ruby/struct:SM::Flow::H 
  level: 2
  text: Keys
- !ruby/struct:SM::Flow::P 
  body: "Properties can be declared as primary or natural keys on a table. You should a property as the primary key of the table:"
- !ruby/struct:SM::Flow::P 
  body: "Examples:"
- !ruby/struct:SM::Flow::VERB 
  body: " property :id,        Serial                # auto-incrementing key\n property :legacy_pk, String, :key =&gt; true  # 'natural' key\n"
- !ruby/struct:SM::Flow::P 
  body: This is roughly equivalent to ActiveRecord's <tt>set_primary_key</tt>, though non-integer data types may be used, thus DataMapper supports natural keys. When a property is declared as a natural key, accessing the object using the indexer syntax <tt>Class[key]</tt> remains valid.
- !ruby/struct:SM::Flow::VERB 
  body: "  User.get(1)\n     # when :id is the primary key on the users table\n  User.get('bill')\n     # when :name is the primary (natural) key on the users table\n"
- !ruby/struct:SM::Flow::H 
  level: 2
  text: Indices
- !ruby/struct:SM::Flow::P 
  body: You can add indices for your properties by using the <tt>:index</tt> option. If you use <tt>true</tt> as the option value, the index will be automatically named. If you want to name the index yourself, use a symbol as the value.
- !ruby/struct:SM::Flow::VERB 
  body: "  property :last_name,  String, :index =&gt; true\n  property :first_name, String, :index =&gt; :name\n"
- !ruby/struct:SM::Flow::P 
  body: You can create multi-column composite indices by using the same symbol in all the columns belonging to the index. The columns will appear in the index in the order they are declared.
- !ruby/struct:SM::Flow::VERB 
  body: "  property :last_name,  String, :index =&gt; :name\n  property :first_name, String, :index =&gt; :name\n     # =&gt; index on (last_name, first_name)\n"
- !ruby/struct:SM::Flow::P 
  body: If you want to make the indices unique, use <tt>:unique_index</tt> instead of <tt>:index</tt>
- !ruby/struct:SM::Flow::H 
  level: 2
  text: Inferred Validations
- !ruby/struct:SM::Flow::P 
  body: "If you require the dm-validations plugin, auto-validations will automatically be mixed-in in to your model classes: validation rules that are inferred when properties are declared with specific column restrictions."
- !ruby/struct:SM::Flow::VERB 
  body: " class Post\n   include DataMapper::Resource\n\n   property :title, String, :length =&gt; 250\n     # =&gt; infers 'validates_length :title,\n            :minimum =&gt; 0, :maximum =&gt; 250'\n\n   property :title, String, :nullable =&gt; false\n     # =&gt; infers 'validates_present :title\n\n   property :email, String, :format =&gt; :email_address\n     # =&gt; infers 'validates_format :email, :with =&gt; :email_address\n\n   property :title, String, :length =&gt; 255, :nullable =&gt; false\n     # =&gt; infers both 'validates_length' as well as\n     #    'validates_present'\n     #    better: property :title, String, :length =&gt; 1..255\n\n end\n"
- !ruby/struct:SM::Flow::P 
  body: This functionality is available with the dm-validations gem, part of the dm-more bundle. For more information about validations, check the documentation for dm-validations.
- !ruby/struct:SM::Flow::H 
  level: 2
  text: Default Values
- !ruby/struct:SM::Flow::P 
  body: To set a default for a property, use the <tt>:default</tt> key. The property will be set to the value associated with that key the first time it is accessed, or when the resource is saved if it hasn't been set with another value already. This value can be a static value, such as 'hello' but it can also be a proc that will be evaluated when the property is read before its value has been set. The property is set to the return of the proc. The proc is passed two values, the resource the property is being set for and the property itself.
- !ruby/struct:SM::Flow::VERB 
  body: "  property :display_name, String, :default =&gt; { |resource, property| resource.login }\n"
- !ruby/struct:SM::Flow::P 
  body: Word of warning. Don't try to read the value of the property you're setting the default for in the proc. An infinite loop will ensue.
- !ruby/struct:SM::Flow::H 
  level: 2
  text: Embedded Values
- !ruby/struct:SM::Flow::P 
  body: As an alternative to extraneous has_one relationships, consider using an EmbeddedValue.
- !ruby/struct:SM::Flow::H 
  level: 2
  text: Property options reference
- !ruby/struct:SM::Flow::VERB 
  body: " :accessor            if false, neither reader nor writer methods are\n                      created for this property\n\n :reader              if false, reader method is not created for this property\n\n :writer              if false, writer method is not created for this property\n\n :lazy                if true, property value is only loaded when on first read\n                      if false, property value is always loaded\n                      if a symbol, property value is loaded with other properties\n                      in the same group\n\n :default             default value of this property\n\n :nullable            if true, property may have a nil value on save\n\n :key                 name of the key associated with this property.\n\n :serial              if true, field value is auto incrementing\n\n :field               field in the data-store which the property corresponds to\n\n :length              string field length\n\n :format              format for autovalidation. Use with dm-validations plugin.\n\n :index               if true, index is created for the property. If a Symbol, index\n                      is named after Symbol value instead of being based on property name.\n\n :unique_index        true specifies that index on this property should be unique\n\n :auto_validation     if true, automatic validation is performed on the property\n\n :validates           validation context. Use together with dm-validations.\n\n :unique              if true, property column is unique. Properties of type Serial\n                      are unique by default.\n\n :precision           Indicates the number of significant digits. Usually only makes sense\n                      for float type properties. Must be &gt;= scale option value. Default is 10.\n\n :scale               The number of significant digits to the right of the decimal point.\n                      Only makes sense for float type properties. Must be &gt; 0.\n                      Default is nil for Float type and 10 for BigDecimal type.\n\n All other keys you pass to <tt>property</tt> method are stored and available\n as options[:extra_keys].\n"
- !ruby/struct:SM::Flow::H 
  level: 2
  text: Misc. Notes
- !ruby/object:SM::Flow::LIST 
  contents: 
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: Properties declared as strings will default to a length of 50, rather than 255 (typical max varchar column size). To overload the default, pass <tt>:length =&gt; 255</tt> or <tt>:length =&gt; 0..255</tt>. Since DataMapper does not introspect for properties, this means that legacy database tables may need their <tt>String</tt> columns defined with a <tt>:length</tt> so that DM does not apply an un-needed length validation, or allow overflow.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: You may declare a Property with the data-type of <tt>Class</tt>. see SingleTableInheritance for more on how to use <tt>Class</tt> columns.
  type: :BULLET
constants: 
- !ruby/object:RI::Constant 
  comment: 
  - !ruby/struct:SM::Flow::P 
    body: "NOTE: PLEASE update OPTIONS in DataMapper::Type when updating them here"
  name: OPTIONS
  value: "[       :accessor, :reader, :writer,       :lazy, :default, :nullable, :key, :serial, :field, :size, :length,       :format, :index, :unique_index, :auto_validation,       :validates, :unique, :precision, :scale, :min, :max"
- !ruby/object:RI::Constant 
  comment: 
  name: PRIMITIVES
  value: "[       TrueClass,       String,       Float,       Integer,       BigDecimal,       DateTime,       Date,       Time,       Object,       Class,     ].to_set.freeze"
- !ruby/object:RI::Constant 
  comment: 
  - !ruby/struct:SM::Flow::P 
    body: Possible :visibility option values
  name: VISIBILITY_OPTIONS
  value: "[ :public, :protected, :private ].to_set.freeze"
- !ruby/object:RI::Constant 
  comment: 
  name: DEFAULT_LENGTH
  value: "50"
- !ruby/object:RI::Constant 
  comment: 
  name: DEFAULT_PRECISION
  value: "10"
- !ruby/object:RI::Constant 
  comment: 
  name: DEFAULT_SCALE_BIGDECIMAL
  value: "0"
- !ruby/object:RI::Constant 
  comment: 
  name: DEFAULT_SCALE_FLOAT
  value: nil
- !ruby/object:RI::Constant 
  comment: 
  name: DEFAULT_NUMERIC_MIN
  value: "0"
- !ruby/object:RI::Constant 
  comment: 
  name: DEFAULT_NUMERIC_MAX
  value: 2**31-1
full_name: DataMapper::Property
includes: 
- !ruby/object:RI::IncludedModule 
  name: Extlib::Assertions
instance_methods: 
- !ruby/object:RI::MethodSummary 
  name: custom?
- !ruby/object:RI::MethodSummary 
  name: default?
- !ruby/object:RI::MethodSummary 
  name: default_for
- !ruby/object:RI::MethodSummary 
  name: field
- !ruby/object:RI::MethodSummary 
  name: get
- !ruby/object:RI::MethodSummary 
  name: get!
- !ruby/object:RI::MethodSummary 
  name: hash
- !ruby/object:RI::MethodSummary 
  name: index
- !ruby/object:RI::MethodSummary 
  name: inspect
- !ruby/object:RI::MethodSummary 
  name: key?
- !ruby/object:RI::MethodSummary 
  name: lazy?
- !ruby/object:RI::MethodSummary 
  name: lazy_load
- !ruby/object:RI::MethodSummary 
  name: lazy_load_properties
- !ruby/object:RI::MethodSummary 
  name: length
- !ruby/object:RI::MethodSummary 
  name: loaded?
- !ruby/object:RI::MethodSummary 
  name: nullable?
- !ruby/object:RI::MethodSummary 
  name: primitive?
- !ruby/object:RI::MethodSummary 
  name: properties
- !ruby/object:RI::MethodSummary 
  name: serial?
- !ruby/object:RI::MethodSummary 
  name: set
- !ruby/object:RI::MethodSummary 
  name: set!
- !ruby/object:RI::MethodSummary 
  name: set_original_value
- !ruby/object:RI::MethodSummary 
  name: typecast
- !ruby/object:RI::MethodSummary 
  name: unique?
- !ruby/object:RI::MethodSummary 
  name: unique_index
- !ruby/object:RI::MethodSummary 
  name: valid?
- !ruby/object:RI::MethodSummary 
  name: value
name: Property
superclass: Object
