Module: EdgeRider::Util

Extended by:
Util
Included in:
Util
Defined in:
lib/edge_rider/util.rb

Instance Method Summary collapse

Instance Method Details

#active_record_versionObject



34
35
36
# File 'lib/edge_rider/util.rb', line 34

def active_record_version
  ActiveRecord::VERSION::MAJOR
end

#define_association(owner, association, target, options) ⇒ Object



28
29
30
31
32
# File 'lib/edge_rider/util.rb', line 28

def define_association(owner, association, target, options)
  conditions = options.extract!(:conditions)
  scope = lambda { |*args| scoped(conditions) }
  owner.send association, target, scope, **options
end

#define_scope(klass, name, lambda) ⇒ Object



21
22
23
24
25
26
# File 'lib/edge_rider/util.rb', line 21

def define_scope(klass, name, lambda)
  klass.send :scope, name, lambda { |*args|
    options = lambda.call(*args)
    scoped(options.slice :conditions) 
  }
end

#exclusive_query(model, conditions) ⇒ Object



13
14
15
# File 'lib/edge_rider/util.rb', line 13

def exclusive_query(model, conditions)
  model.unscoped.where(conditions)
end

#qualify_column_name(model, column_name) ⇒ Object



7
8
9
10
11
# File 'lib/edge_rider/util.rb', line 7

def qualify_column_name(model, column_name)
  column_name = column_name.to_s
  column_name = "#{model.table_name}.#{column_name}" unless column_name.include?('.')
  column_name
end

#rspec_pathObject



55
56
57
58
59
60
61
# File 'lib/edge_rider/util.rb', line 55

def rspec_path
  if rspec_version == 1
    'spec'
  else
    'rspec'
  end
end

#rspec_rootObject



47
48
49
50
51
52
53
# File 'lib/edge_rider/util.rb', line 47

def rspec_root
  if rspec_version == 1
    Spec
  else
    RSpec
  end
end

#rspec_versionObject



38
39
40
41
42
43
44
45
# File 'lib/edge_rider/util.rb', line 38

def rspec_version
  if defined?(Spec)
    1
  else
    require 'rspec/version'
    RSpec::Version::STRING.to_i
  end
end

#scope?(object) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/edge_rider/util.rb', line 17

def scope?(object)
  object.respond_to?(:scoped)
end