Class: Infold::Condition

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
lib/infold/property/condition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(field, **attrs) ⇒ Condition

Returns a new instance of Condition.



13
14
15
16
# File 'lib/infold/property/condition.rb', line 13

def initialize(field, **attrs)
  @field = field
  super(**attrs)
end

Instance Attribute Details

#association_search_form_kindObject

Returns the value of attribute association_search_form_kind.



7
8
9
# File 'lib/infold/property/condition.rb', line 7

def association_search_form_kind
  @association_search_form_kind
end

#association_seqObject

Returns the value of attribute association_seq.



7
8
9
# File 'lib/infold/property/condition.rb', line 7

def association_seq
  @association_seq
end

#fieldObject (readonly)

Returns the value of attribute field.



5
6
7
# File 'lib/infold/property/condition.rb', line 5

def field
  @field
end

#index_association_nameObject

Returns the value of attribute index_association_name.



7
8
9
# File 'lib/infold/property/condition.rb', line 7

def index_association_name
  @index_association_name
end

#index_form_kindObject

Returns the value of attribute index_form_kind.



7
8
9
# File 'lib/infold/property/condition.rb', line 7

def index_form_kind
  @index_form_kind
end

#index_seqObject

Returns the value of attribute index_seq.



7
8
9
# File 'lib/infold/property/condition.rb', line 7

def index_seq
  @index_seq
end

#signObject



18
19
20
# File 'lib/infold/property/condition.rb', line 18

def sign
  (@sign.presence || :eq).to_sym
end

Instance Method Details

#form_kind(view) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/infold/property/condition.rb', line 34

def form_kind(view)
  # indexとassociation_searchでform_kindが異なる場合に対応
  _form_kind = (view == :index ? index_form_kind : association_search_form_kind).to_s
  if _form_kind == 'association_search' && field.association&.belongs_to?
    :association_search
  elsif _form_kind == 'select'
    :select
  elsif sign == :any && field.enum.present?
    :checkbox
  elsif field.type == :boolean || _form_kind == 'switch'
    :switch
  else
    :text
  end
end

#in_association_search?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/infold/property/condition.rb', line 30

def in_association_search?
  association_search_form_kind.present?
end

#in_index?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/infold/property/condition.rb', line 26

def in_index?
  index_form_kind.present?
end

#scopeObject



22
23
24
# File 'lib/infold/property/condition.rb', line 22

def scope
  "#{field.name}_#{sign}"
end

#sign_labelObject



50
51
52
53
54
55
56
57
58
# File 'lib/infold/property/condition.rb', line 50

def sign_label
  case sign
  when :lteq then 'or less'
  when :gteq then 'or more'
  when :full_like then 'like %...%'
  when :start_with then 'like ...%'
  else '='
  end
end