conifer 0.1.0 → 0.2.0

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
  SHA256:
3
- metadata.gz: 3c7b54565aae2076eedd2aab31aa601503fe2954e6a0cdadb5ab28dd4410c16e
4
- data.tar.gz: 95459486a5ed6286a535a832c8a3d58ad28692bdee498dcd91a28728027f2279
3
+ metadata.gz: 9fad9f0c8078a29011a491e89bc57962e1924bbe41b3014fe46059ba6cc2a4f7
4
+ data.tar.gz: a945b31b79184f2850d7cd80a75c638da5ab62a6acd24392fe62294dea618520
5
5
  SHA512:
6
- metadata.gz: 0717fccee49b78659b10fb490626e3274a93c43cda0bda9ce3798115764c3dfb18efafd27a6baee2244502065c64a9ef7e51b393c176df597dd32604b5ebea64
7
- data.tar.gz: df44776de879bebbb2967ef1ecc4c268576d126371f0758e6bb2af9c9b1aa3326361aa4b5a40f329a8ef7a83c46752d0217d6ffeeaa745347a3cc36741b607bd
6
+ metadata.gz: 687ae1f37561670156c2fb44e95b4b817af4785fa427b3526d68b884169c8586076cdce1abfaabddbe617881434a4ff586dcd20161ba915c4a61f07a33b6d62b
7
+ data.tar.gz: e40c1b9a9f8c5c3070b7593033abba374f70a9147c1b562b84af6cea5c0572de3e89302f716785a99424ac1e67a1f3127ed8e15371f6554f42452a078502ac30
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- conifer (0.1.0)
4
+ conifer (0.2.0)
5
5
  activesupport (>= 5.0.0)
6
6
 
7
7
  GEM
data/lib/conifer.rb CHANGED
@@ -3,23 +3,25 @@
3
3
  require 'conifer/version'
4
4
  require 'conifer/file'
5
5
 
6
- require 'active_support/all'
6
+ require 'active_support/concern'
7
7
 
8
8
  module Conifer
9
9
  extend ActiveSupport::Concern
10
10
 
11
- included do
12
- def conifer
13
- self.class.__conifer
14
- end
15
- end
16
-
17
11
  class_methods do
18
- attr_reader :__conifer
12
+ def conifer(file, prefix: nil, dir: nil, method: 'conifer', singleton: false)
13
+ body = proc do
14
+ return instance_variable_get("@conifer_#{method}") if instance_variable_defined?("@conifer_#{method}")
15
+
16
+ directory = dir || ::File.expand_path(::File.dirname(caller_locations.first.path))
17
+ instance_variable_set "@conifer_#{method}", Conifer::File.new(file, prefix: prefix, dir: directory)
18
+ end
19
19
 
20
- def conifer(file, prefix: nil, dir: nil)
21
- directory = dir.presence || ::File.expand_path(::File.dirname(caller_locations.first.path))
22
- @__conifer = Conifer::File.new(file, prefix: prefix, dir: directory)
20
+ if singleton
21
+ define_singleton_method method, &body
22
+ else
23
+ define_method method, &body
24
+ end
23
25
  end
24
26
  end
25
27
  end
data/lib/conifer/file.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'yaml'
4
+ require 'erb'
4
5
 
5
6
  module Conifer
6
7
  class File
@@ -15,10 +16,14 @@ module Conifer
15
16
  end
16
17
 
17
18
  def [](key)
18
- args = key.split('.').tap { |v| v.prepend(prefix) if prefix.present? }
19
+ args = key.split('.').tap { |v| v.prepend(prefix) if prefix }
19
20
  config.dig(*args)
20
21
  end
21
22
 
23
+ def as_hash
24
+ config
25
+ end
26
+
22
27
  private
23
28
 
24
29
  def config
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Conifer
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: conifer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hamed Asghari