Module: EdgeRider::Util
Instance Method Summary collapse
- #active_record_version ⇒ Object
- #define_association(owner, association, target, options) ⇒ Object
- #define_scope(klass, name, lambda) ⇒ Object
- #exclusive_query(model, conditions) ⇒ Object
- #qualify_column_name(model, column_name) ⇒ Object
- #rspec_path ⇒ Object
- #rspec_root ⇒ Object
- #rspec_version ⇒ Object
- #scope?(object) ⇒ Boolean
Instance Method Details
#active_record_version ⇒ Object
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, ) conditions = .extract!(:conditions) scope = lambda { |*args| scoped(conditions) } owner.send association, target, scope, ** 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| = lambda.call(*args) scoped(.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_path ⇒ Object
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_root ⇒ Object
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_version ⇒ Object
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
17 18 19 |
# File 'lib/edge_rider/util.rb', line 17 def scope?(object) object.respond_to?(:scoped) end |