Class: Shaf::Spec::Fixture

Inherits:
Object
  • Object
show all
Includes:
Shaf::Spec::Fixtures::Accessors
Defined in:
lib/shaf/spec/fixture.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Shaf::Spec::Fixtures::Accessors

add, clear, collection

Constructor Details

#initialize(name, block) ⇒ Fixture

Returns a new instance of Fixture.



17
18
19
20
# File 'lib/shaf/spec/fixture.rb', line 17

def initialize(name, block)
  @name = name
  @block = block
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object (private)



35
36
37
38
# File 'lib/shaf/spec/fixture.rb', line 35

def method_missing(method, *args, &block)
  return super unless resource_name?(args.size, block_given?)
  add_entry(method, args.first, &block)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/shaf/spec/fixture.rb', line 10

def name
  @name
end

Class Method Details

.define(name, &block) ⇒ Object



12
13
14
15
# File 'lib/shaf/spec/fixture.rb', line 12

def self.define(name, &block)
  return unless block_given?
  Fixtures.fixture_defined new(name.to_sym, block)
end

Instance Method Details

#add_entry(entry_name, resrc = nil, &block) ⇒ Object



27
28
29
30
31
# File 'lib/shaf/spec/fixture.rb', line 27

def add_entry(entry_name, resrc = nil, &block)
  value = block ? instance_exec(&block) : resrc
  fixtures = send(name)
  fixtures[entry_name] = value
end

#initObject



22
23
24
25
# File 'lib/shaf/spec/fixture.rb', line 22

def init
  instance_exec(&@block)
  self
end