Class: Dock::Sequel

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

Instance Attribute Summary

Attributes inherited from Base

#model

Instance Method Summary collapse

Methods inherited from Base

#embedded, inherited, #initialize, #scoped

Constructor Details

This class inherits a constructor from Dock::Base

Instance Method Details

#all(options = {}) ⇒ Object

Checked



34
35
36
37
# File 'lib/dock/adapters/sequel.rb', line 34

def all(options = {})
  conditions, order = extract_conditions!(options)
  model.filter(conditions_to_hash(conditions)).order(*order_clause(order)).all
end

#associationsObject



55
56
57
# File 'lib/dock/adapters/sequel.rb', line 55

def associations()

end

#belongs_toObject



73
74
75
# File 'lib/dock/adapters/sequel.rb', line 73

def belongs_to()

end

#column_namesObject

Checked



63
64
65
# File 'lib/dock/adapters/sequel.rb', line 63

def column_names
  model.columns
end

#count(options = {}) ⇒ Object

Checked



67
68
69
# File 'lib/dock/adapters/sequel.rb', line 67

def count(options = {})
  all(options).count
end

#createObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/dock/adapters/sequel.rb', line 5

def create()
  associated_objects = []
  attrs = {}

  model.db.transaction do
    attributes.each do |col, value|
      if model.associations.include?(col)
        Array(value).each{|v| associated_objects << [association_method(col), v]}
      else
        attrs.merge!(col => value) # pass it on
      end
    end

    obj = model.create(attrs) # create main obj
    associated_objects.each do |m,o|
      obj.send(m, o)
    end
    obj.save
  end # transaction
end

#cyclic?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/dock/adapters/sequel.rb', line 85

def cyclic?
  true
end

#destroy(object) ⇒ Object

Checked



52
53
54
# File 'lib/dock/adapters/sequel.rb', line 52

def destroy(object)
  object.destroy && true if valid_object?(object)
end

#embedded?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/dock/adapters/sequel.rb', line 82

def embedded?
  false
end

#encodingObject



70
71
72
# File 'lib/dock/adapters/sequel.rb', line 70

def encoding
  'UTF-8'
end

#find(id) ⇒ Object

Checked



26
27
28
# File 'lib/dock/adapters/sequel.rb', line 26

def find(id)
  model.find(wrap_key(model.primary_key => id))
end

#find!(id) ⇒ Object

Checked



30
31
32
# File 'lib/dock/adapters/sequel.rb', line 30

def find!(id)
  model[wrap_key(id)] || raise(Error, "#{model.name} not found with #{model.primary_key} of #{wrap_key(id)}")
end

#first(options = {}) ⇒ Object

Checked



39
40
41
42
# File 'lib/dock/adapters/sequel.rb', line 39

def first(options = {})
  conditions, order = extract_conditions!(options)
  model.filter(conditions_to_hash(conditions)).order(*order_clause(order)).first
end

#has_manyObject



76
77
78
# File 'lib/dock/adapters/sequel.rb', line 76

def has_many()

end

#idObject

Checked



44
45
46
# File 'lib/dock/adapters/sequel.rb', line 44

def id
  'primary_key'
end

#model_nameObject

Checked



59
60
61
# File 'lib/dock/adapters/sequel.rb', line 59

def model_name
  model.class.name
end

#propertiesObject



92
93
94
# File 'lib/dock/adapters/sequel.rb', line 92

def properties()

end

#scoped?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/dock/adapters/sequel.rb', line 79

def scoped?
  false
end

#supports_joins?Boolean

Checked

Returns:

  • (Boolean)


89
90
91
# File 'lib/dock/adapters/sequel.rb', line 89

def supports_joins?
  true
end

#update(search_key, find_by, update_key, by_value) ⇒ Object



47
48
49
50
# File 'lib/dock/adapters/sequel.rb', line 47

def update(search_key, find_by, update_key, by_value)
  entry = model.where(search_key, find_by)
  entry.update(update_key by_value)
end