Module: ActiveRecordExtension::ClassMethods

Defined in:
lib/active_record_extension.rb

Overview

add your static(class) methods here

Instance Method Summary collapse

Instance Method Details

#name_or_title_or_code_or_barcode_starts_with(letter) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/active_record_extension.rb', line 21

def name_or_title_or_code_or_barcode_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



38
39
40
# File 'lib/active_record_extension.rb', line 38

def starts_with_a
  name_or_title_or_code_or_barcode_starts_with :a
end

#starts_with_bObject



42
43
44
# File 'lib/active_record_extension.rb', line 42

def starts_with_b
  name_or_title_or_code_or_barcode_starts_with :b
end

#starts_with_cObject



46
47
48
# File 'lib/active_record_extension.rb', line 46

def starts_with_c
  name_or_title_or_code_or_barcode_starts_with :c
end

#starts_with_dObject



50
51
52
# File 'lib/active_record_extension.rb', line 50

def starts_with_d
  name_or_title_or_code_or_barcode_starts_with :d
end

#starts_with_eObject



54
55
56
# File 'lib/active_record_extension.rb', line 54

def starts_with_e
  name_or_title_or_code_or_barcode_starts_with :e
end

#starts_with_fObject



58
59
60
# File 'lib/active_record_extension.rb', line 58

def starts_with_f
  name_or_title_or_code_or_barcode_starts_with :f
end

#starts_with_gObject



62
63
64
# File 'lib/active_record_extension.rb', line 62

def starts_with_g
  name_or_title_or_code_or_barcode_starts_with :g
end

#starts_with_hObject



66
67
68
# File 'lib/active_record_extension.rb', line 66

def starts_with_h
  name_or_title_or_code_or_barcode_starts_with :h
end

#starts_with_iObject



70
71
72
# File 'lib/active_record_extension.rb', line 70

def starts_with_i
  name_or_title_or_code_or_barcode_starts_with :i
end

#starts_with_jObject



74
75
76
# File 'lib/active_record_extension.rb', line 74

def starts_with_j
  name_or_title_or_code_or_barcode_starts_with :j
end

#starts_with_kObject



78
79
80
# File 'lib/active_record_extension.rb', line 78

def starts_with_k
  name_or_title_or_code_or_barcode_starts_with :k
end

#starts_with_lObject



82
83
84
# File 'lib/active_record_extension.rb', line 82

def starts_with_l
  name_or_title_or_code_or_barcode_starts_with :l
end

#starts_with_mObject



86
87
88
# File 'lib/active_record_extension.rb', line 86

def starts_with_m
  name_or_title_or_code_or_barcode_starts_with :m
end

#starts_with_nObject



90
91
92
# File 'lib/active_record_extension.rb', line 90

def starts_with_n
  name_or_title_or_code_or_barcode_starts_with :n
end

#starts_with_oObject



94
95
96
# File 'lib/active_record_extension.rb', line 94

def starts_with_o
  name_or_title_or_code_or_barcode_starts_with :o
end

#starts_with_pObject



98
99
100
# File 'lib/active_record_extension.rb', line 98

def starts_with_p
  name_or_title_or_code_or_barcode_starts_with :p
end

#starts_with_qObject



102
103
104
# File 'lib/active_record_extension.rb', line 102

def starts_with_q
  name_or_title_or_code_or_barcode_starts_with :q
end

#starts_with_rObject



106
107
108
# File 'lib/active_record_extension.rb', line 106

def starts_with_r
  name_or_title_or_code_or_barcode_starts_with :r
end

#starts_with_sObject



110
111
112
# File 'lib/active_record_extension.rb', line 110

def starts_with_s
  name_or_title_or_code_or_barcode_starts_with :s
end

#starts_with_tObject



114
115
116
# File 'lib/active_record_extension.rb', line 114

def starts_with_t
  name_or_title_or_code_or_barcode_starts_with :t
end

#starts_with_uObject



118
119
120
# File 'lib/active_record_extension.rb', line 118

def starts_with_u
  name_or_title_or_code_or_barcode_starts_with :u
end

#starts_with_vObject



122
123
124
# File 'lib/active_record_extension.rb', line 122

def starts_with_v
  name_or_title_or_code_or_barcode_starts_with :v
end

#starts_with_wObject



126
127
128
# File 'lib/active_record_extension.rb', line 126

def starts_with_w
  name_or_title_or_code_or_barcode_starts_with :w
end

#starts_with_xObject



130
131
132
# File 'lib/active_record_extension.rb', line 130

def starts_with_x
  name_or_title_or_code_or_barcode_starts_with :x
end

#starts_with_yObject



134
135
136
# File 'lib/active_record_extension.rb', line 134

def starts_with_y
  name_or_title_or_code_or_barcode_starts_with :y
end

#starts_with_zObject



138
139
140
# File 'lib/active_record_extension.rb', line 138

def starts_with_z
  name_or_title_or_code_or_barcode_starts_with :z
end

#top_tenObject

E.g: Order.top_ten



17
18
19
# File 'lib/active_record_extension.rb', line 17

def top_ten
  limit(10)
end