Class: Element

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

Constant Summary collapse

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.at(field) ⇒ Object

Find by solr_field shortcut



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

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

.label_nocase(label) ⇒ Object



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

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

.listObject

Element Field List (Labels as Symbols)



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

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”



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

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)


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

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

.sort_elements(id_array) ⇒ Object



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

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



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

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

#export_valueObject

Export value



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

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

#index_valueObject

Index value



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

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