Class: WhereLower::ScopeSpawner

Inherits:
Object
  • Object
show all
Defined in:
lib/where_lower/scope_spawner.rb

Overview

:nodoc:

Direct Known Subclasses

BasicScopeSpawner

Defined Under Namespace

Classes: ArrayScopeSpawner, BasicScopeSpawner, EqualScopeSpawner, HashScopeSpawner, RangeScopeSpawner, StringScopeSpawner

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scope, column_or_table_name, value, prefix = nil) ⇒ ScopeSpawner

Assign ivar only Actual operation is in #spawn

Parameters:

  • scope (ActiveRecord::Relation)

    Relation or collection proxy or some AR classes

  • column_or_table_name (Symbol, String)

    when column name, the actual column name (not attribute name) when table name, the actual table name (not class name converted to underscore)

  • value (Object)

    value to compare to, also determine what scope spawner to be used

  • prefix (Symbol, String) (defaults to: nil)

    used internally for specifying a scope with prefix (table name)

See Also:



31
32
33
34
35
36
# File 'lib/where_lower/scope_spawner.rb', line 31

def initialize(scope, column_or_table_name, value, prefix = nil)
  @scope                = scope
  @column_or_table_name = column_or_table_name
  @value                = value
  @prefix               = prefix
end

Instance Attribute Details

#column_or_table_nameObject (readonly)

:nodoc:



5
6
7
# File 'lib/where_lower/scope_spawner.rb', line 5

def column_or_table_name
  @column_or_table_name
end

#prefixObject (readonly)

:nodoc:



5
6
7
# File 'lib/where_lower/scope_spawner.rb', line 5

def prefix
  @prefix
end

#scopeObject (readonly)

:nodoc:



5
6
7
# File 'lib/where_lower/scope_spawner.rb', line 5

def scope
  @scope
end

#valueObject (readonly)

:nodoc:



5
6
7
# File 'lib/where_lower/scope_spawner.rb', line 5

def value
  @value
end

Class Method Details

.spawn(*args) ⇒ Object

Spawn different scopes based on value Just delegates to new though

Parameters:

  • args (Array)

    arguments that are passed to #initialize

See Also:



13
14
15
# File 'lib/where_lower/scope_spawner.rb', line 13

def self.spawn(*args)
  new(*args).spawn
end

Instance Method Details

#spawnActiveRecord::Relation

Spawn different scopes based on value Data conversion and query string generation are handled by different spanwer classes

Returns:

  • (ActiveRecord::Relation)

    Relation or collection proxy or some AR classs



42
43
44
45
# File 'lib/where_lower/scope_spawner.rb', line 42

def spawn
  CLASS_TO_SPAWNER_CLASS_MAPPINGS[value.class].
    spawn(*scope_arguments)
end