Class: PUNK::Model
- Inherits:
-
Object
show all
- Includes:
- AASM, Loggable
- Defined in:
- lib/punk/framework/model.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Loggable
#exception, #logger, #profile_debug, #profile_info, #profile_trace
Class Method Details
.sample(count = 1) ⇒ Object
36
37
38
39
|
# File 'lib/punk/framework/model.rb', line 36
def self.sample(count = 1)
query = sample_dataset(count)
count == 1 ? query.first : query.all
end
|
.sample_dataset(count = 1) ⇒ Object
32
33
34
|
# File 'lib/punk/framework/model.rb', line 32
def self.sample_dataset(count = 1)
order(Sequel.lit("random()")).limit(count)
end
|
.symbolize(*names) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/punk/framework/model.rb', line 41
def self.symbolize(*names)
names.each do |name|
chain =
Module.new do
define_method(name) do |*args|
super(*args)&.to_sym
end
end
prepend chain
end
end
|
Instance Method Details
#inspect ⇒ Object
28
29
30
|
# File 'lib/punk/framework/model.rb', line 28
def inspect
id.present? ? "#{id}|#{self}" : to_s
end
|
#validate ⇒ Object
25
26
|
# File 'lib/punk/framework/model.rb', line 25
def validate
end
|