Class: TaskMaster::CustomRequestField

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
app/models/task_master/custom_request_field.rb

Constant Summary collapse

DEFAULT_ATTRIBUTES =
{ required: false }
VALID_TYPES =
%w(text textarea tel number email money date datetime-local bool checkbox radio)
TYPES_WITH_OPTIONS =
%w(checkbox radio)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ CustomRequestField

Returns a new instance of CustomRequestField.



13
14
15
16
# File 'app/models/task_master/custom_request_field.rb', line 13

def initialize(attributes = {})
  attributes = attributes.reverse_merge(DEFAULT_ATTRIBUTES)
  super(attributes)
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



11
12
13
# File 'app/models/task_master/custom_request_field.rb', line 11

def description
  @description
end

#field_nameObject

Returns the value of attribute field_name.



11
12
13
# File 'app/models/task_master/custom_request_field.rb', line 11

def field_name
  @field_name
end

#labelObject

Returns the value of attribute label.



11
12
13
# File 'app/models/task_master/custom_request_field.rb', line 11

def label
  @label
end

#optionsObject

Returns the value of attribute options.



11
12
13
# File 'app/models/task_master/custom_request_field.rb', line 11

def options
  @options
end

#orderObject

Returns the value of attribute order.



11
12
13
# File 'app/models/task_master/custom_request_field.rb', line 11

def order
  @order
end

#requiredObject

Returns the value of attribute required.



11
12
13
# File 'app/models/task_master/custom_request_field.rb', line 11

def required
  @required
end

#typeObject

Returns the value of attribute type.



11
12
13
# File 'app/models/task_master/custom_request_field.rb', line 11

def type
  @type
end

Instance Method Details

#_initialize_requiredObject



40
41
42
# File 'app/models/task_master/custom_request_field.rb', line 40

def _initialize_required
  self.required = false if self.required.nil?
end

#to_hashObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/models/task_master/custom_request_field.rb', line 48

def to_hash
  hash = {
    type: type,
    label: label,
    description: description,
    field_name: field_name,
    required: required,
    order: order
  }
  if TYPES_WITH_OPTIONS.include?(type)
    hash[:options] = options
  end
  hash
end