Module: CustomAttributes::ActsAsCustomizable::ClassMethods
- Defined in:
- lib/custom_attributes/acts_as/acts_as_customizable.rb
Instance Method Summary collapse
- #acts_as_customizable(options = {}) ⇒ Object
- #available_custom_fields ⇒ Object
- #default_fields ⇒ Object
-
#index_custom_values(context) ⇒ Object
Helper function to index custom values Use this in mapping context and pass ‘self` as parameter.
Instance Method Details
#acts_as_customizable(options = {}) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/custom_attributes/acts_as/acts_as_customizable.rb', line 9 def acts_as_customizable( = {}) cattr_accessor :customizable_options self. = has_many :custom_values, -> { includes(:custom_field).order("#{CustomField.table_name}.position") }, as: :customizable, inverse_of: :customizable, dependent: :delete_all, validate: false include CustomAttributes::ActsAsCustomizable::InstanceMethods validate :validate_custom_field_values after_save :save_custom_field_values end |
#available_custom_fields ⇒ Object
37 38 39 |
# File 'lib/custom_attributes/acts_as/acts_as_customizable.rb', line 37 def available_custom_fields CustomField.where("model_type = '#{self.name}CustomField'").sorted.to_a end |
#default_fields ⇒ Object
41 42 43 |
# File 'lib/custom_attributes/acts_as/acts_as_customizable.rb', line 41 def default_fields [] end |
#index_custom_values(context) ⇒ Object
Helper function to index custom values Use this in mapping context and pass ‘self` as parameter
27 28 29 30 31 32 33 34 35 |
# File 'lib/custom_attributes/acts_as/acts_as_customizable.rb', line 27 def index_custom_values(context) return unless context.class.name == 'Elasticsearch::Model::Indexing::Mappings' context.indexes :visible_in_search, type: 'boolean' context.indexes :custom_field_values, type: 'nested' do context.indexes :value, type: 'text', fields: { raw: { type: 'keyword' } } context.indexes :custom_field_id, type: 'integer' end end |