Sha256: b78abbd94ef66a7244b448b9b57ab74f2dfdbfd486e36651d680e623892dec71

Contents?: true

Size: 1.52 KB

Versions: 18

Compression:

Stored size: 1.52 KB

Contents

module Rally
  module ParsingHelperClassMethods
    def node_name
      if self.to_s == "Story"
        "HierarchicalRequirement"
      else
        self.to_s
      end
    end

    def from_uri(uri)
      obj = first(:conditions => {:rally_uri => uri}) || new(:rally_uri => uri)
      obj.refresh
    end

    def rally_query options={}
      RallyAPI.all(self, options)
    end
  end

  module ParsingHelpers
    def raw_json options = {}
      options[:refresh] = options[:refresh] || false

      unless self.rally_uri
        raise "Could not fetch resource"
      end
      
      if @rally_hash
        return @rally_hash 
      else
        @rally_hash = get_fields_from_rally
      end
  
      @rally_hash
  
    end
  
    private

    def get_fields_from_rally
      rally_hash = RallyAPI.get(self)
      
      #special case for heirarchical_requirements
      if rally_hash.has_key? "HierarchicalRequirement"
        rally_hash = rally_hash["HierarchicalRequirement"]
      end

      rally_hash
    end

    #next 3 are for mapping from rally to mongo
    def from_rally attr, key=nil
      key = key || attr.capitalize
      self.send("#{attr.to_s}=", raw_json[key.to_s])
    end

    def parse_refs key, rally_objects
      if self.respond_to?(key) && !rally_objects.nil?
        self.send("#{key.to_s}=", rally_objects.collect{|i| i["_ref"]})
      end
    end
  
    def parse_ref key, rally_object  
      if self.respond_to?(key) && !rally_object.nil?
        self.send("#{key.to_s}=", rally_object["_ref"])
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
rallytastic-1.4.6 lib/rally/parsing_helpers.rb
rallytastic-1.4.5 lib/rally/parsing_helpers.rb
rallytastic-1.4.4 lib/rally/parsing_helpers.rb
rallytastic-1.4.0 lib/rally/parsing_helpers.rb
rallytastic-1.3.0 lib/rally/parsing_helpers.rb
rallytastic-1.2.8 lib/rally/parsing_helpers.rb
rallytastic-1.2.7 lib/rally/parsing_helpers.rb
rallytastic-1.2.6 lib/rally/parsing_helpers.rb
rallytastic-1.2.5 lib/rally/parsing_helpers.rb
rallytastic-1.2.4 lib/rally/parsing_helpers.rb
rallytastic-1.2.3 lib/rally/parsing_helpers.rb
rallytastic-1.2.2 lib/rally/parsing_helpers.rb
rallytastic-1.2.1 lib/rally/parsing_helpers.rb
rallytastic-1.2.0 lib/rally/parsing_helpers.rb
rallytastic-1.1.2 lib/rally/parsing_helpers.rb
rallytastic-1.1.1 lib/rally/parsing_helpers.rb
rallytastic-1.1.0 lib/rally/parsing_helpers.rb
rallytastic-1.0.0 lib/rally/parsing_helpers.rb