title: Handling conditions at class level based on association
body: <p>I'm not sure how to frame this question, I am looking to solve a design problem.</p>
  
  <p>I'm using ActiveRecord.</p>
  
  <p>An <code>Agency</code> can have multiple <code>documents</code>.</p>
  
  <p><code>documents</code> has a column <code>additional_details</code> of type <code>jsonb</code>. Contains hash details.</p>
  
  <p><code>additional_details</code> column has different set of key value pair based on <code>agency</code>.</p>
  
  <p>Example:</p>
  
  <pre><code>doc1 = agency1.documents.first.additional_details =&gt; { xml_url: '', ... }
  doc2 = agency2.documents.first.additional_details =&gt; { feed_url1: '', ... }
  </code></pre>
  
  <p>agency1 and agency2 are instance objects of Agency.</p>
  
  <hr/>
  
  <p>When I make a call to fetch the url like <strong><code>document.additional_details.get_url</code></strong></p>
  
  <p>I can write conditions like</p>
  
  <pre><code>def get_url
    if agency1.name == 'Utah'
      return additional_details[xml_url]
    elsif 
      so on
    elsif
      so on
    end
  end
  </code></pre>
  
  <p>Which is not a good practice I feel.</p>
  
  <p>I believe we can solve this at class level. Note I need to solve this on presentation layer, I'm using decorators .</p>
  
  <p>Edit:</p>
  
  <p>An particular agency will have same keys within additional_details column but values are certainly different.</p>