Ohm v2.0.0 Release Notes
-
- Lists now respond to range.
Example:
class Comment < Ohm::Model end class Post < Ohm::Model list :comments, :Comment end c1 = Comment.create c2 = Comment.create c3 = Comment.create post = Post.create post.comments.push(c1) post.comments.push(c2) post.comments.push(c3) post.comments.range(0, 1) == [c1, c2] # => true
- When a record is created,
#id
returns a string instead of an integer. This ensures IDs are strings everywhere:
Example:
# Before Meetup.create(name: "Ruby").id # => 1 Meetup.with(:name, "Ruby").id # => "1" # Now Meetup.create(name: "Ruby").id # => "1" Meetup.with(:name, "Ruby").id # => "1"
- If an attribute is set to an empty string, Ohm won't delete it.
Example:
# Before event = Meetup.create(location: "") Meetup[event.id].location # => nil # Now event = Meetup.create(location: "") Meetup[event.id].location # => ""
- Include
Ohm::List#ids
in the public API. It returns an array with all the ID's in the list.
Example:
class Comment < Ohm::Model end class Post < Ohm::Model list :comments, :Comment end post = Post.create post.comments.push(Comment.create) post.comments.push(Comment.create) post.comments.push(Comment.create) post.comments.ids # => ["1", "2", "3"]
- Include
Ohm::BasicSet#exists?
in the public API. This makes possible to check if an id is included in a set. CheckOhm::BasicSet#exists?
documentation for more details.
Example:
class Post < Ohm::Model end class User < Ohm::Model set :posts, :Post end user = User.create user.posts.add(post = Post.create) user.posts.exists?(post.id) # => true user.posts.exists?("nonexistent") # => false
- ๐ Change
Ohm::MultiSet#except
to union keys instead of intersect them when passing an array.
Example:
class User < Ohm::Model attribute :name end john = User.create(name: "John") jane = User.create(name: "Jane") res = User.all.except(name: [john.name, jane.name]) # Before res.size # => 2 # Now res.size # => 0
๐ Move ID generation to Lua. With this change, it's no longer possible to generate custom ids. All ids are autoincremented.
โ Add
Ohm::Model.track
method to allow track of custom keys. This key is removed when the model is deleted.
Example:
class Foo < Ohm::Model track :notes end foo = Foo.create Foo.redis.call("SET", foo.key[:notes], "something") Foo.redis.call("GET", "Foo:1:notes") # => "something" foo.delete Foo.redis.call("GET", "Foo:1:notes") # => nil
Ohm::Model#reference
accepts strings as model references.
Example:
class Bar < Ohm::Model reference :foo, "SomeNamespace::Foo" end Bar.create.foo.class # => SomeNamespace::Foo
Ohm::Model#save
sanitizes attributes before sending them to Lua. This complies with the original spec in Ohm v1 where ato_s
is done on each value.
Example:
class Post < Ohm::Model attribute :published end post = Post.create(published: true) post = Post[post.id] # Before post.published # => "1" # Now post.published # => "true"
Ohm::Model#save
don't save values for attributes set to false.
Example:
class Post < Ohm::Model attribute :published end post = Post.create(published: false) post = Post[post.id] # Before post.published # => "0" # Now post.published # => nil
๐
nest
dependency has been removed. Now, Ohm uses nido to generate the keys that hold the data.๐
scrivener
dependency has been removed. Ohm no longer supports model validations and favors filter validation on the boundary layer. Check scrivener project for more information.๐
redis
dependency has been removed. Ohm 2 uses redic, a lightweight Redis client. Redic uses thehiredis
gem for the connection and for parsing the replies. Now, it defaults to a Redic connection to "redis://127.0.0.1:6379". To change it, you will need to provide an instance ofRedic
through theOhm.redis=
helper.
Example:
Ohm.redis = Redic.new("redis://:<passwd>@<host>:<port>/<db>")
Check the Redic README for more details.
๐
Ohm::Model#transaction
andOhm::Transaction
have been removed.๐ Move
save
anddelete
operations to Lua scripts.๐ Support for Ruby 1.8 has been removed.