Skip to content
This repository was archived by the owner on Aug 17, 2019. It is now read-only.

Commit fdbd276

Browse files
committed
Introduce transformed vars
1 parent 4bb32b3 commit fdbd276

File tree

2 files changed

+54
-6
lines changed

2 files changed

+54
-6
lines changed

Diff for: src/main/scala/com/ckkloverdos/sys/SysEnv.scala

+15-6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.ckkloverdos.sys
1818

1919
import com.ckkloverdos.convert.Converters
20+
import java.io.File
2021

2122
/**
2223
* Abstraction for environment variables.
@@ -34,23 +35,31 @@ final class SysEnv(val name: String) extends SysVar[SysEnv](System.getenv(_)) {
3435
}
3536

3637
object SysEnv {
37-
lazy val PS1 = this("PS1")
38-
lazy val PS2 = this("PS2")
38+
lazy val PS1 = this("PS1")
39+
lazy val PS2 = this("PS2")
3940

40-
lazy val SHELL = this("SHELL")
41-
lazy val TERM = this("TERM")
41+
lazy val SHELL = this("SHELL")
42+
lazy val TERM = this("TERM")
4243

43-
lazy val PATH = this("PATH")
44-
lazy val MANPATH = this("MANPATH")
44+
lazy val PATH = this("PATH")
45+
46+
lazy val MANPATH = this("MANPATH")
4547

4648
lazy val USER = this("USER")
49+
4750
lazy val HOME = this("HOME")
51+
lazy val HOME_FOLDER = TransformedVar.File(HOME)
4852

4953
lazy val EDITOR = this("EDITOR")
5054

5155
lazy val SCALA_HOME = this("SCALA_HOME")
56+
lazy val SCALA_HOME_FOLDER = TransformedVar.File(SCALA_HOME)
57+
5258
lazy val JAVA_HOME = this("JAVA_HOME")
59+
lazy val JAVA_HOME_FOLDER = TransformedVar.File(JAVA_HOME)
60+
5361
lazy val JDK_HOME = this("JDK_HOME")
62+
lazy val JDK_HOME_FOLDER = TransformedVar.File(JDK_HOME)
5463

5564
lazy val LC_CTYPE = this("LC_CTYPE")
5665

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2011-2012 Christos KK Loverdos
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.ckkloverdos.sys
18+
19+
import java.io.File
20+
21+
/**
22+
* A [[com.ckkloverdos.sys.SysVar]] that can be transformed to something else.
23+
*
24+
* @author Christos KK Loverdos <loverdos@gmail.com>
25+
*/
26+
final class TransformedVar[T <: SysVar[T], V] private(val sysVar: T, f: T V)
27+
extends Function0[V]
28+
with Ordered[TransformedVar[T, V]] {
29+
30+
def compare(thatVar: TransformedVar[T, V]) = sysVar compare thatVar.sysVar
31+
32+
def apply() = f(sysVar)
33+
}
34+
35+
object TransformedVar {
36+
def apply[T <: SysVar[T], V](v: T)(f: T V): TransformedVar[T, V] = new TransformedVar(v, f)
37+
38+
def File[T <: SysVar[T]](v: T) = TransformedVar[T, File](v)(h new File(h.rawValue))
39+
}

0 commit comments

Comments
 (0)