Module: Neo::Rails::Exposure
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/neo/rails/exposure.rb
Overview
A really simple version of exposing variables to the view. Bases on attr_reader and helper_method.
Defined Under Namespace
Modules: ClassMethods Classes: UndeclaredVariableError
Instance Method Summary collapse
-
#expose(key, value = nil) ⇒ Object
Expose an assign at the instance level.
Instance Method Details
#expose(key, value = nil) ⇒ Object
Expose an assign at the instance level.
If the value is given with a block, just execute the block if a value was not set yet.
Raise UndeclaredVariableError if access variable wasn’t declared before.
33 34 35 36 37 38 39 40 |
# File 'lib/neo/rails/exposure.rb', line 33 def expose(key, value=nil) name = key.to_sym raise UndeclaredVariableError unless self.class.exposed_vars.include?(name) value = yield if block_given? self.instance_variable_set("@#{name}", value) end |