Class: Resourcerer::Configuration
- Inherits:
-
Object
- Object
- Resourcerer::Configuration
- Defined in:
- lib/resourcerer/configuration.rb
Overview
Internal: Normalizes configuration options by providing common shortcuts for certain options. These shortcuts make the library easier to use.
Examples:
find_by: :name ->(name, collection) { collection.find_by(name: name)}
assign?: :update -> { action_name == 'update' }
id: :person_id -> { params[:person_id] }
Constant Summary collapse
- OPTIONS =
Public: Available configuration options for a Resource.
[ :assign, :assign?, :attrs, :build, :collection, :find, :find_by, :id, :model, :permit, ].freeze
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#apply(other_options) ⇒ Object
Public: Applies the configuration to the specified options.
-
#initialize(options, &block) ⇒ Configuration
constructor
Public: Normalizes configuration options for a Resource, ensuring every relevant option is assigned a Proc.
Constructor Details
#initialize(options, &block) ⇒ Configuration
Public: Normalizes configuration options for a Resource, ensuring every relevant option is assigned a Proc.
options - Config Hash for the new Resource. See OPTIONS. block - If supplied, the block is executed to provide options.
Returns a Hash where every value is a Proc.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/resourcerer/configuration.rb', line 35 def initialize(, &block) = instance_eval(&block) if block_given? :find_by, :find :permit, :attrs normalize_assign_option normalize_attrs_option normalize_find_by_option normalize_id_option normalize_model_option normalize_permit_option *OPTIONS end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
26 27 28 |
# File 'lib/resourcerer/configuration.rb', line 26 def end |
Instance Method Details
#apply(other_options) ⇒ Object
Public: Applies the configuration to the specified options. Does not override an option if it had previously been specified.
Returns the updated configuration options.
56 57 58 |
# File 'lib/resourcerer/configuration.rb', line 56 def apply() .reverse_merge!() end |