Class: ModelFormatting::Config
- Inherits:
-
Object
- Object
- ModelFormatting::Config
- Defined in:
- lib/model_formatting/config.rb
Overview
Used to configure model formatting for a specific class. See ModelFormatting::Init
Instance Attribute Summary collapse
-
#after_callback ⇒ Object
readonly
Returns the value of attribute after_callback.
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#before_callback ⇒ Object
readonly
Returns the value of attribute before_callback.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#white_list ⇒ Object
readonly
Returns the value of attribute white_list.
Instance Method Summary collapse
- #after(&block) ⇒ Object
- #before(&block) ⇒ Object
-
#initialize(white_list, attributes, context) ⇒ Config
constructor
A new instance of Config.
-
#replace_vars(string, context) ⇒ Object
replace vars in the string with a symbolized key of the same name in the context.
Constructor Details
#initialize(white_list, attributes, context) ⇒ Config
Returns a new instance of Config.
5 6 7 8 9 10 11 |
# File 'lib/model_formatting/config.rb', line 5 def initialize(white_list, attributes, context) @before_callback = nil @after_callback = nil @white_list = white_list @attributes = attributes @context = context end |
Instance Attribute Details
#after_callback ⇒ Object (readonly)
Returns the value of attribute after_callback.
3 4 5 |
# File 'lib/model_formatting/config.rb', line 3 def after_callback @after_callback end |
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
3 4 5 |
# File 'lib/model_formatting/config.rb', line 3 def attributes @attributes end |
#before_callback ⇒ Object (readonly)
Returns the value of attribute before_callback.
3 4 5 |
# File 'lib/model_formatting/config.rb', line 3 def before_callback @before_callback end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
3 4 5 |
# File 'lib/model_formatting/config.rb', line 3 def context @context end |
#white_list ⇒ Object (readonly)
Returns the value of attribute white_list.
3 4 5 |
# File 'lib/model_formatting/config.rb', line 3 def white_list @white_list end |
Instance Method Details
#after(&block) ⇒ Object
17 18 19 |
# File 'lib/model_formatting/config.rb', line 17 def after(&block) @after_callback = block end |
#before(&block) ⇒ Object
13 14 15 |
# File 'lib/model_formatting/config.rb', line 13 def before(&block) @before_callback = block end |
#replace_vars(string, context) ⇒ Object
replace vars in the string with a symbolized key of the same name in the context.
22 23 24 |
# File 'lib/model_formatting/config.rb', line 22 def replace_vars(string, context) string.gsub!(/:([a-z_]+)/) { |m| $1 && $1.size > 0 && context[$1.to_sym] }; string end |