class TFSGraph::Repository
Constants
- NotFound
Attributes
type[R]
Public Class Methods
new(type)
click to toggle source
# File lib/tfs_graph/repository.rb, line 17 def initialize(type) @type = type add_behavior self, constantize("TFSGraph::Behaviors::#{self.base_class_name}::#{type.base_class_name}") # register self as the server type ServerRegistry.server(self) end
Public Instance Methods
build(args={})
click to toggle source
# File lib/tfs_graph/repository.rb, line 53 def build(args={}) @type.new self, args end
create(args)
click to toggle source
# File lib/tfs_graph/repository.rb, line 64 def create(args) object = build(args) save(object) end
delete(obj)
click to toggle source
# File lib/tfs_graph/repository.rb, line 48 def delete(obj) obj.db_object = nil obj.id = nil end
exists?(id)
click to toggle source
# File lib/tfs_graph/repository.rb, line 30 def exists?(id) begin find_native(id) true rescue NotFound false end end
find(id)
click to toggle source
# File lib/tfs_graph/repository.rb, line 26 def find(id) rebuild find_native(id) end
inspect()
click to toggle source
# File lib/tfs_graph/repository.rb, line 69 def inspect type end
rebuild(db_object)
click to toggle source
# File lib/tfs_graph/repository.rb, line 57 def rebuild(db_object) attributes = HashWithIndifferentAccess.new db_object.attributes obj = build attributes obj.persist get_id(db_object), db_object end
save(object)
click to toggle source
# File lib/tfs_graph/repository.rb, line 43 def save(object) db_object = object.persisted? ? update(object) : persist(object) object.persist get_id(db_object), db_object end
Private Instance Methods
normalize(attrs)
click to toggle source
# File lib/tfs_graph/repository.rb, line 74 def normalize(attrs) HashWithIndifferentAccess.new attrs end