Permalink
Browse files

Performance Improvements

  • Loading branch information...
1 parent 04d09f6 commit e11e4488dd34ceb702c22e417471870d6a7fd324 @raphaelcm raphaelcm committed Jan 21, 2014
View
4 Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
- tangocard (0.2.2)
+ tangocard (2.0.0)
httparty (~> 0.11.0)
money (~> 5.1.1)
@@ -15,7 +15,7 @@ GEM
i18n (0.6.5)
money (5.1.1)
i18n (~> 0.6.0)
- multi_json (1.8.0)
+ multi_json (1.8.2)
multi_xml (0.5.5)
rr (1.1.2)
rspec (2.14.1)
View
12 lib/tangocard/brand.rb
@@ -1,5 +1,9 @@
class Tangocard::Brand
attr_reader :description, :rewards
+ @@result = nil
+ @@brands = nil
+ @@default_brands = nil
+ @@brand_finder = {}
# Return an array of all brands.
#
@@ -10,8 +14,8 @@ class Tangocard::Brand
# Arguments:
# none
def self.all
- result = Tangocard::Raas.rewards_index.parsed_response
- result['brands'].map{|p| Tangocard::Brand.new(p)}
+ @@result ||= Tangocard::Raas.rewards_index.parsed_response
+ @@brands ||= @@result['brands'].map{|p| Tangocard::Brand.new(p)}
end
# Return an array of default brands. Must set default_brands in your Tangocard initializer (see README).
@@ -23,7 +27,7 @@ def self.all
# Arguments:
# none
def self.default_brands
- self.all.select{|b| Tangocard.configuration.default_brands.include?(b.description)}
+ @@default_brands ||= self.all.select{|b| Tangocard.configuration.default_brands.include?(b.description)}
end
# Find a brand by its :description field.
@@ -39,7 +43,7 @@ def self.default_brands
# Arguments:
# brand_name: (String)
def self.find(brand_name)
- self.all.select{|b| b.description == brand_name}.first
+ @@brand_finder[brand_name] ||= self.all.select{|b| b.description == brand_name}.first
end
def initialize(params)
View
13 lib/tangocard/response.rb
@@ -1,16 +1,9 @@
class Tangocard::Response
- attr_reader :raw_response
+ attr_reader :parsed_response, :code
def initialize(raw_response)
- @raw_response = raw_response
- end
-
- def parsed_response
- raw_response.parsed_response
- end
-
- def code
- raw_response.code
+ @parsed_response = raw_response.parsed_response
+ @code = raw_response.code
end
def success?
View
2 lib/tangocard/version.rb
@@ -1,3 +1,3 @@
module Tangocard
- VERSION = "1.0.0"
+ VERSION = "2.0.0"
end
View
2 spec/lib/tangocard/brand_spec.rb
@@ -6,7 +6,7 @@
describe "class methods" do
describe "self.all" do
before do
- mock(Tangocard::Raas).rewards_index.mock!.parsed_response { sample_parsed_response }
+ stub(Tangocard::Raas).rewards_index.stub!.parsed_response { sample_parsed_response }
end
it "should return an array of Tangocard::Brand objects" do
View
15 spec/lib/tangocard/response_spec.rb
@@ -12,21 +12,8 @@
end
describe "inialize" do
- it "should set the raw_response ivar on initialize" do
- @response.raw_response.should == raw_response
- end
- end
-
- describe "parsed_response" do
- it "should return the parsed response from the raw_response" do
- mock(raw_response).parsed_response { parsed_response }
+ it "should set the ivars on initialize" do
@response.parsed_response.should == parsed_response
- end
- end
-
- describe "code" do
- it "should return the code from the raw_response" do
- mock(raw_response).code { code }
@response.code.should == code
end
end

0 comments on commit e11e448

Please sign in to comment.