Module: MotionDataWrapper::Model::FinderMethods::ClassMethods
- Defined in:
- lib/motion_data_wrapper/model/finder_methods.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
# File 'lib/motion_data_wrapper/model/finder_methods.rb', line 98
def method_missing(method, *args, &block)
if method.start_with?("find_by_")
attribute = method.gsub("find_by_", "").gsub("!", "")
chain = relation.where("#{attribute} = ?", *args)
if method.end_with?("!")
chain.first!
else
chain.first
end
elsif method.start_with?("find_all_by_")
attribute = method.gsub("find_all_by_", "")
relation.where("#{attribute} = ?", *args).to_a
else
super
end
end
|
Instance Method Details
#except(query_part) ⇒ Object
20
21
22
|
# File 'lib/motion_data_wrapper/model/finder_methods.rb', line 20
def except(query_part)
relation.except(query_part)
end
|
#find(object_id) ⇒ Object
32
33
34
|
# File 'lib/motion_data_wrapper/model/finder_methods.rb', line 32
def find(object_id)
find_by_id!(object_id)
end
|
#first ⇒ Object
25
26
27
|
# File 'lib/motion_data_wrapper/model/finder_methods.rb', line 25
def first
relation.first
end
|
#last ⇒ Object
37
38
39
|
# File 'lib/motion_data_wrapper/model/finder_methods.rb', line 37
def last
relation.last
end
|
#limit(l) ⇒ Object
43
44
45
|
# File 'lib/motion_data_wrapper/model/finder_methods.rb', line 43
def limit(l)
relation.limit(l)
end
|
#offset(o) ⇒ Object
49
50
51
|
# File 'lib/motion_data_wrapper/model/finder_methods.rb', line 49
def offset(o)
relation.offset(o)
end
|
#order(*args) ⇒ Object
56
57
58
|
# File 'lib/motion_data_wrapper/model/finder_methods.rb', line 56
def order(*args)
relation.order(*args)
end
|
#pluck(column) ⇒ Object
62
63
64
|
# File 'lib/motion_data_wrapper/model/finder_methods.rb', line 62
def pluck(column)
relation.pluck(column)
end
|
#reorder(*args) ⇒ Object
69
70
71
|
# File 'lib/motion_data_wrapper/model/finder_methods.rb', line 69
def reorder(*args)
relation.except(:order).order(*args)
end
|
#respond_to?(method) ⇒ Boolean
73
74
75
76
77
78
79
|
# File 'lib/motion_data_wrapper/model/finder_methods.rb', line 73
def respond_to?(method)
if method.start_with?("find_by_") || method.start_with?("find_all_by_")
true
else
super
end
end
|
#where(*args) ⇒ Object
Usage:
where("title contains[cd] ?", "title")
86
87
88
|
# File 'lib/motion_data_wrapper/model/finder_methods.rb', line 86
def where(*args)
relation.where(*args)
end
|
#with_context(ctx) ⇒ Object
92
93
94
|
# File 'lib/motion_data_wrapper/model/finder_methods.rb', line 92
def with_context(ctx)
relation.with_context(ctx)
end
|