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



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)



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

def name
  @name
end

#optionsHash (readonly)



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

def options
  @options
end

Instance Method Details

#form_partial_pathString



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

def form_partial_path
  "form/#{type}"
end

#index_partial_pathString



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

def index_partial_path
  "index/#{type}"
end

#keySymbol



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

def key
  @key ||= name
end

#ransack_nameString



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

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

#strong_parameterSymbol



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


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

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