Class: Dock::Sequel
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#all(options = {}) ⇒ Object
Checked.
- #associations ⇒ Object
- #belongs_to ⇒ Object
-
#column_names ⇒ Object
Checked.
-
#count(options = {}) ⇒ Object
Checked.
- #create ⇒ Object
- #cyclic? ⇒ Boolean
-
#destroy(object) ⇒ Object
Checked.
- #embedded? ⇒ Boolean
- #encoding ⇒ Object
-
#find(id) ⇒ Object
Checked.
-
#find!(id) ⇒ Object
Checked.
-
#first(options = {}) ⇒ Object
Checked.
- #has_many ⇒ Object
-
#id ⇒ Object
Checked.
-
#model_name ⇒ Object
Checked.
- #properties ⇒ Object
- #scoped? ⇒ Boolean
-
#supports_joins? ⇒ Boolean
Checked.
- #update(search_key, find_by, update_key, by_value) ⇒ Object
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( = {}) conditions, order = extract_conditions!() model.filter(conditions_to_hash(conditions)).order(*order_clause(order)).all end |
#associations ⇒ Object
55 56 57 |
# File 'lib/dock/adapters/sequel.rb', line 55 def associations() end |
#belongs_to ⇒ Object
73 74 75 |
# File 'lib/dock/adapters/sequel.rb', line 73 def belongs_to() end |
#column_names ⇒ Object
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( = {}) all().count end |
#create ⇒ Object
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
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
82 83 84 |
# File 'lib/dock/adapters/sequel.rb', line 82 def false end |
#encoding ⇒ Object
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( = {}) conditions, order = extract_conditions!() model.filter(conditions_to_hash(conditions)).order(*order_clause(order)).first end |
#has_many ⇒ Object
76 77 78 |
# File 'lib/dock/adapters/sequel.rb', line 76 def has_many() end |
#id ⇒ Object
Checked
44 45 46 |
# File 'lib/dock/adapters/sequel.rb', line 44 def id 'primary_key' end |
#model_name ⇒ Object
Checked
59 60 61 |
# File 'lib/dock/adapters/sequel.rb', line 59 def model_name model.class.name end |
#properties ⇒ Object
92 93 94 |
# File 'lib/dock/adapters/sequel.rb', line 92 def properties() end |
#scoped? ⇒ Boolean
79 80 81 |
# File 'lib/dock/adapters/sequel.rb', line 79 def scoped? false end |
#supports_joins? ⇒ Boolean
Checked
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 |