Module: Sus::With
- Extended by:
- Context
- Defined in:
- lib/sus/with.rb
Instance Attribute Summary collapse
-
#subject ⇒ Object
Returns the value of attribute subject.
-
#variables ⇒ Object
Returns the value of attribute variables.
Attributes included from Context
#children, #description, #identity
Class Method Summary collapse
Instance Method Summary collapse
Methods included from Context
add, after, around, before, call, describe, each, empty?, extended, file, full_name, include_context, inspect, it, it_behaves_like, leaf?, let, set_temporary_name, to_s, with
Instance Attribute Details
#subject ⇒ Object
Returns the value of attribute subject.
12 13 14 |
# File 'lib/sus/with.rb', line 12 def subject @subject end |
#variables ⇒ Object
Returns the value of attribute variables.
13 14 15 |
# File 'lib/sus/with.rb', line 13 def variables @variables end |
Class Method Details
.build(parent, subject, variables, unique: true, &block) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/sus/with.rb', line 15 def self.build(parent, subject, variables, unique: true, &block) base = Class.new(parent) base.singleton_class.prepend(With) base.children = Hash.new base.subject = subject base.description = subject base.identity = Identity.nested(parent.identity, base.description, unique: unique) base.set_temporary_name("#{self}[#{base.description}]") base.variables = variables base.define_method(:description, ->{subject}) variables.each do |key, value| base.define_method(key, ->{value}) end if block_given? base.class_exec(&block) end return base end |
Instance Method Details
#print(output) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/sus/with.rb', line 39 def print(output) self.superclass.print(output) output.write( " with ", :with, self.description, :reset, # " ", :variables, self.variables.inspect ) end |