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
40 41 42 |
# File 'app/models/alchemy/ingredient_definition.rb', line 40 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
63 64 65 66 67 68 69 70 |
# File 'app/models/alchemy/ingredient_definition.rb', line 63 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 is deprecated
You can scope the translation per element as well.
en:
alchemy:
ingredient_deprecation_notices:
element_name:
old_ingredient: Elements foo baz is deprecated
or use the global translation that apply to all deprecated ingredients.
en:
alchemy:
ingredient_deprecation_notice: Foo baz is deprecated
or pass string as deprecation notice.
- name: element_name
ingredients:
- role: old_ingredient
type: Text
deprecated: This ingredient will be removed soon.
116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'app/models/alchemy/ingredient_definition.rb', line 116 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
44 45 46 |
# File 'app/models/alchemy/ingredient_definition.rb', line 44 def settings super.with_indifferent_access end |
#validate ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'app/models/alchemy/ingredient_definition.rb', line 48 def validate super.map do |validation| case validation when Hash validation.with_indifferent_access else validation end end end |