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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1a5b0f8d107b7aab6695951a9f8c46cd369277df
4
- data.tar.gz: 431d640431dc975213627d48e3c69566b850d4cf
3
+ metadata.gz: d9c08256cfa27cf58ff029a01e9d1f6a962b6905
4
+ data.tar.gz: c3535b0dc02bbfb66ca3c9423738cf120a4d78bd
5
5
  SHA512:
6
- metadata.gz: db1c43bcf2c7d9ac9d5ee6aeecbcea188b57a86eb4cad7dcbeb2b86ef392a95f5e71032aaed6d1dd49573aa197f282f9484e3808058711a979d1175e0a7d03c9
7
- data.tar.gz: d0cbb63764909447b0921bbc54dea193cb4a6c138527334c3e60c5bfe90e82916d69ad6db02dad983fe202bc69b6a6eab5ea7b9f74cee662b273ebb67546e757
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
- class AppRoot
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
- def find_with_flag(flag)
36
- find_root_with_flag(flag, called_from)
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
@@ -1,3 +1,3 @@
1
- class AppRoot
2
- VERSION = "0.1.0"
1
+ module AppRoot
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: app_root
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - nownabe