Class: Element

Inherits:
ApplicationRecord show all
Defined in:
app/models/element.rb

Constant Summary collapse

FIELD_TYPES =
%w[
  string
  text
  integer
  boolean
  date
  datetime
].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.at(field) ⇒ Object

Find by solr_field shortcut



36
37
38
# File 'app/models/element.rb', line 36

def self.at(field)
  Element.find_by_solr_field(field)
end

.label_nocase(label) ⇒ Object



67
68
69
# File 'app/models/element.rb', line 67

def self.label_nocase(label)
  Element.where("LOWER(label) = ?", label.to_s.tr("_", " ").downcase).first
end

.listObject

Element Field List (Labels as Symbols)



41
42
43
# File 'app/models/element.rb', line 41

def self.list
  @list ||= Element.all.map { |e| e.label.parameterize(separator: "_").to_sym }
end

.method_missing(m, *args, &block) ⇒ Object

Class Level - Method Missing ex. :title => “Title”



73
74
75
76
77
78
79
# File 'app/models/element.rb', line 73

def self.method_missing(m, *args, &block)
  if list.include?(m)
    label_nocase(m)
  else
    super
  end
end

.respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


90
91
92
# File 'app/models/element.rb', line 90

def self.respond_to_missing?(method_name, include_private = false)
  label_nocase(method_name).present? || super
end

.sort_elements(id_array) ⇒ Object



81
82
83
84
85
86
87
88
# File 'app/models/element.rb', line 81

def self.sort_elements(id_array)
  transaction do
    logger.debug { id_array.inspect }
    id_array.each_with_index do |elm_id, i|
      Element.update(elm_id, position: i)
    end
  end
end

Instance Method Details

#constantized_labelObject



45
46
47
# File 'app/models/element.rb', line 45

def constantized_label
  label.parameterize(separator: "_").upcase
end

#export_valueObject

Export value



59
60
61
62
63
64
65
# File 'app/models/element.rb', line 59

def export_value
  if export_transformation_method.present?
    export_transformation_method
  else
    solr_field
  end
end

#index_valueObject

Index value



50
51
52
53
54
55
56
# File 'app/models/element.rb', line 50

def index_value
  if index_transformation_method.present?
    index_transformation_method
  else
    solr_field
  end
end