cask/config: new method for cask.config.explicit as string
This commit is contained in:
		
							parent
							
								
									4ae8dfe43f
								
							
						
					
					
						commit
						f39fb5d6b2
					
				@ -127,7 +127,7 @@ module Cask
 | 
				
			|||||||
          .map { |arg| T.cast(arg.split("=", 2), [String, String]) }
 | 
					          .map { |arg| T.cast(arg.split("=", 2), [String, String]) }
 | 
				
			||||||
          .map do |(flag, value)|
 | 
					          .map do |(flag, value)|
 | 
				
			||||||
            key = flag.sub(/^--/, "")
 | 
					            key = flag.sub(/^--/, "")
 | 
				
			||||||
 | 
					            # converts --language flag to :languages config key
 | 
				
			||||||
            if key == "language"
 | 
					            if key == "language"
 | 
				
			||||||
              key = "languages"
 | 
					              key = "languages"
 | 
				
			||||||
              value = value.split(",")
 | 
					              value = value.split(",")
 | 
				
			||||||
@ -182,6 +182,18 @@ module Cask
 | 
				
			|||||||
      self.class.new(explicit: other.explicit.merge(explicit))
 | 
					      self.class.new(explicit: other.explicit.merge(explicit))
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    sig { returns(String) }
 | 
				
			||||||
 | 
					    def explicit_s
 | 
				
			||||||
 | 
					      explicit.map do |key, value|
 | 
				
			||||||
 | 
					        # inverse of #env - converts :languages config key back to --language flag
 | 
				
			||||||
 | 
					        if key == :languages
 | 
				
			||||||
 | 
					          key = "language"
 | 
				
			||||||
 | 
					          value = languages.join(",")
 | 
				
			||||||
 | 
					        end
 | 
				
			||||||
 | 
					        "#{key}: \"#{value.to_s.sub(/^#{ENV['HOME']}/, "~")}\""
 | 
				
			||||||
 | 
					      end.join(", ")
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    sig { params(options: T.untyped).returns(String) }
 | 
					    sig { params(options: T.untyped).returns(String) }
 | 
				
			||||||
    def to_json(**options)
 | 
					    def to_json(**options)
 | 
				
			||||||
      {
 | 
					      {
 | 
				
			||||||
 | 
				
			|||||||
@ -60,11 +60,22 @@ describe Cask::Config, :cask do
 | 
				
			|||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  describe "#explicit" do
 | 
					  describe "#explicit" do
 | 
				
			||||||
    let(:config) { described_class.new(explicit: { appdir: "/explicit/path/to/apps" }) }
 | 
					    let(:config) {
 | 
				
			||||||
 | 
					      described_class.new(explicit: { appdir:    "/explicit/path/to/apps",
 | 
				
			||||||
 | 
					                                      languages: ["zh-TW", "en"] })
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    it "returns directories explicitly given as arguments" do
 | 
					    it "returns directories explicitly given as arguments" do
 | 
				
			||||||
      expect(config.explicit[:appdir]).to eq(Pathname("/explicit/path/to/apps"))
 | 
					      expect(config.explicit[:appdir]).to eq(Pathname("/explicit/path/to/apps"))
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    it "returns array of preferred languages" do
 | 
				
			||||||
 | 
					      expect(config.explicit[:languages]).to eq(["zh-TW", "en"])
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    it "returns string of explicit config keys and values" do
 | 
				
			||||||
 | 
					      expect(config.explicit_s).to eq('appdir: "/explicit/path/to/apps", language: "zh-TW,en"')
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  context "when installing a cask and then adding a global default dir" do
 | 
					  context "when installing a cask and then adding a global default dir" do
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user