Class: Madmin::Field

Inherits:
Object
  • Object
show all
Defined in:
lib/madmin.rb,
lib/madmin/field.rb,
lib/madmin/field/text.rb,
lib/madmin/field/email.rb,
lib/madmin/field/number.rb,
lib/madmin/field/select.rb,
lib/madmin/field/has_one.rb,
lib/madmin/field/has_many.rb,
lib/madmin/field/password.rb,
lib/madmin/field/check_box.rb,
lib/madmin/field/date_time.rb,
lib/madmin/field/text_area.rb,
lib/madmin/field/belongs_to.rb,
lib/madmin/field/polymorphic.rb,
lib/madmin/field/associatable.rb

Defined Under Namespace

Modules: Associatable Classes: BelongsTo, CheckBox, DateTime, Email, HasMany, HasOne, Number, Password, Polymorphic, Select, Text, TextArea

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Field

Returns a new instance of Field.



12
13
14
15
16
17
18
19
20
# File 'lib/madmin/field.rb', line 12

def initialize(args)
  @key     = args[:key]
  @options = args
  @model   = args[:model]
  @label   = option_or_default(:label, label_from_attribute(key))
  @form    = option_or_default(:form, false)
  @index   = option_or_default(:index, false)
  @show    = option_or_default(:show, true)
end

Instance Attribute Details

#formObject (readonly)

Returns the value of attribute form.



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

def form
  @form
end

#indexObject (readonly)

Returns the value of attribute index.



4
5
6
# File 'lib/madmin/field.rb', line 4

def index
  @index
end

#keyObject (readonly)

Returns the value of attribute key.



5
6
7
# File 'lib/madmin/field.rb', line 5

def key
  @key
end

#labelObject (readonly)

Returns the value of attribute label.



6
7
8
# File 'lib/madmin/field.rb', line 6

def label
  @label
end

#modelObject (readonly)

Returns the value of attribute model.



7
8
9
# File 'lib/madmin/field.rb', line 7

def model
  @model
end

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/madmin/field.rb', line 8

def options
  @options
end

#showObject (readonly)

Returns the value of attribute show.



9
10
11
# File 'lib/madmin/field.rb', line 9

def show
  @show
end

#typeObject (readonly)

Returns the value of attribute type.



10
11
12
# File 'lib/madmin/field.rb', line 10

def type
  @type
end

Instance Method Details

#strong_params_keysObject

Returns an array of key(s) to use in strong params for the resources controller.



25
26
27
# File 'lib/madmin/field.rb', line 25

def strong_params_keys
  [key]
end

#to_partial_pathObject

Returns the partial path for the field type



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

def to_partial_path
  "madmin/fields/#{self.class.to_s.split("Madmin::Field::").last.underscore}"
end

#value_for(resource) ⇒ Object

Returns the value for a given resource



37
38
39
# File 'lib/madmin/field.rb', line 37

def value_for(resource)
  resource.send(key)
end