README.md in ohm-1.0.0.rc4 vs README.md in ohm-1.0.0

- old
+ new

@@ -75,11 +75,11 @@ The other noteworthy style of connecting is by just doing `Ohm.connect` and set the environment variable `REDIS_URL`. Here are the options for {Ohm.connect} in detail: -### :url +### :url (recommended) A Redis URL of the form `redis://:<passwd>@<host>:<port>/<db>`. Note that if you specify a URL and one of the other options at the same time, the other options will take precedence. Also, if you try and do `Ohm.connect` without any arguments, it will check @@ -124,12 +124,12 @@ ### Example ```ruby class Event < Ohm::Model attribute :name - reference :venue, Venue - set :participants, Person + reference :venue, :Venue + set :participants, :Person counter :votes index :name def validate @@ -137,11 +137,11 @@ end end class Venue < Ohm::Model attribute :name - collection :events, Event + collection :events, :Event end class Person < Ohm::Model attribute :name end @@ -257,11 +257,11 @@ Given the following model declaration: ```ruby class Event < Ohm::Model attribute :name - set :attendees, Person + set :attendees, :Person end ``` You can add instances of `Person` to the set of attendees with the `add` method: @@ -347,16 +347,16 @@ ```ruby class Post < Ohm::Model attribute :title attribute :body - collection :comments, Comment + collection :comments, :Comment end class Comment < Ohm::Model attribute :body - reference :post, Post + reference :post, :Post end ``` After this, every time you refer to `post.comments` you will be talking about instances of the model `Comment`. If you want to get a list of IDs @@ -417,18 +417,18 @@ The only "magic" happening is with the inference of the `index` that was used in the other model. The following all produce the same effect: ```ruby # easiest, with the basic assumption that the index is `:post_id` -collection :comments, Comment +collection :comments, :Comment # we can explicitly declare this as follows too: -collection :comments, Comment, :post +collection :comments, :Comment, :post # finally, we can use the default argument for the third parameter which # is `to_reference`. -collection :comments, Comment, to_reference +collection :comments, :Comment, to_reference # exploring `to_reference` reveals a very interesting and simple concept: Post.to_reference == :post # => true ``` @@ -552,10 +552,55 @@ ```ruby assert_numeric :votes ``` +### assert_url + +Provides a pretty general URL regular expression match. An important +point to make is that this assumes that the URL should start with +`http://` or `https://`. The error code for this assertion is +`:not_url`. + +### assert_email + +In this current day and age, almost all web applications need to +validate an email address. This pretty much matches 99% of the emails +out there. The error code for this assertion is `:not_email`. + +### assert_member + +Checks that a given field is contained within a set of values (i.e. +like an `ENUM`). + +``` ruby +def validate + assert_member :state, %w{pending paid delivered} +end +``` + +The error code for this assertion is `:not_valid` + +### assert_length + +Checks that a given field's length falls under a specified range. + +``` ruby +def validate + assert_length :username, 3..20 +end +``` + +The error code for this assertion is `:not_in_range`. + +### assert_decimal + +Checks that a given field looks like a number in the human sense +of the word. Valid numbers are: 0.1, .1, 1, 1.1, 3.14159, etc. + +The error code for this assertion is `:not_decimal`. + Errors ------ When an assertion fails, the error report is added to the errors array. Each error report contains two elements: the field where the assertion @@ -588,53 +633,15 @@ A lot of amazing contributions are available at [Ohm Contrib][contrib] make sure to check them if you need to extend Ohm's functionality. [contrib]: http://cyx.github.com/ohm-contrib/doc/ -Tutorials +Upgrading ========= -NOTE: These tutorials were written against Ohm 0.1.x. Please give us -a while to fully update all of them. - -Check the examples to get a feeling of the design patterns for Redis. - -1. [Activity Feed](http://ohm.keyvalue.org/examples/activity-feed.html) -2. [Chaining finds](http://ohm.keyvalue.org/examples/chaining.html) -3. [Serialization to JSON](http://ohm.keyvalue.org/examples/json-hash.html) -4. [One to many associations](http://ohm.keyvalue.org/examples/one-to-many.html) -5. [Philosophy behind Ohm](http://ohm.keyvalue.org/examples/philosophy.html) -6. [Learning Ohm internals](http://ohm.keyvalue.org/examples/redis-logging.html) -7. [Slugs and permalinks](http://ohm.keyvalue.org/examples/slug.html) -8. [Tagging](http://ohm.keyvalue.org/examples/tagging.html) - - -Versions -======== - -Ohm uses features from Redis > 2.6.x. If you are stuck in previous -versions, please use Ohm 0.1.x instead. - -Upgrading from 0.0.x to 0.1 ---------------------------- - -Since Ohm 0.1 changes the persistence strategy (from 1-key-per-attribute -to Hashes), you'll need to run a script to upgrade your old data set. -Fortunately, it is built in: - -```ruby -require "ohm/utils/upgrade" - -Ohm.connect :port => 6380 - -Ohm::Utils::Upgrade.new([:User, :Post, :Comment]).run -``` - -Yes, you need to provide the model names. The good part is that you -don't have to load your application environment. Since we assume it's -very likely that you have a bunch of data, the script uses -[Batch](http://github.com/djanowski/batch) to show you some progress -while the process runs. - +The changes in Ohm 1 break the compatibility with previous versions. +We will do our best to provide a script to ease the pain of upgrading. +In the meantime, it's recommended that you use the new version only +for new projects. [redis]: http://redis.io [ohm]: http://github.com/soveran/ohm