class Fixture
Constants
- FIXTURE_DIR
- FIXTURE_FILE
Public Class Methods
assigneds()
click to toggle source
# File lib/fixture/fixture.rb, line 33 def assigneds @@assigneds ||= {} end
candidates()
click to toggle source
# File lib/fixture/fixture.rb, line 37 def candidates @@candidates ||= {} end
get( name )
click to toggle source
# File lib/fixture/fixture.rb, line 29 def get( name ) assigneds[name] end
load()
click to toggle source
# File lib/fixture/fixture.rb, line 41 def load prepare unless prepared? candidates.each do |name, candidate| candidate[:attributes].each do |attr, val| candidate[:obj].send("#{attr}=", val.is_a?(Proc) ? val.call : val) end assigneds[name] = obj = candidate[:obj] if obj.respond_to? :save! obj.save! elsif obj.respond_to? :save obj.save end end end
manage( klass, &block )
click to toggle source
# File lib/fixture/fixture.rb, line 25 def manage( klass, &block ) self.new(klass).instance_eval &block end
new(klass)
click to toggle source
# File lib/fixture/fixture.rb, line 2 def initialize(klass) @klass = klass end
prepare()
click to toggle source
# File lib/fixture/fixture.rb, line 59 def prepare %w(spec test).each do |dir| require "#{dir}/#{FIXTURE_FILE}" if File.exists? "#{dir}/#{FIXTURE_FILE}" Dir["#{dir}/#{FIXTURE_DIR}/*.rb"].each {|f| require f } end @@prepared = true end
prepared?()
click to toggle source
# File lib/fixture/fixture.rb, line 67 def prepared? !!@@prepared end
Public Instance Methods
assign( name ) { || ... }
click to toggle source
# File lib/fixture/fixture.rb, line 6 def assign( name, &block ) self.class.candidates[name] = @candidate = { obj: @klass.new, attributes: {} } yield end
attribute( name, *args, &block)
click to toggle source
# File lib/fixture/fixture.rb, line 11 def attribute( name, *args, &block) val = args.first val = block if block_given? @candidate[:attributes][name] = val end
Also aliased as: method_missing