Sha256: efcabeec9ac849e4556c642fc06fe526e7d18c84974478e201279a3b2801ab6b

Contents?: true

Size: 1.24 KB

Versions: 24

Compression:

Stored size: 1.24 KB

Contents

class Refine::Inline::Criteria::Input
  include ActiveModel::Model

  MODIFIERS = {
    ago: "days ago",
    from_now: "days from now"
  }.freeze

  attr_accessor :clause,
  :date1,
  :date2,
  :days,
  :modifier,
  :selected,
  :value,
  :value1,
  :value2,
  :count_refinement,
  :date_refinement

  def attributes
    {
      clause: clause,
      date1: date1,
      date2: date2,
      days: days,
      modifier: modifier,
      selected: selected,
      value: value,
      value1: value1,
      value2: value2,
      count_refinement: count_refinement_attributes.presence,
      date_refinement: date_refinement_attributes.presence
    }.compact
  end

  def count_refinement
    @count_refinement ||= Refine::Inline::Criteria::NumericRefinement.new
  end

  def count_refinement_attributes
    count_refinement.attributes
  end

  def count_refinement_attributes=(attrs = {})
    count_refinement.attributes = attrs.to_h
  end

  def date_refinement
    @date_refinement ||= Refine::Inline::Criteria::DateRefinement.new
  end

  def date_refinement_attributes
    date_refinement.attributes
  end

  def date_refinement_attributes=(attrs = {})
    date_refinement.attributes = attrs.to_h
  end

  def selected=(value)
    @selected = Array.wrap(value)
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
refine-rails-2.9.7 app/models/refine/inline/criteria/input.rb
refine-rails-2.9.6 app/models/refine/inline/criteria/input.rb
refine-rails-2.9.5 app/models/refine/inline/criteria/input.rb
refine-rails-2.9.4 app/models/refine/inline/criteria/input.rb