app_root 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +24 -0
- data/lib/app_root.rb +22 -4
- data/lib/app_root/version.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d9c08256cfa27cf58ff029a01e9d1f6a962b6905
|
4
|
+
data.tar.gz: c3535b0dc02bbfb66ca3c9423738cf120a4d78bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0965e22a22633b3f8f268a48b3e2cd29a111b7fe7e2836eca807759a83782647fc12fa3b6d5b89d284d8e5e399621212a4b8734a500e8742fb3c7f164a1c8e86
|
7
|
+
data.tar.gz: 44da995349f3c0882cc77b96d446c97eea6d722389771d0e0c4957cc800c45fb5ac9ba531ccb196aa23804bdbf3b3bc5a7907ff9781a69cda07243d0141b474d
|
data/README.md
CHANGED
@@ -18,6 +18,7 @@ Or install it yourself as:
|
|
18
18
|
$ gem install app_root
|
19
19
|
|
20
20
|
## Usage
|
21
|
+
### Basic Usage
|
21
22
|
```ruby
|
22
23
|
require "app_root"
|
23
24
|
|
@@ -25,6 +26,29 @@ puts AppRoot.path("config.ru")
|
|
25
26
|
#=> /path/to/your/application/root
|
26
27
|
```
|
27
28
|
|
29
|
+
### Integrate Your App
|
30
|
+
Using AppRoot.path:
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
class MyApp
|
34
|
+
def self.root
|
35
|
+
AppRoot.path("config.ru")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
```
|
39
|
+
|
40
|
+
Including AppRoot:
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
class MyApp
|
44
|
+
include AppRoot
|
45
|
+
|
46
|
+
def self.root_flag
|
47
|
+
"config.ru"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
```
|
51
|
+
|
28
52
|
## Development
|
29
53
|
|
30
54
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/app_root.rb
CHANGED
@@ -1,7 +1,18 @@
|
|
1
|
-
|
1
|
+
module AppRoot
|
2
2
|
class << self
|
3
3
|
attr_writer :default_path
|
4
4
|
|
5
|
+
def find_with_flag(flag)
|
6
|
+
find_root_with_flag(flag, called_from)
|
7
|
+
end
|
8
|
+
alias_method :path, :find_with_flag
|
9
|
+
|
10
|
+
def included(base)
|
11
|
+
base.extend(ClassMethods)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
5
16
|
def called_from
|
6
17
|
File.dirname(
|
7
18
|
caller_locations.map do |l|
|
@@ -31,10 +42,17 @@ class AppRoot
|
|
31
42
|
|
32
43
|
Pathname.new(File.realpath(root))
|
33
44
|
end
|
45
|
+
end
|
34
46
|
|
35
|
-
|
36
|
-
|
47
|
+
module ClassMethods
|
48
|
+
def root
|
49
|
+
AppRoot.find_with_flag(root_flag)
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def root_flag
|
55
|
+
raise(NotImplementedError, "You must implement #{self}.#{__method__}")
|
37
56
|
end
|
38
|
-
alias_method :path, :find_with_flag
|
39
57
|
end
|
40
58
|
end
|
data/lib/app_root/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = "0.1.
|
1
|
+
module AppRoot
|
2
|
+
VERSION = "0.1.1"
|
3
3
|
end
|