Module: Harbor::AccessorInjector

Included in:
Plugin
Defined in:
lib/harbor/accessor_injector.rb

Overview

A simple module to facilitate accessor based injection. This is used by Harbor::Plugin to allow you to easily construct plugins from hashes, i.e.:

<%= plugin("user/tabs", :user => @user)

It can of course be used for anything, however:

class Dog
  include Harbor::AccessorInjector
  attr_accessor :owner
end

dog = Dog.new.inject(:owner => "Tom")
dog.owner # => "Tom"

Instance Method Summary collapse

Instance Method Details

#inject(options = {}) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/harbor/accessor_injector.rb', line 20

def inject(options = {})
  options.each do |key, value|
    setter = "#{key}="
    send(setter, value) if respond_to?(setter)
  end

  self
end