Class: ReleaseFeature::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/release_feature/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(environment:, base_repository:, extra_repository: nil, refresh_interval_sec: 600) ⇒ Client

Returns a new instance of Client.

Parameters:

  • environment (String, Symbol)
  • base_repository (ActiveRecordRepository, YamlRecordRepository, HashRecordRepository)
  • extra_repository (nil) (defaults to: nil)
  • refresh_interval_sec (Integer) (defaults to: 600)


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_atObject (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_featuresObject



39
40
41
# File 'lib/release_feature/client.rb', line 39

def current_features
  @features
end

#environmentsObject



56
57
58
# File 'lib/release_feature/client.rb', line 56

def environments
  @features.environments
end

#namesObject



52
53
54
# File 'lib/release_feature/client.rb', line 52

def names
  @features.names
end

#permitted?(feature_name, time: nil) ⇒ Boolean

Parameters:

  • feature_name (Symbol)
  • time (TrueClass, FalseClass) (defaults to: nil)

Returns:

  • (Boolean)

Raises:



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

#refreshObject



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.message
  # errorがある場合は@featuresを更新しない
  false
end