Class: EditInPlace::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/edit_in_place/configuration.rb

Overview

Configuration is a class that is capable of storing configuration for an edit_in_place Builder. Essentially all the options provided by edit_in_place reside in this class, for easy reuse. This class is currently used in two locations—the global configuration in config and the builder-specific configuration in Builder#config.

Author:

  • Jacob Lockard

Since:

  • 0.1.0

Constant Summary collapse

DEFAULT_MODE =

The default mode in which fields should be rendered if left unspecified in #field_options.

Since:

  • 0.1.0

:viewing

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Creates a new, default instance of EditInPlace::Configuration.

Since:

  • 0.1.0


38
39
40
41
42
43
# File 'lib/edit_in_place/configuration.rb', line 38

def initialize
  @field_types = FieldTypeRegistrar.new
  @field_options = FieldOptions.new(mode: DEFAULT_MODE)
  @defined_middlewares = []
  @registered_middlewares = MiddlewareRegistrar.new
end

Instance Attribute Details

#defined_middlewaresArray

An array containing all the middleware classes permitted, in the order they should be run.

Returns:

  • (Array)

    the array of defined middlewares.

Since:

  • 0.1.0


30
31
32
# File 'lib/edit_in_place/configuration.rb', line 30

def defined_middlewares
  @defined_middlewares
end

#field_optionsFieldOptions

The default FieldOptions instance to use when a builder renders a field. Note that this instance will be merged with the one passed directly to Builder#field.

Returns:

  • (FieldOptions)

    the default field options to use when rendering a field.

Since:

  • 0.1.0


26
27
28
# File 'lib/edit_in_place/configuration.rb', line 26

def field_options
  @field_options
end

#field_typesFieldTypeRegistrar

The FieldTypeRegistrar used to store the list of registered field types.

Returns:

Since:

  • 0.1.0


21
22
23
# File 'lib/edit_in_place/configuration.rb', line 21

def field_types
  @field_types
end

#registered_middlewaresMiddlewareRegistrar

The MiddlewareRegistrar used to store the list of registered middlewares.

Returns:

Since:

  • 0.1.0


35
36
37
# File 'lib/edit_in_place/configuration.rb', line 35

def registered_middlewares
  @registered_middlewares
end

Instance Method Details

#dupConfiguration

Creates a deep copy of this EditInPlace::Configuration that can be safely modified.

Returns:

Since:

  • 0.1.0


47
48
49
50
51
52
53
54
55
# File 'lib/edit_in_place/configuration.rb', line 47

def dup
  c = self.class.new
  c.field_types = field_types.dup
  c.field_options = field_options.dup
  # Note that this is purposely NOT a deep copy---it doesn't make sense to duplicate classes.
  c.defined_middlewares = defined_middlewares.dup
  c.registered_middlewares = registered_middlewares.dup
  c
end