Class | FragmentHash
In: | lib/fragment_hash.rb
Parent: | ActiveSupport::OrderedHash

URL の fragment を構成するためのハッシュクラス。

### Methods

[] default_params motion new to_fragment

### Classes and Modules

Module FragmentHash::ControllerHelper
Module FragmentHash::UrlHelper

### Constants

DUMMY_MOTION | = | "0".freeze

### Public Class methods

new(fragment)

[Source]

        # File lib/fragment_hash.rb, line 3
     3:   def initialize(fragment)
     4:     @motion = {}
     5:     @default_params = {}
     6:     if fragment
     7:       fragment.scan(/([a-z0-9]+)=([._a-z0-9]+)/) do |key, value|
     8:         values = value.split(/\./) # restSeparator in application.js
     9:         @motion[key] = values.shift
    10:         h = self[key] = {}.with_indifferent_access
    11:         values.each do |v|
    12:           k, v = v.split(/_/, 2)
    13:           h[k] = v
    14:         end
    15:       end
    16:     end
    17:   end

### Public Instance methods

[](key)

[Source]

        # File lib/fragment_hash.rb, line 19
    19:   def [](key)
    20:     return super(key.to_s) || {}.with_indifferent_access
    21:   end

default_params(view)

既定のパラメータを参照する。

[Source]

        # File lib/fragment_hash.rb, line 31
    31:   def default_params(view)
    32:     @default_params[view] ||= {}
    33:     return @default_params[view]
    34:   end

motion(view)

view にともなる motion を返す。

[Source]

        # File lib/fragment_hash.rb, line 26
    26:   def motion(view)
    27:     return @motion.fetch(view, DUMMY_MOTION)
    28:   end

to_fragment()

fragment を文字列として返す。

[Source]

        # File lib/fragment_hash.rb, line 37
    37:   def to_fragment
    38:     parts = []
    39:     self.each do |view, hash|
    40:       next if /\A\[/ =~ view
    41:       a = ["#{view}=#{motion(view)}"]
    42:       hash.keys.sort.each do |key|
    43:         a << "#{key}_#{hash[key]}"
    44:       end
    45:       parts << a.join(".")
    46:     end
    47:     return parts.join(",")
    48:   end

[Validate]