Class: Friendly::ScopeProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/friendly/scope_proxy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, scope_klass = Scope) ⇒ ScopeProxy

Returns a new instance of ScopeProxy.



5
6
7
8
9
# File 'lib/friendly/scope_proxy.rb', line 5

def initialize(klass, scope_klass = Scope)
  @klass       = klass
  @scope_klass = scope_klass
  @scopes      = {}
end

Instance Attribute Details

#klassObject (readonly)

Returns the value of attribute klass.



3
4
5
# File 'lib/friendly/scope_proxy.rb', line 3

def klass
  @klass
end

#scope_klassObject (readonly)

Returns the value of attribute scope_klass.



3
4
5
# File 'lib/friendly/scope_proxy.rb', line 3

def scope_klass
  @scope_klass
end

#scopesObject (readonly)

Returns the value of attribute scopes.



3
4
5
# File 'lib/friendly/scope_proxy.rb', line 3

def scopes
  @scopes
end

Instance Method Details

#ad_hoc(parameters) ⇒ Object



24
25
26
# File 'lib/friendly/scope_proxy.rb', line 24

def ad_hoc(parameters)
  scope_klass.new(klass, parameters)
end

#add_named(name, parameters) ⇒ Object



11
12
13
14
# File 'lib/friendly/scope_proxy.rb', line 11

def add_named(name, parameters)
  scopes[name] = parameters
  add_scope_method_to_klass(name)
end

#get(name) ⇒ Object



16
17
18
# File 'lib/friendly/scope_proxy.rb', line 16

def get(name)
  scopes[name]
end

#get_instance(name) ⇒ Object



20
21
22
# File 'lib/friendly/scope_proxy.rb', line 20

def get_instance(name)
  scope_klass.new(klass, get(name))
end

#has_named_scope?(name) ⇒ Boolean

Returns:



28
29
30
# File 'lib/friendly/scope_proxy.rb', line 28

def has_named_scope?(name)
  scopes.has_key?(name)
end