Class: Safer::IVarFactory::Dsl

Inherits:
Object
  • Object
show all
Defined in:
lib/safer/ivarfactory/dsl.rb

Overview

Present a lightweight interface to instance variable creation. An instance of this class is given to the user as an argument to the yield block passed to Safer::IVarFactory#run. For example:

class Foo
  Safer::IVar.run(self) do |ivar|
    # ivar is an instance of Safer::IVarFactory::Dsl
  end
end

Instance Method Summary collapse

Constructor Details

#initialize(factory, klass) ⇒ Dsl

Initialize a DSL object.

factory

IVarFactory to use for creating instance variables.

klass

+klass argument to Safer::IVarFactory#run; create instance variables in this class.



16
17
18
19
20
# File 'lib/safer/ivarfactory/dsl.rb', line 16

def initialize(factory, klass)
  @factory = factory
  @klass = klass
  @symbol_prefix = factory.class_symbol_prefix(klass)
end

Instance Method Details

#accessor(*args) ⇒ Object

Export accessors for Safer::IVarFactory instance variables in the class attached to this DSL object. See Safer::IVarFactory#export_reader



46
47
48
# File 'lib/safer/ivarfactory/dsl.rb', line 46

def accessor(*args)
  @factory._export_accessor_internal(@klass, @symbol_prefix, args)
end

#ivar(*args) ⇒ Object

Define Safer::IVarFactory instance variables for the class attached to this DSL object. See Safer::IVarFactory#instance_variable



25
26
27
# File 'lib/safer/ivarfactory/dsl.rb', line 25

def ivar(*args)
  @factory._instance_variable_internal(@klass, @symbol_prefix, args)
end

#reader(*args) ⇒ Object

Export readers for Safer::IVarFactory instance variables in the class attached to this DSL object. See Safer::IVarFactory#export_reader



32
33
34
# File 'lib/safer/ivarfactory/dsl.rb', line 32

def reader(*args)
  @factory._export_reader_internal(@klass, @symbol_prefix, args)
end

#writer(*args) ⇒ Object

Export writers for Safer::IVarFactory instance variables in the class attached to this DSL object. See Safer::IVarFactory#export_reader



39
40
41
# File 'lib/safer/ivarfactory/dsl.rb', line 39

def writer(*args)
  @factory._export_writer_internal(@klass, @symbol_prefix, args)
end