Class DataMapper::Context
In: lib/data_mapper/context.rb
lib/data_mapper/context.rb
Parent: Object

Methods

Classes and Modules

Class DataMapper::Context::MaterializationError

Attributes

adapter  [R] 
adapter  [R] 

Public Class methods

[Source]

    # File lib/data_mapper/context.rb, line 12
12:     def initialize(adapter)
13:       @adapter = adapter
14:     end

[Source]

    # File lib/data_mapper/context.rb, line 12
12:     def initialize(adapter)
13:       @adapter = adapter
14:     end

Public Instance methods

[Source]

    # File lib/data_mapper/context.rb, line 51
51:     def all(klass, options = {})
52:       @adapter.load(self, klass, options)
53:     end

[Source]

    # File lib/data_mapper/context.rb, line 51
51:     def all(klass, options = {})
52:       @adapter.load(self, klass, options)
53:     end

[Source]

    # File lib/data_mapper/context.rb, line 87
87:     def column_exists_for_table?(klass, column_name)
88:       @adapter.column_exists_for_table?(klass, column_name)
89:     end

[Source]

    # File lib/data_mapper/context.rb, line 87
87:     def column_exists_for_table?(klass, column_name)
88:       @adapter.column_exists_for_table?(klass, column_name)
89:     end

[Source]

    # File lib/data_mapper/context.rb, line 55
55:     def count(klass, *args)
56:       table(klass).count(*args)
57:     end

[Source]

    # File lib/data_mapper/context.rb, line 55
55:     def count(klass, *args)
56:       table(klass).count(*args)
57:     end

[Source]

    # File lib/data_mapper/context.rb, line 75
75:     def create_table(klass)
76:       table(klass).create!
77:     end

[Source]

    # File lib/data_mapper/context.rb, line 75
75:     def create_table(klass)
76:       table(klass).create!
77:     end

[Source]

    # File lib/data_mapper/context.rb, line 67
67:     def delete_all(klass)
68:       @adapter.delete(self, klass)
69:     end

[Source]

    # File lib/data_mapper/context.rb, line 67
67:     def delete_all(klass)
68:       @adapter.delete(self, klass)
69:     end

[Source]

    # File lib/data_mapper/context.rb, line 63
63:     def destroy(instance)
64:       @adapter.delete(self, instance)
65:     end

[Source]

    # File lib/data_mapper/context.rb, line 63
63:     def destroy(instance)
64:       @adapter.delete(self, instance)
65:     end

[Source]

    # File lib/data_mapper/context.rb, line 79
79:     def drop_table(klass)
80:       table(klass).drop!
81:     end

[Source]

    # File lib/data_mapper/context.rb, line 79
79:     def drop_table(klass)
80:       table(klass).drop!
81:     end

[Source]

    # File lib/data_mapper/context.rb, line 91
91:     def execute(*args)
92:       @adapter.execute(*args)
93:     end

[Source]

    # File lib/data_mapper/context.rb, line 91
91:     def execute(*args)
92:       @adapter.execute(*args)
93:     end

[Source]

    # File lib/data_mapper/context.rb, line 20
20:     def first(klass, *args)
21:       id = nil
22:       options = nil
23:       table = self.table(klass)
24:       key = table.key
25:       
26:       if args.empty? # No id, no options
27:         options = { :limit => 1 }
28:       elsif args.size == 2 && args.last.kind_of?(Hash) # id AND options
29:         options = args.last.merge(key => args.first)
30:       elsif args.size == 1 # id OR options
31:         if args.first.kind_of?(Hash)
32:           options = args.first.merge(:limit => 1) # no id, add limit
33:         else
34:           options = { key => args.first } # no options, set id
35:         end
36:       else
37:         raise ArgumentError.new('Context#first takes a class, and optional type_or_id and/or options arguments')
38:       end
39:       
40:       # Account for undesired behaviour in MySQL that returns the
41:       # last inserted row when the WHERE clause contains a "#{primary_key} IS NULL".
42:       return nil if options.has_key?(key.name) && options[key.name] == nil
43:       
44:       @adapter.load(self, klass, options).first
45:     end

[Source]

    # File lib/data_mapper/context.rb, line 20
20:     def first(klass, *args)
21:       id = nil
22:       options = nil
23:       table = self.table(klass)
24:       key = table.key
25:       
26:       if args.empty? # No id, no options
27:         options = { :limit => 1 }
28:       elsif args.size == 2 && args.last.kind_of?(Hash) # id AND options
29:         options = args.last.merge(key => args.first)
30:       elsif args.size == 1 # id OR options
31:         if args.first.kind_of?(Hash)
32:           options = args.first.merge(:limit => 1) # no id, add limit
33:         else
34:           options = { key => args.first } # no options, set id
35:         end
36:       else
37:         raise ArgumentError.new('Context#first takes a class, and optional type_or_id and/or options arguments')
38:       end
39:       
40:       # Account for undesired behaviour in MySQL that returns the
41:       # last inserted row when the WHERE clause contains a "#{primary_key} IS NULL".
42:       return nil if options.has_key?(key.name) && options[key.name] == nil
43:       
44:       @adapter.load(self, klass, options).first
45:     end

[Source]

    # File lib/data_mapper/context.rb, line 47
47:     def get(klass, keys)
48:       @adapter.get(self, klass, keys)
49:     end

[Source]

    # File lib/data_mapper/context.rb, line 47
47:     def get(klass, keys)
48:       @adapter.get(self, klass, keys)
49:     end

[Source]

    # File lib/data_mapper/context.rb, line 16
16:     def identity_map
17:       @identity_map || ( @identity_map = IdentityMap.new )
18:     end

[Source]

    # File lib/data_mapper/context.rb, line 16
16:     def identity_map
17:       @identity_map || ( @identity_map = IdentityMap.new )
18:     end

[Source]

     # File lib/data_mapper/context.rb, line 107
107:     def logger
108:       @logger || @logger = @adapter.logger
109:     end

[Source]

     # File lib/data_mapper/context.rb, line 107
107:     def logger
108:       @logger || @logger = @adapter.logger
109:     end

[Source]

    # File lib/data_mapper/context.rb, line 95
95:     def query(*args)      
96:       @adapter.query(*args)
97:     end

[Source]

    # File lib/data_mapper/context.rb, line 95
95:     def query(*args)      
96:       @adapter.query(*args)
97:     end

[Source]

    # File lib/data_mapper/context.rb, line 59
59:     def save(instance)
60:       @adapter.save(self, instance)
61:     end

[Source]

    # File lib/data_mapper/context.rb, line 59
59:     def save(instance)
60:       @adapter.save(self, instance)
61:     end

[Source]

     # File lib/data_mapper/context.rb, line 99
 99:     def schema
100:       @adapter.schema
101:     end

[Source]

     # File lib/data_mapper/context.rb, line 99
 99:     def schema
100:       @adapter.schema
101:     end

[Source]

     # File lib/data_mapper/context.rb, line 103
103:     def table(klass)
104:       @adapter.table(klass)
105:     end

[Source]

     # File lib/data_mapper/context.rb, line 103
103:     def table(klass)
104:       @adapter.table(klass)
105:     end

[Source]

    # File lib/data_mapper/context.rb, line 83
83:     def table_exists?(klass)
84:       table(klass).exists?
85:     end

[Source]

    # File lib/data_mapper/context.rb, line 83
83:     def table_exists?(klass)
84:       table(klass).exists?
85:     end

[Source]

    # File lib/data_mapper/context.rb, line 71
71:     def truncate(klass)
72:       table(klass).truncate!
73:     end

[Source]

    # File lib/data_mapper/context.rb, line 71
71:     def truncate(klass)
72:       table(klass).truncate!
73:     end

[Validate]