Class: ReleaseFeature::Client
- Inherits:
-
Object
- Object
- ReleaseFeature::Client
- Defined in:
- lib/release_feature/client.rb
Instance Attribute Summary collapse
-
#updated_at ⇒ Object
readonly
Returns the value of attribute updated_at.
Instance Method Summary collapse
- #current_features ⇒ Object
- #environments ⇒ Object
-
#initialize(environment:, base_repository:, extra_repository: nil, refresh_interval_sec: 600) ⇒ Client
constructor
A new instance of Client.
- #names ⇒ Object
- #permitted?(feature_name, time: nil) ⇒ Boolean
- #refresh ⇒ Object
Constructor Details
#initialize(environment:, base_repository:, extra_repository: nil, refresh_interval_sec: 600) ⇒ Client
Returns a new instance of Client.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/release_feature/client.rb', line 11 def initialize(environment:, base_repository:, extra_repository: nil, refresh_interval_sec: 600) @environment = environment.to_sym @base_repository = base_repository @extra_repository = extra_repository @refresh_interval_sec = if refresh_interval_sec.is_a?(Integer) refresh_interval_sec else raise ReleaseFeature::Error, 'refresh_interval_sec must be Integer' end load_features end |
Instance Attribute Details
#updated_at ⇒ Object (readonly)
Returns the value of attribute updated_at.
5 6 7 |
# File 'lib/release_feature/client.rb', line 5 def updated_at @updated_at end |
Instance Method Details
#current_features ⇒ Object
39 40 41 |
# File 'lib/release_feature/client.rb', line 39 def current_features @features end |
#environments ⇒ Object
56 57 58 |
# File 'lib/release_feature/client.rb', line 56 def environments @features.environments end |
#names ⇒ Object
52 53 54 |
# File 'lib/release_feature/client.rb', line 52 def names @features.names end |
#permitted?(feature_name, time: nil) ⇒ Boolean
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/release_feature/client.rb', line 25 def permitted?(feature_name, time: nil) time ||= Time.now refresh if expired?(time) name = feature_name.to_sym raise ReleaseFeature::Error, "#{feature_name} is not registered." if @features[feature_name.to_sym].nil? feature = to_feature(@features, name, @environment) return false if feature.nil? feature.permitted?(time) end |
#refresh ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/release_feature/client.rb', line 43 def refresh load_features true rescue StandardError => e e. # errorがある場合は@featuresを更新しない false end |