Class: Antigravity::Guards::FileProtection
- Inherits:
-
Object
- Object
- Antigravity::Guards::FileProtection
- Defined in:
- lib/antigravity/guards.rb
Overview
Configurable opt-in file protection guard
Constant Summary collapse
- DEFAULT_FILES =
[ /\.env(\..*)?$/i, /Gemfile(\.lock)?$/i, /config\/secrets\.yml$/i, /config\/database\.yml$/i ].freeze
Instance Attribute Summary collapse
-
#protected_files ⇒ Object
readonly
Returns the value of attribute protected_files.
Instance Method Summary collapse
- #call(_tool_name, params) ⇒ Object
-
#initialize(files: nil, add: [], remove: []) ⇒ FileProtection
constructor
A new instance of FileProtection.
- #to_proc ⇒ Object
Constructor Details
#initialize(files: nil, add: [], remove: []) ⇒ FileProtection
Returns a new instance of FileProtection.
153 154 155 156 157 158 159 |
# File 'lib/antigravity/guards.rb', line 153 def initialize(files: nil, add: [], remove: []) initial_patterns = files ? Array(files) : DEFAULT_FILES patterns = initial_patterns.map { |f| f.is_a?(Regexp) ? f : /#{Regexp.escape(f.to_s)}$/i } patterns += Array(add).map { |f| f.is_a?(Regexp) ? f : /#{Regexp.escape(f.to_s)}$/i } patterns -= Array(remove).map { |f| f.is_a?(Regexp) ? f : /#{Regexp.escape(f.to_s)}$/i } @protected_files = patterns.freeze end |
Instance Attribute Details
#protected_files ⇒ Object (readonly)
Returns the value of attribute protected_files.
151 152 153 |
# File 'lib/antigravity/guards.rb', line 151 def protected_files @protected_files end |
Instance Method Details
#call(_tool_name, params) ⇒ Object
161 162 163 164 165 166 167 168 169 170 |
# File 'lib/antigravity/guards.rb', line 161 def call(_tool_name, params) path = extract_path(params) return :allow unless path if protected_path?(path) { status: :deny, reason: "FileProtection Guard: Modifications to '#{path}' are restricted." } else :allow end end |
#to_proc ⇒ Object
172 173 174 |
# File 'lib/antigravity/guards.rb', line 172 def to_proc method(:call).to_proc end |