Module: ActiveRecordEx::ManyToMany::ClassMethods
- Defined in:
- lib/active-record-ex/many_to_many.rb
Instance Method Summary collapse
- #belongs_to(name, scope = nil, options = {}) ⇒ Object
- #has_many(name, scope = nil, options = {}, &extension) ⇒ Object
- #has_one(name, scope = nil, options = {}, &extension) ⇒ Object
- #set_scope_and_options(scope, options) ⇒ Object
- #singularize(method_name) ⇒ Object
Instance Method Details
#belongs_to(name, scope = nil, options = {}) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/active-record-ex/many_to_many.rb', line 37 def belongs_to(name, scope = nil, = {}) scope, = (scope, ) subtypes = .delete(:subtypes) if ActiveRecord::VERSION::MAJOR < 4 super(name, ) else super end define_belongs_assoc(name, .merge(subtypes: subtypes)) end |
#has_many(name, scope = nil, options = {}, &extension) ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/active-record-ex/many_to_many.rb', line 48 def has_many(name, scope = nil, = {}, &extension) scope, = (scope, ) if ActiveRecord::VERSION::MAJOR < 4 super(name, , &extension) else super end define_has_assoc(name.to_s.singularize, ) end |
#has_one(name, scope = nil, options = {}, &extension) ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/active-record-ex/many_to_many.rb', line 58 def has_one(name, scope = nil, = {}, &extension) scope, = (scope, ) if ActiveRecord::VERSION::MAJOR < 4 super(name, , &extension) else super end define_has_assoc(name.to_s, ) end |
#set_scope_and_options(scope, options) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/active-record-ex/many_to_many.rb', line 29 def (scope, ) if scope.is_a?(Hash) = scope scope = nil end [scope, ] end |
#singularize(method_name) ⇒ Object
68 69 70 71 72 |
# File 'lib/active-record-ex/many_to_many.rb', line 68 def singularize(method_name) define_method(method_name) do |*params| ModelArel.new(self).send(method_name, *params) end end |