Class: Pageflow::Admin::FormInputs

Inherits:
Object
  • Object
show all
Defined in:
lib/pageflow/admin/form_inputs.rb

Overview

A registry of additional inputs for admin forms.

Since:

  • 0.9

Instance Method Summary collapse

Constructor Details

#initializeFormInputs

Returns a new instance of FormInputs.

Since:

  • 0.9



7
8
9
# File 'lib/pageflow/admin/form_inputs.rb', line 7

def initialize
  @resources = {}
end

Instance Method Details

#build(resource_name, form_builder) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.9



24
25
26
27
28
# File 'lib/pageflow/admin/form_inputs.rb', line 24

def build(resource_name, form_builder)
  find_all_for(resource_name).each do |form_input|
    form_input.build(form_builder)
  end
end

#find_all_for(resource_name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.9



36
37
38
# File 'lib/pageflow/admin/form_inputs.rb', line 36

def find_all_for(resource_name)
  @resources.fetch(resource_name, [])
end

#permitted_attributes_for(resource_name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.9



31
32
33
# File 'lib/pageflow/admin/form_inputs.rb', line 31

def permitted_attributes_for(resource_name)
  find_all_for(resource_name).map(&:attribute_name)
end

#register(resource_name, attribute_name, options = {}) ⇒ Object

Register a proc which adds additional inputs to admin forms.

Parameters:

  • resource_name (Symbol)

    A resource name like ‘:entry`, `:account` or `:theming`

  • attribute_name (Symbol)

    The name of the additional attribute

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

    Formtastic options

Since:

  • 0.9



18
19
20
21
# File 'lib/pageflow/admin/form_inputs.rb', line 18

def register(resource_name, attribute_name, options = {})
  @resources[resource_name] ||= []
  @resources[resource_name] << FormInput.new(attribute_name, options)
end