Class: Alchemy::IngredientDefinition
- Inherits:
-
Object
- Object
- Alchemy::IngredientDefinition
- Extended by:
- ActiveModel::Translation
- Includes:
- ActiveModel::Attributes, ActiveModel::Model, Hints
- Defined in:
- app/models/alchemy/ingredient_definition.rb
Instance Method Summary collapse
- #attributes ⇒ Object
-
#default_value ⇒ Object
Returns the default value from ingredient definition.
-
#deprecation_notice(element_name: nil) ⇒ Object
Returns a deprecation notice for ingredients marked deprecated.
- #settings ⇒ Object
- #validate ⇒ Object
Methods included from Hints
Instance Method Details
#attributes ⇒ Object
35 36 37 |
# File 'app/models/alchemy/ingredient_definition.rb', line 35 def attributes super.with_indifferent_access end |
#default_value ⇒ Object
Returns the default value from ingredient definition
If the value is a symbol it gets passed through i18n inside the alchemy.default_ingredient_texts scope
58 59 60 61 62 63 64 65 |
# File 'app/models/alchemy/ingredient_definition.rb', line 58 def default_value case default when Symbol Alchemy.t(default, scope: :default_ingredient_texts) when String default end end |
#deprecation_notice(element_name: nil) ⇒ Object
Returns a deprecation notice for ingredients marked deprecated
You can either use localizations or pass a String as notice in the ingredient definition.
Custom deprecation notices
Use general ingredient deprecation notice
- name: element_name
ingredients:
- role: old_ingredient
type: Text
deprecated: true
Add a translation to your locale file for a per ingredient notice.
en:
alchemy:
ingredient_deprecation_notices:
old_ingredient: Foo baz widget is deprecated
You can scope the translation per element as well.
en:
alchemy:
ingredient_deprecation_notices:
element_name:
old_ingredient: Elements foo baz widget is deprecated
or use the global translation that apply to all deprecated ingredients.
en:
alchemy:
ingredient_deprecation_notice: Foo baz widget is deprecated
or pass string as deprecation notice.
- name: element_name
ingredients:
- role: old_ingredient
type: Text
deprecated: This ingredient will be removed soon.
111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'app/models/alchemy/ingredient_definition.rb', line 111 def deprecation_notice(element_name: nil) case deprecated when String deprecated when TrueClass Alchemy.t( role, scope: [:ingredient_deprecation_notices, element_name].compact, default: Alchemy.t(:ingredient_deprecated) ) end end |
#settings ⇒ Object
39 40 41 |
# File 'app/models/alchemy/ingredient_definition.rb', line 39 def settings super.with_indifferent_access end |
#validate ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'app/models/alchemy/ingredient_definition.rb', line 43 def validate super.map do |validation| case validation when Hash validation.with_indifferent_access else validation end end end |