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 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/fortitude/support/staticized_method.rb', line 30 def create_method! begin .instance_method(method_name) rescue NameError => ne raise NameError, %{You declared the method #{method_name.inspect} in class #{.name.inspect} to be a Fortitude static content method, but there is no method declared on this class with that name. (It's possible you simply tried to declare the method static before it was defined on that class -- the call to 'static' must come _after_ the definition of the method in the class's source code.)} end 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 |