Class: PUNK::Model

Inherits:
Object
  • Object
show all
Includes:
AASM, Loggable
Defined in:
lib/punk/framework/model.rb

Direct Known Subclasses

Group, Identity, Session, Tenant, User

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



35
36
37
38
# File 'lib/punk/framework/model.rb', line 35

def self.sample(count=1)
  query = sample_dataset(count)
  count == 1 ? query.first : query.all
end

.sample_dataset(count = 1) ⇒ Object



31
32
33
# File 'lib/punk/framework/model.rb', line 31

def self.sample_dataset(count=1)
  order(Sequel.lit('random()')).limit(count)
end

.symbolize(*names) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/punk/framework/model.rb', line 40

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

#inspectObject



27
28
29
# File 'lib/punk/framework/model.rb', line 27

def inspect
  id.present? ? "#{id}|#{self}" : to_s
end

#validateObject



25
# File 'lib/punk/framework/model.rb', line 25

def validate; end