pears 0.1.4 → 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: 84ea4b16d1dcfcc4911f20b9acfb4053aec840216e682e02364877648a979e9e
4
- data.tar.gz: 6851286da9c77ae22c7bfef5418a84400b1663f763f450e7115a89a1cc1c0b1a
3
+ metadata.gz: 7abec7354b67f08e28107cfb1fb8c94864d7ac207ff1b7fd64fc916768195544
4
+ data.tar.gz: ecd79dde81cd9964d287aaa12e42bbc6c449403b4eded1f5a23d1d886d735066
5
5
  SHA512:
6
- metadata.gz: '085fe231ed469af60f246a03d69555713334c00c80f39a0e22c753a3d8c901f46412328f20579497ac852732c000173390c7f6a60f09ddb57446d5f5c73f744b'
7
- data.tar.gz: 3ff07d4ebc6354a61b5dfc84d1a463ba7a43c4fc69d472b7570754bc181a6d94ebdd000da83fd00459f6724ca386fd0facaba6060a73574667dcca018c47ffe9
6
+ metadata.gz: 3e5da3506aa2ae5fd633a8ef815b109bf317d6c9338a4730b0f3d304dce946158cac778e8cdb67c510c9ff02a69dec318f2c35eb6307f9ede9367fcc716cfb2d
7
+ data.tar.gz: edf8f9e02d5c04de51c97400bcf666c362e92a5ce0b91ad8d6820360c0e111e8b83b5d9f155d75e473bf546acb7af8aa945a54cefe8e4f5fd89fb18faf8e0bab
@@ -7,13 +7,23 @@ module Pears
7
7
  def self.enable_provider(provider, yielder: false)
8
8
  method_name = provider.name.split('::').last.underscore.to_sym
9
9
  if yielder
10
- define_method(method_name) do |*args, &block|
10
+ define_method(method_name) do |*args, **opts, &block|
11
+ # Skip if Rails environment should not use this perticular setting
12
+ if defined?(Rails)
13
+ return if Array.wrap(opts[:skip_env]).include?(Rails.env.to_sym)
14
+ end
15
+
11
16
  pr = provider.new(builder: self, &block)
12
17
  push pr
13
18
  pr
14
19
  end
15
20
  else
16
21
  define_method(method_name) do |*args, **opts, &block|
22
+ # Skip if Rails environment should not use this perticular setting
23
+ if defined?(Rails)
24
+ return if Array.wrap(opts[:skip_env]).include?(Rails.env.to_sym)
25
+ end
26
+
17
27
  pr = provider.new(*args, **opts, &block)
18
28
  push pr
19
29
  pr
@@ -26,6 +36,10 @@ module Pears
26
36
  enable_provider RemoteFile
27
37
  enable_provider Subscription, yielder: true
28
38
 
39
+ if defined?(Rails) == "constant"
40
+ enable_provider RailsConfig
41
+ end
42
+
29
43
  delegate :name, to: :subject
30
44
 
31
45
  def initialize(subject)
@@ -0,0 +1,23 @@
1
+ require 'yaml'
2
+ require 'active_support/core_ext/hash/indifferent_access'
3
+
4
+ module Pears
5
+ module Provider
6
+ # Used for loading simple YAML file locally.
7
+ class RailsConfig < Base
8
+ def initialize(*path_parts, on_failure: :raise)
9
+ file = path_parts.pop
10
+ file_path = Rails.root.join('config', *path_parts, "#{file}.yml")
11
+ yaml_data = File.read(file_path)
12
+ @data = parse_yaml(yaml_data)
13
+ rescue Errno::ENOENT,
14
+ Pears::InvalidProviderData => error
15
+ if on_failure == :null
16
+ @data = {}
17
+ else
18
+ raise error
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,6 +1,7 @@
1
1
  require_relative "provider/base"
2
2
  require_relative "provider/local_file"
3
3
  require_relative "provider/remote_file"
4
+ require_relative "provider/rails_config"
4
5
  require_relative "provider/subscription"
5
6
  require_relative "provider/env"
6
7
  require_relative "provider/loco"
data/lib/pears/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pears
4
- VERSION = "0.1.4"
4
+ VERSION = "0.2.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pears
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Kemp
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-03-29 00:00:00.000000000 Z
11
+ date: 2022-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-configurable
@@ -92,6 +92,7 @@ files:
92
92
  - lib/pears/provider/hash.rb
93
93
  - lib/pears/provider/local_file.rb
94
94
  - lib/pears/provider/loco.rb
95
+ - lib/pears/provider/rails_config.rb
95
96
  - lib/pears/provider/remote_file.rb
96
97
  - lib/pears/provider/subscription.rb
97
98
  - lib/pears/subject.rb