Class: DynamicActiveModel::ForeignKey
- Inherits:
- 
      Object
      
        - Object
- DynamicActiveModel::ForeignKey
 
- Defined in:
- lib/dynamic-active-model/foreign_key.rb
Overview
DynamicActiveModel::ForeignKey tracks foreign keys related to the model
Constant Summary collapse
- DEFAULT_ID_SUFFIX =
- '_id'
Instance Attribute Summary collapse
- 
  
    
      #keys  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute keys. 
- 
  
    
      #model  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute model. 
Class Method Summary collapse
- .id_suffix ⇒ Object
- 
  
    
      .id_suffix=(val)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    rubocop:disable Style/TrivialAccessors. 
Instance Method Summary collapse
- #add(key, relationship_name = nil) ⇒ Object
- #generate_foreign_key(table_name) ⇒ Object
- 
  
    
      #initialize(model)  ⇒ ForeignKey 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    rubocop:enable Style/TrivialAccessors. 
Constructor Details
#initialize(model) ⇒ ForeignKey
rubocop:enable Style/TrivialAccessors
| 21 22 23 24 25 | # File 'lib/dynamic-active-model/foreign_key.rb', line 21 def initialize(model) @model = model @keys = {} add(generate_foreign_key(model.table_name)) end | 
Instance Attribute Details
#keys ⇒ Object (readonly)
Returns the value of attribute keys.
| 6 7 8 | # File 'lib/dynamic-active-model/foreign_key.rb', line 6 def keys @keys end | 
#model ⇒ Object (readonly)
Returns the value of attribute model.
| 6 7 8 | # File 'lib/dynamic-active-model/foreign_key.rb', line 6 def model @model end | 
Class Method Details
.id_suffix ⇒ Object
| 11 12 13 | # File 'lib/dynamic-active-model/foreign_key.rb', line 11 def self.id_suffix @id_suffix || DEFAULT_ID_SUFFIX end | 
.id_suffix=(val) ⇒ Object
rubocop:disable Style/TrivialAccessors
| 16 17 18 | # File 'lib/dynamic-active-model/foreign_key.rb', line 16 def self.id_suffix=(val) @id_suffix = val end | 
Instance Method Details
#add(key, relationship_name = nil) ⇒ Object
| 27 28 29 | # File 'lib/dynamic-active-model/foreign_key.rb', line 27 def add(key, relationship_name = nil) @keys[key] = relationship_name || model.table_name.underscore end | 
#generate_foreign_key(table_name) ⇒ Object
| 31 32 33 | # File 'lib/dynamic-active-model/foreign_key.rb', line 31 def generate_foreign_key(table_name) table_name.underscore.singularize + self.class.id_suffix end |