Class: HelloSign::Resource::BaseResource
- Inherits:
- 
      Object
      
        - Object
- HelloSign::Resource::BaseResource
 
- Defined in:
- lib/hello_sign/resource/base_resource.rb
Overview
Stores the value of a hash. Use missing_method to create method to access it like an object
Direct Known Subclasses
Account, ApiApp, BulkSendJob, Embedded, SignatureRequest, Team, Template, TemplateDraft, UnclaimedDraft
Instance Attribute Summary collapse
- 
  
    
      #data  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute data. 
- 
  
    
      #headers  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute headers. 
- 
  
    
      #raw_data  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute raw_data. 
- 
  
    
      #warnings  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute warnings. 
Instance Method Summary collapse
- 
  
    
      #initialize(hash, key = nil)  ⇒ HelloSign::Resource::BaseResource 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    Converts hash data recursively into BaseResource. 
- 
  
    
      #method_missing(method)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Magic method, gives class dynamic methods based on hash keys. 
Constructor Details
#initialize(hash, key = nil) ⇒ HelloSign::Resource::BaseResource
Converts hash data recursively into BaseResource.
| 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | # File 'lib/hello_sign/resource/base_resource.rb', line 39 def initialize(hash, key=nil) @headers = hash[:headers] @raw_data = key ? hash[:body][key] : hash if hash[:body] @warnings = hash[:body]['warnings'] ? hash[:body]['warnings'] : nil end @data = @raw_data.inject({}) do |data, (key, value)| data[key.to_s] = if value.is_a? Hash value = BaseResource.new(value) elsif ((value.is_a? Array) && (value[0].is_a? Hash)) value = value.map {|v| BaseResource.new(v)} else value end data end end | 
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method) ⇒ Object
Magic method, gives class dynamic methods based on hash keys. If initialized hash has a key which matches the method name, return value of that key. Otherwise, return nil.
| 68 69 70 | # File 'lib/hello_sign/resource/base_resource.rb', line 68 def method_missing(method) @data.key?(method.to_s) ? @data[method.to_s] : nil end | 
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
| 31 32 33 | # File 'lib/hello_sign/resource/base_resource.rb', line 31 def data @data end | 
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
| 31 32 33 | # File 'lib/hello_sign/resource/base_resource.rb', line 31 def headers @headers end | 
#raw_data ⇒ Object (readonly)
Returns the value of attribute raw_data.
| 31 32 33 | # File 'lib/hello_sign/resource/base_resource.rb', line 31 def raw_data @raw_data end | 
#warnings ⇒ Object (readonly)
Returns the value of attribute warnings.
| 31 32 33 | # File 'lib/hello_sign/resource/base_resource.rb', line 31 def warnings @warnings end |