Module: Rollout::UI::Helpers
- Defined in:
- lib/rollout/ui/helpers.rb
Instance Method Summary collapse
- #activate_percentage_feature_path(feature_name, percentage) ⇒ Object
- #config ⇒ Object
- #current_user ⇒ Object
- #delete_feature_path(feature_name) ⇒ Object
- #feature_path(feature_name) ⇒ Object
-
#feature_to_hash(feature) ⇒ Object
Returns a hash of feature data to be rendered as json.
-
#filtered_features(rollout, feature_names) ⇒ Object
Filters features by user and group if those params are provided.
- #format_change_key(key) ⇒ Object
- #format_change_value(value) ⇒ Object
- #index_path ⇒ Object
- #json_request? ⇒ Boolean
- #new_feature_path ⇒ Object
- #stylesheet_path(name) ⇒ Object
- #time_ago(time) ⇒ Object
- #with_rollout_context(rollout, context) ⇒ Object
Instance Method Details
#activate_percentage_feature_path(feature_name, percentage) ⇒ Object
28 29 30 |
# File 'lib/rollout/ui/helpers.rb', line 28 def activate_percentage_feature_path(feature_name, percentage) "#{request.script_name}/features/#{feature_name}/activate-percentage?percentage=#{percentage.to_f}" end |
#config ⇒ Object
49 50 51 |
# File 'lib/rollout/ui/helpers.rb', line 49 def config Rollout::UI.config end |
#current_user ⇒ Object
32 33 34 35 36 37 |
# File 'lib/rollout/ui/helpers.rb', line 32 def current_user @current_user ||= begin id = request.session["warden.user.user.key"].try(:[], 0).try(:[], 0) User.find_by(id: id) unless id.nil? end end |
#delete_feature_path(feature_name) ⇒ Object
24 25 26 |
# File 'lib/rollout/ui/helpers.rb', line 24 def delete_feature_path(feature_name) "#{request.script_name}/features/#{feature_name}/delete" end |
#feature_path(feature_name) ⇒ Object
20 21 22 |
# File 'lib/rollout/ui/helpers.rb', line 20 def feature_path(feature_name) "#{request.script_name}/features/#{feature_name}" end |
#feature_to_hash(feature) ⇒ Object
Returns a hash of feature data to be rendered as json
103 104 105 106 107 108 109 110 |
# File 'lib/rollout/ui/helpers.rb', line 103 def feature_to_hash(feature) { data: feature.data, groups: feature.groups, name: feature.name, percentage: feature.percentage } end |
#filtered_features(rollout, feature_names) ⇒ Object
Filters features by user and group if those params are provided
93 94 95 96 97 98 99 100 |
# File 'lib/rollout/ui/helpers.rb', line 93 def filtered_features(rollout, feature_names) feature_names.select do |feature_name| feature = rollout.get(feature_name) user_match = params[:user].nil? || feature.users.member?(params[:user]) group_match = params[:group].nil? || feature.groups.member?(params[:group].to_sym) user_match && group_match end end |
#format_change_key(key) ⇒ Object
73 74 75 |
# File 'lib/rollout/ui/helpers.rb', line 73 def format_change_key(key) key.to_s.gsub('data.', '') end |
#format_change_value(value) ⇒ Object
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/rollout/ui/helpers.rb', line 77 def format_change_value(value) case value when Array "[#{value.join(', ')}]" when String, nil "'#{value}'" else value end end |
#index_path ⇒ Object
12 13 14 |
# File 'lib/rollout/ui/helpers.rb', line 12 def index_path "#{request.script_name}/" end |
#json_request? ⇒ Boolean
88 89 90 |
# File 'lib/rollout/ui/helpers.rb', line 88 def json_request? request.env['HTTP_ACCEPT'] == 'application/json' end |
#new_feature_path ⇒ Object
16 17 18 |
# File 'lib/rollout/ui/helpers.rb', line 16 def new_feature_path "#{request.script_name}/features/new" end |
#stylesheet_path(name) ⇒ Object
8 9 10 |
# File 'lib/rollout/ui/helpers.rb', line 8 def stylesheet_path(name) "#{request.script_name}/css/#{name}.css" end |
#time_ago(time) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/rollout/ui/helpers.rb', line 53 def time_ago(time) return '' unless time diff = (Time.now-time).to_i case diff when 0 then 'just now' when 1 then 'a second ago' when 2..59 then diff.to_s+' seconds ago' when 60..119 then 'a minute ago' #120 = 2 minutes when 120..3540 then (diff/60).to_i.to_s+' minutes ago' when 3541..7100 then 'an hour ago' # 3600 = 1 hour when 7101..82800 then ((diff+99)/3600).to_i.to_s+' hours ago' when 82801..172000 then 'a day ago' # 86400 = 1 day when 172001..518400 then ((diff+800)/(60*60*24)).to_i.to_s+' days ago' when 518400..1036800 then 'a week ago' else ((diff+180000)/(60*60*24*7)).to_i.to_s+' weeks ago' end end |
#with_rollout_context(rollout, context) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/rollout/ui/helpers.rb', line 39 def with_rollout_context(rollout, context) if rollout.respond_to?(:logging) rollout.logging.with_context(context) do yield end else yield end end |