Class: Workarea::Content::Field

Inherits:
Object
  • Object
show all
Defined in:
app/models/workarea/content/field.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ Field

Returns a new instance of Field.



6
7
8
9
# File 'app/models/workarea/content/field.rb', line 6

def initialize(name, options = {})
  @name = name
  @options = options
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'app/models/workarea/content/field.rb', line 4

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'app/models/workarea/content/field.rb', line 4

def options
  @options
end

Instance Method Details

#defaultObject



19
20
21
22
23
24
25
# File 'app/models/workarea/content/field.rb', line 19

def default
  if options[:default].respond_to?(:call)
    options[:default].call
  else
    options[:default]
  end
end

#noteObject



40
41
42
# File 'app/models/workarea/content/field.rb', line 40

def note
  options[:note]
end

#partialObject



27
28
29
30
# File 'app/models/workarea/content/field.rb', line 27

def partial
  options[:partial].presence ||
    self.class.name.demodulize.underscore.systemize
end

#required?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'app/models/workarea/content/field.rb', line 32

def required?
  !!options[:required]
end

#slugObject



11
12
13
# File 'app/models/workarea/content/field.rb', line 11

def slug
  name.to_s.systemize.to_sym
end

#tooltipObject



44
45
46
# File 'app/models/workarea/content/field.rb', line 44

def tooltip
  options[:tooltip]
end

#typeObject



15
16
17
# File 'app/models/workarea/content/field.rb', line 15

def type
  self.class.name.demodulize.systemize.to_sym
end

#typecast(value) ⇒ Object



36
37
38
# File 'app/models/workarea/content/field.rb', line 36

def typecast(value)
  value.to_s
end