Class: SolidWebUi::Cache::EntriesController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- SolidWebUi::Cache::EntriesController
- Defined in:
- app/controllers/solid_web_ui/cache/entries_controller.rb
Instance Method Summary collapse
- #clear ⇒ Object
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#clear ⇒ Object
95 96 97 98 |
# File 'app/controllers/solid_web_ui/cache/entries_controller.rb', line 95 def clear SolidCache::Entry.delete_all redirect_to root_path, notice: "Cache cleared." end |
#create ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/controllers/solid_web_ui/cache/entries_controller.rb', line 35 def create @key = params[:key].to_s @value = params[:value].to_s @expires_at = params[:expires_at].to_s @version = params[:version].to_s if @key.empty? return render_new_error("Key can't be blank.") elsif SolidCache::Entry.read(@key) return render_new_error("An entry with that key already exists.") end expires_at = parse_expires_at(@expires_at) SolidCache::Entry.write(@key, encode_entry(@value, version: @version.presence, expires_at: expires_at)) redirect_to entries_path, notice: "Entry created." rescue InvalidExpiry render_new_error("Couldn't parse the expiry time.") end |
#destroy ⇒ Object
90 91 92 93 |
# File 'app/controllers/solid_web_ui/cache/entries_controller.rb', line 90 def destroy @entry.destroy redirect_to entries_path, notice: "Entry deleted." end |
#edit ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/controllers/solid_web_ui/cache/entries_controller.rb', line 54 def edit decoded = decode_value(@entry.value) value = resolved_value(decoded) @value_editable = value.is_a?(String) @meta_editable = value != UNREADABLE @key = scrub_for_display(@entry.key) @expires_at = format_expires_at(decoded) @version = (decoded.version if decoded.respond_to?(:version)).to_s if @value_editable @value = value elsif @meta_editable @value = value.inspect @note = "This entry holds a #{value.class} (not a plain string), so the value is " \ "read-only — but you can still change its metadata below." else @value = scrub_for_display(@entry.value) @note = "This value couldn't be read as a cache entry (it may use a different cache format " \ "or reference a class this app can't load), so it can't be edited here." end end |
#index ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'app/controllers/solid_web_ui/cache/entries_controller.rb', line 11 def index scope = SolidCache::Entry.order(id: :desc) @paginator = SolidWebUi::Paginator.new(scope, page: params[:page], per_page: per_page) @entries = @paginator.records # Per-entry expiry, read from each cache envelope's header (no value # deserialization). Numeric epoch = has a TTL, :never = decodable but no # TTL, :undecodable = couldn't be read. @expiry = @entries.to_h { |entry| [ entry.id, entry_expiry(entry) ] } end |
#new ⇒ Object
28 29 30 31 32 33 |
# File 'app/controllers/solid_web_ui/cache/entries_controller.rb', line 28 def new @key = "" @value = "" @expires_at = "" @version = "" end |
#show ⇒ Object
21 22 23 24 25 26 |
# File 'app/controllers/solid_web_ui/cache/entries_controller.rb', line 21 def show @decoded = decode_value(@entry.value) value = resolved_value(@decoded) @value_readable = value != UNREADABLE @value_text = value.is_a?(String) ? value : value.inspect if @value_readable end |
#update ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'app/controllers/solid_web_ui/cache/entries_controller.rb', line 76 def update value = resolved_value(decode_value(@entry.value)) if value == UNREADABLE return redirect_to edit_entry_path(@entry), alert: "This entry can't be edited." end value = params[:value].to_s if value.is_a?(String) expires_at = parse_expires_at(params[:expires_at]) SolidCache::Entry.write(@entry.key, encode_entry(value, version: params[:version].presence, expires_at: expires_at)) redirect_to entry_path(@entry), notice: "Entry updated." rescue InvalidExpiry redirect_to edit_entry_path(@entry), alert: "Couldn't parse the expiry time." end |