Class: Placet::ActionRegistry
- Inherits:
-
Object
- Object
- Placet::ActionRegistry
- Defined in:
- lib/placet/action_registry.rb
Overview
既知の action を宣言して typo を検出するレジストリ(docs/rails-usage.md 2.5)。 評価セマンティクスに影響しない lint であり、正規形(version 1)には含まれない ランタイム機能なので、Definition(正規形と 1:1)ではなくランタイムが所有する
Instance Method Summary collapse
- #add(resource, operations) ⇒ Object
-
#empty? ⇒ Boolean
宣言が 1 つもない場合、レジストリは未使用(lint 無効)として扱う.
-
#initialize ⇒ ActionRegistry
constructor
A new instance of ActionRegistry.
-
#known_action?(action) ⇒ Boolean
具体的な action の照合.
-
#known_pattern?(pattern) ⇒ Boolean
パターン(ワイルドカード可)の照合.
Constructor Details
#initialize ⇒ ActionRegistry
Returns a new instance of ActionRegistry.
10 11 12 |
# File 'lib/placet/action_registry.rb', line 10 def initialize @by_resource = {} end |
Instance Method Details
#add(resource, operations) ⇒ Object
14 15 16 |
# File 'lib/placet/action_registry.rb', line 14 def add(resource, operations) (@by_resource[resource] ||= Set.new).merge(operations) end |
#empty? ⇒ Boolean
宣言が 1 つもない場合、レジストリは未使用(lint 無効)として扱う
19 |
# File 'lib/placet/action_registry.rb', line 19 def empty? = @by_resource.empty? |
#known_action?(action) ⇒ Boolean
具体的な action の照合
22 23 24 25 26 27 |
# File 'lib/placet/action_registry.rb', line 22 def known_action?(action) return true if empty? resource, operation = action.split(":", 2) @by_resource.key?(resource) && @by_resource[resource].include?(operation) end |
#known_pattern?(pattern) ⇒ Boolean
パターン(ワイルドカード可)の照合
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/placet/action_registry.rb', line 30 def known_pattern?(pattern) return true if empty? || pattern == "*" resource, operation = pattern.split(":", 2) return false if resource != "*" && !@by_resource.key?(resource) return true if operation == "*" if resource == "*" @by_resource.values.any? { |ops| ops.include?(operation) } else @by_resource[resource].include?(operation) end end |