Class: Backstage::Field

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Field.



5
6
7
8
9
# File 'lib/backstage/field.rb', line 5

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/backstage/field.rb', line 3

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/backstage/field.rb', line 3

def options
  @options
end

#typeObject (readonly)

Returns the value of attribute type.



3
4
5
# File 'lib/backstage/field.rb', line 3

def type
  @type
end

Instance Method Details

#associationObject



59
60
61
# File 'lib/backstage/field.rb', line 59

def association
  options[:association]
end

#belongs_to?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/backstage/field.rb', line 27

def belongs_to?
  type == :belongs_to
end

#collapsed?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/backstage/field.rb', line 55

def collapsed?
  options.fetch(:collapsed, false)
end

#container?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/backstage/field.rb', line 43

def container?
  row? || section?
end

#enum?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/backstage/field.rb', line 19

def enum?
  type == :enum
end

#enum_valuesObject



23
24
25
# File 'lib/backstage/field.rb', line 23

def enum_values
  options[:enum_values] || []
end

#has_many?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/backstage/field.rb', line 31

def has_many?
  type == :has_many
end

#headingObject



51
52
53
# File 'lib/backstage/field.rb', line 51

def heading
  options[:heading]
end

#partial_pathObject



11
12
13
# File 'lib/backstage/field.rb', line 11

def partial_path
  options[:partial] || "backstage/fields/#{type}"
end

#readonly?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/backstage/field.rb', line 15

def readonly?
  options.fetch(:readonly, false)
end

#row?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/backstage/field.rb', line 35

def row?
  type == :row
end

#section?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/backstage/field.rb', line 39

def section?
  type == :section
end

#sub_fieldsObject



47
48
49
# File 'lib/backstage/field.rb', line 47

def sub_fields
  options[:sub_fields] || []
end