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



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

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

#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

#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