Module: Dome::ViewMethods
- Defined in:
- lib/dome/view_methods.rb
Instance Method Summary collapse
-
#exhibit(thing, by: nil, to: dome_view_context) ⇒ Object
exhibit(@one) exhibit(@one, by: SomeEx).
-
#exhibit_enum(things, by: nil, to: dome_view_context) ⇒ Object
exhibit_enum(@ones) exhibit_enum(@ones, by: SomeEx).
-
#present(name, *vals, to: dome_view_context) ⇒ Object
present(:pair, @one, @two).
Instance Method Details
#exhibit(thing, by: nil, to: dome_view_context) ⇒ Object
exhibit(@one) exhibit(@one, by: SomeEx)
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/dome/view_methods.rb', line 23 def exhibit(thing, by: nil, to: dome_view_context) klass = by || begin class_name = "#{thing.class.name}Exhibit" klass = class_name.safe_constantize klass || raise( Dome::ExhibitClassNotFound, "Exhibit class '#{class_name}' for '#{thing.inspect}' not found." ) end exhibited = klass.new(thing) exhibited.instance_variable_set("@view_context", to) exhibited end |
#exhibit_enum(things, by: nil, to: dome_view_context) ⇒ Object
exhibit_enum(@ones) exhibit_enum(@ones, by: SomeEx)
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/dome/view_methods.rb', line 40 def exhibit_enum(things, by: nil, to: dome_view_context) klass = by || begin class_name = "#{things.first.class.name}Exhibit" klass = class_name.safe_constantize klass || raise( Dome::ExhibitClassNotFound, "Exhibit class '#{class_name}' for '#{things.first.inspect}' not found." ) end exhibited_enum = things.map do |x| exhibited = klass.new(x) exhibited.instance_variable_set("@view_context", to) exhibited end exhibited_enum end |
#present(name, *vals, to: dome_view_context) ⇒ Object
present(:pair, @one, @two)
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/dome/view_methods.rb', line 8 def present(name, *vals, to: dome_view_context) class_name = "#{name.to_s.camelize}Presenter" klass = class_name.safe_constantize klass || raise( Dome::PresenterClassNotFound, "Presenter class '#{class_name}' for '#{name}' not found." ) presented = klass.new(*vals) presented.instance_variable_set("@view_context", to) presented end |