| Module | Ribs::Repository::ClassMethods |
| In: |
lib/ribs/repository.rb
|
The ClassMethods are everything that‘s available when getting the repository for a specific model class. It includes most of the things you‘d expect to do on the class itself in ActiveRecord - stuff like finders, creators and things like that.
First creates a model object based on the values in attrs and then saves this to the database directly.
# File lib/ribs/repository.rb, line 98
98: def create(attrs = {})
99: val = new(attrs)
100: R(val, self.database).save
101: val
102: end
Define accessors for this model
# File lib/ribs/repository.rb, line 60
60: def define_accessors
61: self.metadata.properties_and_identity.each do |name, _|
62: self.model.send :attr_accessor, name.downcase
63: end
64: end
Destroys the model with the id id.
# File lib/ribs/repository.rb, line 120
120: def destroy(id)
121: Ribs.with_handle(self.database) do |h|
122: h.delete(get(id))
123: end
124: end
Get the meta data for this model
# File lib/ribs/repository.rb, line 55
55: def metadata
56: @metadata
57: end
Makes a specific instance of this class be marked persistent
# File lib/ribs/repository.rb, line 67
67: def persistent(obj)
68: (@persistent ||= {})[obj.object_id] = true
69: end
Checks if a specific instance is marked as persistent
# File lib/ribs/repository.rb, line 72
72: def persistent?(obj)
73: @persistent && @persistent[obj.object_id]
74: end