Class: Keela::Strategies::Attributes

Inherits:
Keela::Strategy show all
Defined in:
lib/keela/strategies/attributes.rb

Instance Method Summary collapse

Methods inherited from Keela::Strategy

#extract_definitions_from_file

Instance Method Details

#definition_file_patternObject



10
11
12
13
# File 'lib/keela/strategies/attributes.rb', line 10

def definition_file_pattern
  # Match app/ and lib/ directories, but exclude spec/ and test/
  %r{(?:^|/)(?:ee/)?(?:app|lib)/}
end

#extract_definition(line) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/keela/strategies/attributes.rb', line 15

def extract_definition(line)
  # Match attr_accessor, attr_reader, attr_writer declarations
  # But NOT other attr_* DSLs like attr_encrypted, attr_spammable, etc.
  return nil unless line =~ /^\s*attr_(accessor|reader|writer)\s+/

  # Extract the first symbol after the attr_* declaration
  return nil unless line =~ /attr_(?:accessor|reader|writer)\s+:(\w+)/

  Regexp.last_match(1)
end

#nameObject



6
7
8
# File 'lib/keela/strategies/attributes.rb', line 6

def name
  "attributes"
end

#skip_comments?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/keela/strategies/attributes.rb', line 39

def skip_comments?
  true
end

#usage_regex(name) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/keela/strategies/attributes.rb', line 26

def usage_regex(name)
  # Match usage of the attribute:
  # - Getter: obj.name, name (without receiver)
  # - Setter: obj.name = value, self.name = value
  # - Instance variable: @name (direct access)
  #
  # Exclude:
  # - Symbol notation (:name)
  # - The attr_* definition itself
  # - Partial word matches (username shouldn't match name)
  /(?:(?<!:)(?<!attr_accessor\s)(?<!attr_reader\s)(?<!attr_writer\s)(?<![a-z_])#{Regexp.quote(name)}(?!\w)|@#{Regexp.quote(name)}(?!\w))/
end