Class: Adminable::Fields::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/adminable/fields/base.rb

Overview

Note:

Cannot be initialized

Base class for fields

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Base.

Parameters:

  • name (Symbol)

    field name e.g. ‘:id` or `:title`

  • options (Hash) (defaults to: {})

    options, see #default_options



14
15
16
17
18
19
# File 'lib/adminable/fields/base.rb', line 14

def initialize(name, options = {})
  raise 'Base class cannot be initialized' if self.class == Base

  @name = name.to_sym
  @options = default_options.merge(options)
end

Instance Attribute Details

#nameSymbol (readonly)

Returns field name.

Returns:

  • (Symbol)

    field name



7
8
9
# File 'lib/adminable/fields/base.rb', line 7

def name
  @name
end

#optionsHash (readonly)

Returns default options for field.

Returns:

  • (Hash)

    default options for field



10
11
12
# File 'lib/adminable/fields/base.rb', line 10

def options
  @options
end

Instance Method Details

#form_partial_pathString

Returns path to field form partial.

Returns:

  • (String)

    path to field form partial



50
51
52
# File 'lib/adminable/fields/base.rb', line 50

def form_partial_path
  "form/#{type}"
end

#index_partial_pathString

Returns path to field index partial.

Returns:

  • (String)

    path to field index partial



45
46
47
# File 'lib/adminable/fields/base.rb', line 45

def index_partial_path
  "index/#{type}"
end

#keySymbol

Returns field form key.

Returns:

  • (Symbol)

    field form key



22
23
24
# File 'lib/adminable/fields/base.rb', line 22

def key
  @key ||= name
end

#ransack_nameString

Returns ransack form key.

Returns:

  • (String)

    ransack form key



32
33
34
# File 'lib/adminable/fields/base.rb', line 32

def ransack_name
  @ransack_name ||= "#{name}_cont"
end

#strong_parameterSymbol

Returns controller strong parameters key.

Returns:

  • (Symbol)

    controller strong parameters key



27
28
29
# File 'lib/adminable/fields/base.rb', line 27

def strong_parameter
  @strong_parameter ||= key
end

#typeSymbol

Returns field type.

Examples:

Adminable::Fields::String.new(:title).type
# => :string

Returns:

  • (Symbol)

    field type



40
41
42
# File 'lib/adminable/fields/base.rb', line 40

def type
  @type ||= self.class.name.demodulize.underscore.to_sym
end