Module: Fathom::ContextBehavior::ClassMethods

Defined in:
lib/fathom/behaviors/context_behavior.rb

Instance Method Summary collapse

Instance Method Details

#default_class(value = nil) ⇒ Object



6
7
8
9
# File 'lib/fathom/behaviors/context_behavior.rb', line 6

def default_class(value=nil)
  @default_class = value if value
  @default_class
end

#new(*attrs, &block) ⇒ Object

Raises:

  • (ArgumentError)


11
12
13
14
15
16
17
18
# File 'lib/fathom/behaviors/context_behavior.rb', line 11

def new(*attrs, &block)
  target = attrs.shift
  target ||= default_class.new if default_class
  raise ArgumentError, "You must provide a target object to build this context." unless target
  obj = super(*attrs, &block)
  obj.send(:instance_variable_set, :@object, target)
  obj
end