Class: RDFMapper::Adapters::Rails

Inherits:
Base
  • Object
show all
Defined in:
lib/lib/adapters/rails.rb

Overview

-

Defined Under Namespace

Classes: Query

Instance Method Summary collapse

Methods included from Logger

#debug, #fatal, #warn

Constructor Details

#initialize(cls, options = {}) ⇒ Rails

-


11
12
13
14
15
16
# File 'lib/lib/adapters/rails.rb', line 11

def initialize(cls, options = {})
  @rdf, @options = cls, options
  @options[:skip] ||= []
  @options[:substitute] ||= { }
  @options[:substitute][:id] ||= :uid
end

Instance Method Details

#create(instance) ⇒ Object

-


68
69
70
# File 'lib/lib/adapters/rails.rb', line 68

def create(instance)
  Query.new(default_query(instance), @options).create
end

#load(query) ⇒ Object

-


22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/lib/adapters/rails.rb', line 22

def load(query)
  @rdf.associations.values.select do |assoc|
    assoc.belongs_to?
  end.map do |assoc|
    assoc.name
  end.reject do |name|
    @options[:skip].include?(name)
  end.each do |name|
    query.include!(name)
  end
  Query.new(query, @options).find
end

#reload(instance) ⇒ Object

-


53
54
55
56
# File 'lib/lib/adapters/rails.rb', line 53

def reload(instance)
  query = RDFMapper::Scope::Query.new(instance.class, :conditions => { :id => instance.id })
  Query.new(query, @options).find.first
end

#save(instance) ⇒ Object

-


38
39
40
41
42
43
44
45
46
47
48
# File 'lib/lib/adapters/rails.rb', line 38

def save(instance)
  if instance[:rails_id].nil?
    obj = instance.class.find(instance.id.to_s).from(:rails)
    instance[:rails_id] = obj[:rails_id] unless obj.nil?
  end
  if instance[:rails_id].nil?
    create(instance)
  else
    update(instance)
  end
end

#update(instance) ⇒ Object

-


61
62
63
# File 'lib/lib/adapters/rails.rb', line 61

def update(instance)
  Query.new(default_query(instance), @options).update
end