Merge pull request #8156 from samford/add-strategy-to-livecheck-dsl
Add strategy to livecheck DSL
This commit is contained in:
		
						commit
						b8bafe4e90
					
				@ -15,6 +15,7 @@ class Livecheck
 | 
				
			|||||||
    @regex = nil
 | 
					    @regex = nil
 | 
				
			||||||
    @skip = false
 | 
					    @skip = false
 | 
				
			||||||
    @skip_msg = nil
 | 
					    @skip_msg = nil
 | 
				
			||||||
 | 
					    @strategy = nil
 | 
				
			||||||
    @url = nil
 | 
					    @url = nil
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -40,6 +41,22 @@ class Livecheck
 | 
				
			|||||||
    @skip
 | 
					    @skip
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  # Sets the strategy instance variable to the provided symbol or returns the
 | 
				
			||||||
 | 
					  # strategy instance variable when no argument is provided. The strategy
 | 
				
			||||||
 | 
					  # symbols use snake case (e.g., `:page_match`) and correspond to the strategy
 | 
				
			||||||
 | 
					  # file name.
 | 
				
			||||||
 | 
					  # @param symbol [Symbol] symbol for the desired strategy
 | 
				
			||||||
 | 
					  def strategy(symbol = nil)
 | 
				
			||||||
 | 
					    case symbol
 | 
				
			||||||
 | 
					    when nil
 | 
				
			||||||
 | 
					      @strategy
 | 
				
			||||||
 | 
					    when Symbol
 | 
				
			||||||
 | 
					      @strategy = symbol
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					      raise TypeError, "Livecheck#strategy expects a Symbol"
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  # Sets the url instance variable to the argument given, returns the url
 | 
					  # Sets the url instance variable to the argument given, returns the url
 | 
				
			||||||
  # instance variable when no argument is given.
 | 
					  # instance variable when no argument is given.
 | 
				
			||||||
  def url(val = nil)
 | 
					  def url(val = nil)
 | 
				
			||||||
@ -61,6 +78,7 @@ class Livecheck
 | 
				
			|||||||
      "regex"    => @regex,
 | 
					      "regex"    => @regex,
 | 
				
			||||||
      "skip"     => @skip,
 | 
					      "skip"     => @skip,
 | 
				
			||||||
      "skip_msg" => @skip_msg,
 | 
					      "skip_msg" => @skip_msg,
 | 
				
			||||||
 | 
					      "strategy" => @strategy,
 | 
				
			||||||
      "url"      => @url,
 | 
					      "url"      => @url,
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
				
			|||||||
@ -44,6 +44,23 @@ describe Livecheck do
 | 
				
			|||||||
    end
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  describe "#strategy" do
 | 
				
			||||||
 | 
					    it "returns nil if not set" do
 | 
				
			||||||
 | 
					      expect(livecheckable.strategy).to be nil
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    it "returns the Symbol if set" do
 | 
				
			||||||
 | 
					      livecheckable.strategy(:page_match)
 | 
				
			||||||
 | 
					      expect(livecheckable.strategy).to eq(:page_match)
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    it "raises a TypeError if the argument isn't a Symbol" do
 | 
				
			||||||
 | 
					      expect {
 | 
				
			||||||
 | 
					        livecheckable.strategy("page_match")
 | 
				
			||||||
 | 
					      }.to raise_error(TypeError, "Livecheck#strategy expects a Symbol")
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  describe "#url" do
 | 
					  describe "#url" do
 | 
				
			||||||
    it "returns nil if unset" do
 | 
					    it "returns nil if unset" do
 | 
				
			||||||
      expect(livecheckable.url).to be nil
 | 
					      expect(livecheckable.url).to be nil
 | 
				
			||||||
@ -57,7 +74,15 @@ describe Livecheck do
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  describe "#to_hash" do
 | 
					  describe "#to_hash" do
 | 
				
			||||||
    it "returns a Hash of all instance variables" do
 | 
					    it "returns a Hash of all instance variables" do
 | 
				
			||||||
      expect(livecheckable.to_hash).to eq({ "regex"=>nil, "skip"=>false, "skip_msg"=>nil, "url"=>nil })
 | 
					      expect(livecheckable.to_hash).to eq(
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					          "regex"    => nil,
 | 
				
			||||||
 | 
					          "skip"     => false,
 | 
				
			||||||
 | 
					          "skip_msg" => nil,
 | 
				
			||||||
 | 
					          "strategy" => nil,
 | 
				
			||||||
 | 
					          "url"      => nil,
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					      )
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user