class Easyrb::Context

Attributes

helpers[R]
#

Declarations #

#

Public Class Methods

[](context, helpers) click to toggle source
#

Class Methods #

#
# File lib/easyrb/context.rb, line 30
def self.[](context, helpers)
  new(context, helpers).generate_context
end
new(context, helpers) click to toggle source
#

Constructor #

#
# File lib/easyrb/context.rb, line 19
def initialize(context, helpers)
  @context = context
  @helpers = Array(helpers)
end

Public Instance Methods

generate_context() click to toggle source
#

Instance Methods #

#
# File lib/easyrb/context.rb, line 40
def generate_context
  context.tap do |obj|
    helpers.each do |mod|
      obj.extend(mod)
    end
  end
end

Private Instance Methods

bare_context() click to toggle source
# File lib/easyrb/context.rb, line 50
def bare_context
  @context
end
context() click to toggle source
# File lib/easyrb/context.rb, line 54
def context
  delegated_context || bare_context || Object.new
end
delegated_context() click to toggle source
# File lib/easyrb/context.rb, line 58
def delegated_context
  SimpleDelegator.new(bare_context) if bare_context && helpers.any?
end