Class: ModelFormatting::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/model_formatting/config.rb

Overview

Used to configure model formatting for a specific class. See ModelFormatting::Init

Instance Attribute Summary collapse

Instance Method Summary collapse

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_callbackObject (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

#attributesObject (readonly)

Returns the value of attribute attributes.



3
4
5
# File 'lib/model_formatting/config.rb', line 3

def attributes
  @attributes
end

#before_callbackObject (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

#contextObject (readonly)

Returns the value of attribute context.



3
4
5
# File 'lib/model_formatting/config.rb', line 3

def context
  @context
end

#white_listObject (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