Class: Infold::Field

Inherits:
Object
  • Object
show all
Defined in:
lib/infold/field.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type = nil) ⇒ Field

Returns a new instance of Field.



26
27
28
29
30
# File 'lib/infold/field.rb', line 26

def initialize(name, type=nil)
  @name = name
  @type = type&.to_sym
  @search_conditions = []
end

Instance Attribute Details

#active_storageObject (readonly)

Returns the value of attribute active_storage.



12
13
14
# File 'lib/infold/field.rb', line 12

def active_storage
  @active_storage
end

#associationObject (readonly)

Returns the value of attribute association.



12
13
14
# File 'lib/infold/field.rb', line 12

def association
  @association
end

#association_search_list_seqObject

Returns the value of attribute association_search_list_seq.



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

def association_search_list_seq
  @association_search_list_seq
end

#csv_seqObject

Returns the value of attribute csv_seq.



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

def csv_seq
  @csv_seq
end

#decoratorObject (readonly)

Returns the value of attribute decorator.



12
13
14
# File 'lib/infold/field.rb', line 12

def decorator
  @decorator
end

#enumObject (readonly)

Returns the value of attribute enum.



12
13
14
# File 'lib/infold/field.rb', line 12

def enum
  @enum
end

#form_elementObject (readonly)

Returns the value of attribute form_element.



12
13
14
# File 'lib/infold/field.rb', line 12

def form_element
  @form_element
end

#index_list_seqObject

Returns the value of attribute index_list_seq.



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

def index_list_seq
  @index_list_seq
end

#search_conditionsObject (readonly)

Returns the value of attribute search_conditions.



12
13
14
# File 'lib/infold/field.rb', line 12

def search_conditions
  @search_conditions
end

#show_elementObject (readonly)

Returns the value of attribute show_element.



12
13
14
# File 'lib/infold/field.rb', line 12

def show_element
  @show_element
end

#typeObject (readonly)

Returns the value of attribute type.



12
13
14
# File 'lib/infold/field.rb', line 12

def type
  @type
end

#validationObject (readonly)

Returns the value of attribute validation.



12
13
14
# File 'lib/infold/field.rb', line 12

def validation
  @validation
end

Instance Method Details

#active_storage?Boolean

Returns:

  • (Boolean)


69
# File 'lib/infold/field.rb', line 69

def active_storage?; @active_storage.present? end

#add_search_condition(view_kind, sign:, form_kind:, seq: 0, association_name: nil) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/infold/field.rb', line 77

def add_search_condition(view_kind, sign:, form_kind:, seq: 0, association_name: nil)
  form_kind = 'text' if form_kind.blank?
  condition = @search_conditions.find{ |sc| sc.sign == sign.to_sym }
  condition ||= (@search_conditions << Condition.new(self, sign: sign)).last
  if view_kind == :index
    condition.index_form_kind = form_kind
    condition.index_seq = seq
  else
    condition.association_search_form_kind = form_kind
    condition.association_seq = seq
  end
  condition.index_association_name = association_name
  condition
end

#add_validation(condition, options = {}) ⇒ Object



72
73
74
75
# File 'lib/infold/field.rb', line 72

def add_validation(condition, options = {})
  @validation ||= Validation.new(self)
  @validation.add_conditions(condition, options)
end

#association?Boolean

Returns:

  • (Boolean)


67
# File 'lib/infold/field.rb', line 67

def association?; @association.present? end

#build_active_storage(**attrs) ⇒ Object



41
42
43
# File 'lib/infold/field.rb', line 41

def build_active_storage(**attrs)
  @active_storage = ActiveStorage.new(self, **attrs)
end

#build_association(**attrs) ⇒ Object



45
46
47
# File 'lib/infold/field.rb', line 45

def build_association(**attrs)
  @association = Association.new(self, **attrs)
end

#build_decorator(**attrs) ⇒ Object



61
62
63
# File 'lib/infold/field.rb', line 61

def build_decorator(**attrs)
  @decorator = Decorator.new(self, **attrs)
end

#build_enumObject



49
50
51
# File 'lib/infold/field.rb', line 49

def build_enum
  @enum = Enum.new(self)
end

#build_form_element(**attrs) ⇒ Object



57
58
59
# File 'lib/infold/field.rb', line 57

def build_form_element(**attrs)
  @form_element = FormElement.new(self, **attrs)
end

#build_show_element(**attrs) ⇒ Object



53
54
55
# File 'lib/infold/field.rb', line 53

def build_show_element(**attrs)
  @show_element = ShowElement.new(self, **attrs)
end

#datepicker?Boolean

Returns:

  • (Boolean)


92
93
94
# File 'lib/infold/field.rb', line 92

def datepicker?
  %w(date datetime).include?(type.to_s)
end

#decorator?Boolean

Returns:

  • (Boolean)


66
# File 'lib/infold/field.rb', line 66

def decorator?; @decorator.present? end

#enum?Boolean

Returns:

  • (Boolean)


65
# File 'lib/infold/field.rb', line 65

def enum?; @enum.present? end

#form_element?Boolean

Returns:

  • (Boolean)


70
# File 'lib/infold/field.rb', line 70

def form_element?; @form_element.present? end

#in_association_search_list?Boolean

Returns:

  • (Boolean)


102
# File 'lib/infold/field.rb', line 102

def in_association_search_list?; association_search_list_seq.present? end

#in_csv?Boolean

Returns:

  • (Boolean)


101
# File 'lib/infold/field.rb', line 101

def in_csv?; csv_seq.present? end

#in_index_list?Boolean

Returns:

  • (Boolean)


100
# File 'lib/infold/field.rb', line 100

def in_index_list?; index_list_seq.present? end

#name(*attr) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/infold/field.rb', line 32

def name(*attr)
  name = @name
  name = name.underscore if attr.include?(:snake)
  name = name.camelize if attr.include?(:camel)
  name = name.singularize if attr.include?(:single)
  name = name.pluralize if attr.include?(:multi)
  name
end

#number?Boolean

Returns:

  • (Boolean)


96
97
98
# File 'lib/infold/field.rb', line 96

def number?
  %w(integer float decimal).include?(type.to_s)
end

#validation?Boolean

Returns:

  • (Boolean)


68
# File 'lib/infold/field.rb', line 68

def validation?; @validation.present? end