Class: Infold::Field
- Inherits:
-
Object
- Object
- Infold::Field
- Defined in:
- lib/infold/field.rb
Instance Attribute Summary collapse
-
#active_storage ⇒ Object
readonly
Returns the value of attribute active_storage.
-
#association ⇒ Object
readonly
Returns the value of attribute association.
-
#association_search_list_seq ⇒ Object
Returns the value of attribute association_search_list_seq.
-
#csv_seq ⇒ Object
Returns the value of attribute csv_seq.
-
#decorator ⇒ Object
readonly
Returns the value of attribute decorator.
-
#enum ⇒ Object
readonly
Returns the value of attribute enum.
-
#form_element ⇒ Object
readonly
Returns the value of attribute form_element.
-
#index_list_seq ⇒ Object
Returns the value of attribute index_list_seq.
-
#search_conditions ⇒ Object
readonly
Returns the value of attribute search_conditions.
-
#show_element ⇒ Object
readonly
Returns the value of attribute show_element.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#validation ⇒ Object
readonly
Returns the value of attribute validation.
Instance Method Summary collapse
- #active_storage? ⇒ Boolean
- #add_search_condition(view_kind, sign:, form_kind:, seq: 0, association_name: nil) ⇒ Object
- #add_validation(condition, options = {}) ⇒ Object
- #association? ⇒ Boolean
- #build_active_storage(**attrs) ⇒ Object
- #build_association(**attrs) ⇒ Object
- #build_decorator(**attrs) ⇒ Object
- #build_enum ⇒ Object
- #build_form_element(**attrs) ⇒ Object
- #build_show_element(**attrs) ⇒ Object
- #datepicker? ⇒ Boolean
- #decorator? ⇒ Boolean
- #enum? ⇒ Boolean
- #form_element? ⇒ Boolean
- #in_association_search_list? ⇒ Boolean
- #in_csv? ⇒ Boolean
- #in_index_list? ⇒ Boolean
-
#initialize(name, type = nil) ⇒ Field
constructor
A new instance of Field.
- #name(*attr) ⇒ Object
- #number? ⇒ Boolean
- #validation? ⇒ Boolean
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_storage ⇒ Object (readonly)
Returns the value of attribute active_storage.
12 13 14 |
# File 'lib/infold/field.rb', line 12 def active_storage @active_storage end |
#association ⇒ Object (readonly)
Returns the value of attribute association.
12 13 14 |
# File 'lib/infold/field.rb', line 12 def association @association end |
#association_search_list_seq ⇒ Object
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_seq ⇒ Object
Returns the value of attribute csv_seq.
22 23 24 |
# File 'lib/infold/field.rb', line 22 def csv_seq @csv_seq end |
#decorator ⇒ Object (readonly)
Returns the value of attribute decorator.
12 13 14 |
# File 'lib/infold/field.rb', line 12 def decorator @decorator end |
#enum ⇒ Object (readonly)
Returns the value of attribute enum.
12 13 14 |
# File 'lib/infold/field.rb', line 12 def enum @enum end |
#form_element ⇒ Object (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_seq ⇒ Object
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_conditions ⇒ Object (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_element ⇒ Object (readonly)
Returns the value of attribute show_element.
12 13 14 |
# File 'lib/infold/field.rb', line 12 def show_element @show_element end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
12 13 14 |
# File 'lib/infold/field.rb', line 12 def type @type end |
#validation ⇒ Object (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
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, = {}) @validation ||= Validation.new(self) @validation.add_conditions(condition, ) end |
#association? ⇒ 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_enum ⇒ Object
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
92 93 94 |
# File 'lib/infold/field.rb', line 92 def datepicker? %w(date datetime).include?(type.to_s) end |
#decorator? ⇒ Boolean
66 |
# File 'lib/infold/field.rb', line 66 def decorator?; @decorator.present? end |
#enum? ⇒ Boolean
65 |
# File 'lib/infold/field.rb', line 65 def enum?; @enum.present? end |
#form_element? ⇒ Boolean
70 |
# File 'lib/infold/field.rb', line 70 def form_element?; @form_element.present? end |
#in_association_search_list? ⇒ Boolean
102 |
# File 'lib/infold/field.rb', line 102 def in_association_search_list?; association_search_list_seq.present? end |
#in_csv? ⇒ Boolean
101 |
# File 'lib/infold/field.rb', line 101 def in_csv?; csv_seq.present? end |
#in_index_list? ⇒ 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
96 97 98 |
# File 'lib/infold/field.rb', line 96 def number? %w(integer float decimal).include?(type.to_s) end |
#validation? ⇒ Boolean
68 |
# File 'lib/infold/field.rb', line 68 def validation?; @validation.present? end |