Class: Associationist::Mixin
- Inherits:
-
Module
- Object
- Module
- Associationist::Mixin
- Defined in:
- lib/associationist/mixin.rb
Instance Method Summary collapse
- #included(base) ⇒ Object
-
#initialize(raw_config) ⇒ Mixin
constructor
A new instance of Mixin.
- #inspect ⇒ Object
Constructor Details
#initialize(raw_config) ⇒ Mixin
Returns a new instance of Mixin.
3 4 5 |
# File 'lib/associationist/mixin.rb', line 3 def initialize raw_config @raw_config = raw_config end |
Instance Method Details
#included(base) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/associationist/mixin.rb', line 7 def included base config = Config.new @raw_config config.check = {associationist: config} case config.type when :singular reflection = Builder::SingularAssociation.build(base, config.name, nil, ) when :collection reflection = Builder::CollectionAssociation.build(base, config.name, nil, ) else raise "unknown type #{config.type.inspect}" end ::ActiveRecord::Reflection.add_reflection base, config.name, reflection end |
#inspect ⇒ Object
24 25 26 |
# File 'lib/associationist/mixin.rb', line 24 def inspect "#<Associationist::Mixin @name=#{@raw_config[:name].inspect}>" end |