Module: RansackAbbreviator::Configuration

Included in:
RansackAbbreviator
Defined in:
lib/ransack_abbreviator/configuration.rb

Instance Method Summary collapse

Instance Method Details

#add_assoc_abbreviation(assoc, abbr) ⇒ Object



39
40
41
# File 'lib/ransack_abbreviator/configuration.rb', line 39

def add_assoc_abbreviation(assoc, abbr)
  self.assoc_abbreviations[assoc.to_s] = abbr.to_s
end

#add_column_abbreviation(column, abbr) ⇒ Object



35
36
37
# File 'lib/ransack_abbreviator/configuration.rb', line 35

def add_column_abbreviation(column, abbr)
  self.column_abbreviations[column.to_s] = abbr.to_s
end

#assoc_abbreviation_for(assoc) ⇒ Object



53
54
55
56
# File 'lib/ransack_abbreviator/configuration.rb', line 53

def assoc_abbreviation_for(assoc)
  assoc = assoc.to_s
  self.assoc_abbreviations.has_key?(assoc) ? self.assoc_abbreviations[assoc] : assoc
end

#assoc_abbreviations=(abbreviations) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/ransack_abbreviator/configuration.rb', line 24

def assoc_abbreviations=(abbreviations)
  if abbreviations
    raise ArgumentError, "abbreviates must be a Hash" unless abbreviations.is_a?(Hash)
    if !(abbreviations.values & RansackAbbreviator::Constants::RESERVED_KEYWORDS).blank?
      raise ArgumentError, "You used a reserved keyword as an association abbreviation. Reserverd keywords: #{RansackAbbreviator::Constants::RESERVED_KEYWORDS.join(", ")}"
    end
    
    @@assoc_abbreviations = abbreviations
  end
end

#assoc_name_for(assoc_abbr) ⇒ Object



58
59
60
61
# File 'lib/ransack_abbreviator/configuration.rb', line 58

def assoc_name_for(assoc_abbr)
  assoc_abbr = assoc_abbr.to_s
  self.assoc_abbreviations.has_value?(assoc_abbr) ? self.assoc_abbreviations.key(assoc_abbr) : assoc_abbr
end

#column_abbreviation_for(column) ⇒ Object



43
44
45
46
# File 'lib/ransack_abbreviator/configuration.rb', line 43

def column_abbreviation_for(column)
  column = column.to_s
  self.column_abbreviations.has_key?(column) ? self.column_abbreviations[column] : column
end

#column_abbreviations=(abbreviations) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/ransack_abbreviator/configuration.rb', line 13

def column_abbreviations=(abbreviations)
  if abbreviations
    raise ArgumentError, "abbreviates must be a Hash" unless abbreviations.is_a?(Hash)
    if !(abbreviations.values & RansackAbbreviator::Constants::RESERVED_KEYWORDS).blank?
      raise ArgumentError, "You used a reserved keyword as a column abbreviation. Reserverd keywords: #{RansackAbbreviator::Constants::RESERVED_KEYWORDS.join(", ")}"
    end
    
    @@column_abbreviations = abbreviations
  end
end

#column_name_for(column_abbr) ⇒ Object



48
49
50
51
# File 'lib/ransack_abbreviator/configuration.rb', line 48

def column_name_for(column_abbr)
  column_abbr = column_abbr.to_s
  self.column_abbreviations.has_value?(column_abbr) ? self.column_abbreviations.key(column_abbr) : column_abbr
end

#config_dirObject



63
64
65
# File 'lib/ransack_abbreviator/configuration.rb', line 63

def config_dir
  Pathname.new("config")
end

#configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



9
10
11
# File 'lib/ransack_abbreviator/configuration.rb', line 9

def configure
  yield self
end