Sha256: d3ed98865752d0a90cebaecf2e9bbcf5b7401cc245626695b91bf28574786ba4

Contents?: true

Size: 820 Bytes

Versions: 19

Compression:

Stored size: 820 Bytes

Contents

# frozen_string_literal: true

module Tramway::Core::ExtendableFormsHelpers::MorePropertiesHelper
  def define_property_method(property_name)
    define_method property_name do
      model.values[property_name] if model.values
    end
  end

  def define_assignment_method(property)
    define_method "#{property[0]}=" do |value|
      property[1][:validates].each do |pair|
        make_validates property[0], pair, value
      end
    end
  end

  def define_file_property_assignment_method(property, field)
    define_method "#{property[0]}=" do |value|
      file_instance = property[1][:association_model].find_or_create_by(
        "#{model.class.name.underscore}_id" => model.id, "#{field.class.name.underscore}_id" => field.id
      )
      file_instance.file = value
      file_instance.save!
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
tramway-core-1.18 app/forms/tramway/core/extendable_forms_helpers/more_properties_helper.rb
tramway-core-1.17.9.1 app/forms/tramway/core/extendable_forms_helpers/more_properties_helper.rb
tramway-core-1.17.9 app/forms/tramway/core/extendable_forms_helpers/more_properties_helper.rb
tramway-core-1.17.8 app/forms/tramway/core/extendable_forms_helpers/more_properties_helper.rb
tramway-core-1.17.7.2 app/forms/tramway/core/extendable_forms_helpers/more_properties_helper.rb
tramway-core-1.17.7.1 app/forms/tramway/core/extendable_forms_helpers/more_properties_helper.rb
tramway-core-1.17.7 app/forms/tramway/core/extendable_forms_helpers/more_properties_helper.rb
tramway-core-1.17.6.1 app/forms/tramway/core/extendable_forms_helpers/more_properties_helper.rb
tramway-core-1.17.6 app/forms/tramway/core/extendable_forms_helpers/more_properties_helper.rb
tramway-core-1.17.5 app/forms/tramway/core/extendable_forms_helpers/more_properties_helper.rb
tramway-core-1.17.4.2 app/forms/tramway/core/extendable_forms_helpers/more_properties_helper.rb
tramway-core-1.17.4.1 app/forms/tramway/core/extendable_forms_helpers/more_properties_helper.rb
tramway-core-1.17.4 app/forms/tramway/core/extendable_forms_helpers/more_properties_helper.rb
tramway-core-1.17.3.1 app/forms/tramway/core/extendable_forms_helpers/more_properties_helper.rb
tramway-core-1.17.3 app/forms/tramway/core/extendable_forms_helpers/more_properties_helper.rb
tramway-core-1.17.2.5 app/forms/tramway/core/extendable_forms_helpers/more_properties_helper.rb
tramway-core-1.17.2.4 app/forms/tramway/core/extendable_forms_helpers/more_properties_helper.rb
tramway-core-1.17.2.3 app/forms/tramway/core/extendable_forms_helpers/more_properties_helper.rb
tramway-core-1.17.2.2 app/forms/tramway/core/extendable_forms_helpers/more_properties_helper.rb