module Onceler::BasicHelpers::ClassMethods
Attributes
onceler_connections[W]
Set this if you have multiple (or different) conns you will be once-ler'ing. Can either be an enumerable, or a proc that returns one. Note that if given a proc, it will only be called once (the first time it's needed) and cached after that.
context “Foo” do
self.onceler_connections = -> { [Foo.connection] } ...
Public Instance Methods
after(*args, &block)
click to toggle source
Calls superclass method
# File lib/onceler/basic_helpers.rb, line 80 def after(*args, &block) scope = args.first case scope when :record, :reset onceler(:create).hooks[:after][scope] << block else super end end
around(*args, &block)
click to toggle source
Calls superclass method
# File lib/onceler/basic_helpers.rb, line 90 def around(*args, &block) scope = args.first case scope when *once_scopes around_once(&block) when :once_and_each around_once(&block) around(:each, &block) else super(*args, &block) end end
around_once(&block)
click to toggle source
# File lib/onceler/basic_helpers.rb, line 31 def around_once(&block) onceler(:create).add_around(block) add_onceler_hooks! end
before(*args, &block)
click to toggle source
Calls superclass method
# File lib/onceler/basic_helpers.rb, line 68 def before(*args, &block) scope = args.first case scope when :record, :reset onceler(:create).hooks[:before][scope] << block when *once_scopes before_once(&block) else super(*args, &block) end end
before_once(&block)
click to toggle source
# File lib/onceler/basic_helpers.rb, line 36 def before_once(&block) onceler(:create) << block add_onceler_hooks! end
let_once(name, &block)
click to toggle source
# File lib/onceler/basic_helpers.rb, line 15 def let_once(name, &block) raise ArgumentError, "wrong number of arguments (0 for 1)" if name.nil? raise "#let or #subject called without a block" if block.nil? onceler(:create)[name] = block add_onceler_hooks! @current_let_once = name define_method(name) { onceler[name] } end
once_scopes()
click to toggle source
# File lib/onceler/basic_helpers.rb, line 41 def once_scopes [:once] end
onceler(create_own = false)
click to toggle source
# File lib/onceler/basic_helpers.rb, line 103 def onceler(create_own = false) if create_own @onceler ||= Recorder.new(self) else @onceler || parent_onceler end end
onceler_connections()
click to toggle source
# File lib/onceler/basic_helpers.rb, line 125 def onceler_connections @onceler_connections ||= [ActiveRecord::Base.connection] @onceler_connections = instance_eval(&@onceler_connections) if @onceler_connections.respond_to?(:call) @onceler_connections end
parent_onceler()
click to toggle source
# File lib/onceler/basic_helpers.rb, line 111 def parent_onceler return unless superclass.respond_to?(:onceler) superclass.onceler end
subject_once(name = nil, &block)
click to toggle source
TODO NamedSubjectPreventSuper
# File lib/onceler/basic_helpers.rb, line 25 def subject_once(name = nil, &block) name ||= :subject let_once(name, &block) alias_method :subject, name if name != :subject end
Private Instance Methods
add_onceler_hooks!()
click to toggle source
# File lib/onceler/basic_helpers.rb, line 133 def add_onceler_hooks! return if @onceler_hooks_added @onceler_hooks_added = true before(:all) do |group| group.onceler.record! end after(:all) do |group| group.onceler.reset! end group_class = self prepend_before(:each) do group_class.onceler.replay_into!(self) end end
onceler!()
click to toggle source
# File lib/onceler/basic_helpers.rb, line 151 def onceler! extend AmbitiousHelpers end