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.

Methods

Included Modules

Repository

Public Instance methods

Returns all instances for the current model

[Source]

     # File lib/ribs/repository.rb, line 105
105:       def all
106:         Ribs.with_handle(self.database) do |h|
107:           h.all(self.metadata.persistent_class.entity_name)
108:         end
109:       end

First creates a model object based on the values in attrs and then saves this to the database directly.

[Source]

     # 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

[Source]

    # 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.

[Source]

     # 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

Makes a specific instance of this class be marked destroyed

[Source]

    # File lib/ribs/repository.rb, line 77
77:       def destroyed(obj)
78:         (@destroyed ||= {})[obj.object_id] = true
79:       end

Checks if a specific instance is marked as destroyed

[Source]

    # File lib/ribs/repository.rb, line 82
82:       def destroyed?(obj)
83:         @destroyed && @destroyed[obj.object_id]
84:       end

Will get the instance with id or return nil if no such entity exists.

[Source]

     # File lib/ribs/repository.rb, line 113
113:       def get(id)
114:         Ribs.with_handle(self.database) do |h|
115:           h.get(self.metadata.persistent_class.entity_name, id)
116:         end
117:       end

Get the meta data for this model

[Source]

    # File lib/ribs/repository.rb, line 55
55:       def metadata
56:         @metadata
57:       end

Create a new instance of this model object, optionally setting properties based on attrs.

[Source]

    # File lib/ribs/repository.rb, line 88
88:       def new(attrs = {})
89:         obj = self.model.new
90:         attrs.each do |k,v|
91:           obj.send("#{k}=", v)
92:         end
93:         obj
94:       end

Makes a specific instance of this class be marked persistent

[Source]

    # 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

[Source]

    # File lib/ribs/repository.rb, line 72
72:       def persistent?(obj)
73:         @persistent && @persistent[obj.object_id]
74:       end

[Validate]