Module: ActiveRecordExtensions::ClassMethods

Defined in:
lib/patches/active_record_extensions.rb

Overview

add your static(class) methods here

Instance Method Summary collapse

Instance Method Details

#identifier_starts_with(letter) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/patches/active_record_extensions.rb', line 11

def identifier_starts_with letter
  # Se ha name o code o barcode, uso uno di questi:
  column = if self.column_names.include? "name"
    :name
  elsif self.column_names.include? "title"
    :title
  elsif self.column_names.include? "code"
    :code
  elsif self.column_names.include? "barcode"
    :barcode
  end
  # Ecco la ricerca dedicata a Postgres, la facciamo multiplatform? Fatto
  query = "#{letter}%"
  match = arel_table[column].matches(query)
  where(match)
end

#starts_with_aObject



28
29
30
# File 'lib/patches/active_record_extensions.rb', line 28

def starts_with_a
  identifier_starts_with :a
end

#starts_with_bObject



32
33
34
# File 'lib/patches/active_record_extensions.rb', line 32

def starts_with_b
  identifier_starts_with :b
end

#starts_with_cObject



36
37
38
# File 'lib/patches/active_record_extensions.rb', line 36

def starts_with_c
  identifier_starts_with :c
end

#starts_with_dObject



40
41
42
# File 'lib/patches/active_record_extensions.rb', line 40

def starts_with_d
  identifier_starts_with :d
end

#starts_with_eObject



44
45
46
# File 'lib/patches/active_record_extensions.rb', line 44

def starts_with_e
  identifier_starts_with :e
end

#starts_with_fObject



48
49
50
# File 'lib/patches/active_record_extensions.rb', line 48

def starts_with_f
  identifier_starts_with :f
end

#starts_with_gObject



52
53
54
# File 'lib/patches/active_record_extensions.rb', line 52

def starts_with_g
  identifier_starts_with :g
end

#starts_with_hObject



56
57
58
# File 'lib/patches/active_record_extensions.rb', line 56

def starts_with_h
  identifier_starts_with :h
end

#starts_with_iObject



60
61
62
# File 'lib/patches/active_record_extensions.rb', line 60

def starts_with_i
  identifier_starts_with :i
end

#starts_with_jObject



64
65
66
# File 'lib/patches/active_record_extensions.rb', line 64

def starts_with_j
  identifier_starts_with :j
end

#starts_with_kObject



68
69
70
# File 'lib/patches/active_record_extensions.rb', line 68

def starts_with_k
  identifier_starts_with :k
end

#starts_with_lObject



72
73
74
# File 'lib/patches/active_record_extensions.rb', line 72

def starts_with_l
  identifier_starts_with :l
end

#starts_with_mObject



76
77
78
# File 'lib/patches/active_record_extensions.rb', line 76

def starts_with_m
  identifier_starts_with :m
end

#starts_with_nObject



80
81
82
# File 'lib/patches/active_record_extensions.rb', line 80

def starts_with_n
  identifier_starts_with :n
end

#starts_with_oObject



84
85
86
# File 'lib/patches/active_record_extensions.rb', line 84

def starts_with_o
  identifier_starts_with :o
end

#starts_with_pObject



88
89
90
# File 'lib/patches/active_record_extensions.rb', line 88

def starts_with_p
  identifier_starts_with :p
end

#starts_with_qObject



92
93
94
# File 'lib/patches/active_record_extensions.rb', line 92

def starts_with_q
  identifier_starts_with :q
end

#starts_with_rObject



96
97
98
# File 'lib/patches/active_record_extensions.rb', line 96

def starts_with_r
  identifier_starts_with :r
end

#starts_with_sObject



100
101
102
# File 'lib/patches/active_record_extensions.rb', line 100

def starts_with_s
  identifier_starts_with :s
end

#starts_with_tObject



104
105
106
# File 'lib/patches/active_record_extensions.rb', line 104

def starts_with_t
  identifier_starts_with :t
end

#starts_with_uObject



108
109
110
# File 'lib/patches/active_record_extensions.rb', line 108

def starts_with_u
  identifier_starts_with :u
end

#starts_with_vObject



112
113
114
# File 'lib/patches/active_record_extensions.rb', line 112

def starts_with_v
  identifier_starts_with :v
end

#starts_with_wObject



116
117
118
# File 'lib/patches/active_record_extensions.rb', line 116

def starts_with_w
  identifier_starts_with :w
end

#starts_with_xObject



120
121
122
# File 'lib/patches/active_record_extensions.rb', line 120

def starts_with_x
  identifier_starts_with :x
end

#starts_with_yObject



124
125
126
# File 'lib/patches/active_record_extensions.rb', line 124

def starts_with_y
  identifier_starts_with :y
end

#starts_with_zObject



128
129
130
# File 'lib/patches/active_record_extensions.rb', line 128

def starts_with_z
  identifier_starts_with :z
end

#top_tenObject

E.g: Order.top_ten



7
8
9
# File 'lib/patches/active_record_extensions.rb', line 7

def top_ten
  limit(10)
end