Class: RailsCodebook::Model::Base

Inherits:
RedisOrm::Base
  • Object
show all
Defined in:
lib/rails_codebook/model/base.rb

Direct Known Subclasses

Codebook

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.search(column_name = '', value = '', strict = false, init_cb = RailsCodebook::Codebook.all) ⇒ Object

universal regexp_search



11
12
13
14
15
16
17
18
19
20
# File 'lib/rails_codebook/model/base.rb', line 11

def self.search column_name='', value='', strict=false, init_cb=RailsCodebook::Codebook.all
  # binding.pry
  if column_name != ''
    strict ? \
      init_cb.select{|j| ((column_name == 'name') ? I18n.t(j.send(column_name)) : j.send(column_name)) =~ /^#{value}$/i} : \
      init_cb.select{|j| ((column_name == 'name') ? I18n.t(j.send(column_name)) : j.send(column_name)) =~ /(#{value})/i}
  else
    init_cb
  end
end

Instance Method Details

#cb_serialize(format = :codebook_format) ⇒ Object



22
23
24
25
# File 'lib/rails_codebook/model/base.rb', line 22

def cb_serialize format=:codebook_format
  format = :codebook_format if format.nil? 
  self.send(format)
end

#codebook_formatObject



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rails_codebook/model/base.rb', line 27

def codebook_format
  {
    id: self.id, 
    value: self.value, 
    name: I18n.t(self.name), 
    cb_name: self.cb_name, 
    created_at: self.created_at, 
    updated_at: self.updated_at, 
    sequence: self.sequence,
    deleted: self.deleted
  }
end

#to_partial_pathObject



53
54
55
# File 'lib/rails_codebook/model/base.rb', line 53

def to_partial_path
  "codebooks/codebook"
end