Class: HumanAttributes::MethodBuilder
- Inherits:
-
Object
- Object
- HumanAttributes::MethodBuilder
- Includes:
- Config
- Defined in:
- lib/human_attributes/method_builder.rb
Constant Summary
Constants included from Config
Instance Attribute Summary collapse
-
#model_class ⇒ Object
readonly
Returns the value of attribute model_class.
Instance Method Summary collapse
- #build(formatter) ⇒ Object
-
#initialize(model_class) ⇒ MethodBuilder
constructor
A new instance of MethodBuilder.
Methods included from Config
#category_by_type, #formatter_by_type, #known_type?, #raise_error, #suffix_by_type, #type_config
Constructor Details
#initialize(model_class) ⇒ MethodBuilder
Returns a new instance of MethodBuilder.
7 8 9 |
# File 'lib/human_attributes/method_builder.rb', line 7 def initialize(model_class) @model_class = model_class end |
Instance Attribute Details
#model_class ⇒ Object (readonly)
Returns the value of attribute model_class.
5 6 7 |
# File 'lib/human_attributes/method_builder.rb', line 5 def model_class @model_class end |
Instance Method Details
#build(formatter) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/human_attributes/method_builder.rb', line 11 def build(formatter) model_class.send(:define_method, formatter.method_name) do value = send(formatter.attribute) || formatter.default formatter.apply(self, value) end formatter.method_name end |