Class: CheeseCloth::Wrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/cheesecloth/wrapper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass) ⇒ Wrapper

Returns a new instance of Wrapper.



6
7
8
9
# File 'lib/cheesecloth/wrapper.rb', line 6

def initialize(klass)
  @klass = klass
  @filter_list = FilterList.new(klass)
end

Instance Attribute Details

#default_scope_procObject (readonly)

Returns the value of attribute default_scope_proc.



4
5
6
# File 'lib/cheesecloth/wrapper.rb', line 4

def default_scope_proc
  @default_scope_proc
end

#filter_listObject (readonly)

Returns the value of attribute filter_list.



4
5
6
# File 'lib/cheesecloth/wrapper.rb', line 4

def filter_list
  @filter_list
end

#klassObject (readonly)

Returns the value of attribute klass.



4
5
6
# File 'lib/cheesecloth/wrapper.rb', line 4

def klass
  @klass
end

#scopeObject (readonly)

Returns the value of attribute scope.



4
5
6
# File 'lib/cheesecloth/wrapper.rb', line 4

def scope
  @scope
end

Instance Method Details

#assign_and_check_scope(instance) ⇒ Object

Raises:



20
21
22
23
# File 'lib/cheesecloth/wrapper.rb', line 20

def assign_and_check_scope(instance)
  @scope ||= default_scope_proc && default_scope_proc.call
  raise MissingScopeError, self.class unless instance.scope
end

#assign_default_scope_proc(block) ⇒ Object



11
12
13
# File 'lib/cheesecloth/wrapper.rb', line 11

def assign_default_scope_proc(block)
  @default_scope_proc = block
end

#prepare_and_run(instance) ⇒ Object



15
16
17
18
# File 'lib/cheesecloth/wrapper.rb', line 15

def prepare_and_run(instance)
  assign_and_check_scope(instance)
  run(instance)
end

#run(instance) ⇒ Object



25
26
27
# File 'lib/cheesecloth/wrapper.rb', line 25

def run(instance)
  filter_list.run_filters(instance)
end