Class: Fortitude::Support::StaticizedMethod
- Inherits:
-
Object
- Object
- Fortitude::Support::StaticizedMethod
- Defined in:
- lib/fortitude/support/staticized_method.rb
Instance Method Summary collapse
- #create_method! ⇒ Object
-
#initialize(widget_class, method_name, options = { }) ⇒ StaticizedMethod
constructor
A new instance of StaticizedMethod.
- #run!(widget) ⇒ Object
Constructor Details
#initialize(widget_class, method_name, options = { }) ⇒ StaticizedMethod
Returns a new instance of StaticizedMethod.
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/fortitude/support/staticized_method.rb', line 4 def initialize(, method_name, = { }) @widget_class = @method_name = method_name @output_by_locale = { } @has_yield = false @options = @options.assert_valid_keys(:locale_support) set_constant! end |
Instance Method Details
#create_method! ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/fortitude/support/staticized_method.rb', line 30 def create_method! unless .instance_methods.map(&:to_s).include?(dynamic_method_name.to_s) .send(:alias_method, dynamic_method_name, method_name) end .class_eval <<-EOS def #{method_name} #{constant_name}.run!(self) { yield } end EOS end |
#run!(widget) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/fortitude/support/staticized_method.rb', line 17 def run!() locale = locale_support? ? . : nil output = (@output_by_locale[locale] ||= generate_content!()) if output.kind_of?(Array) .rawtext(output[0]) yield .rawtext(output[1]) else .rawtext(output) end end |