Class: CopyTunerIncompatibleSearch::SearchCommand::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/copy_tuner_incompatible_search/search_command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, key) ⇒ Result

Returns a new instance of Result.



28
29
30
31
32
# File 'lib/copy_tuner_incompatible_search/search_command.rb', line 28

def initialize(type, key)
  @type = type
  @key = key
  @usages = []
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



26
27
28
# File 'lib/copy_tuner_incompatible_search/search_command.rb', line 26

def key
  @key
end

#typeObject (readonly)

Returns the value of attribute type.



26
27
28
# File 'lib/copy_tuner_incompatible_search/search_command.rb', line 26

def type
  @type
end

#usagesObject (readonly)

Returns the value of attribute usages.



26
27
28
# File 'lib/copy_tuner_incompatible_search/search_command.rb', line 26

def usages
  @usages
end

Instance Method Details

#add_usage(grep_result) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/copy_tuner_incompatible_search/search_command.rb', line 46

def add_usage(grep_result)
  grep_result.each_line do |line|
    if lazy?
      line.scan(/(?<=['"])\.[^'"]+/) do |lazy_key|
        @usages << Usage.new(line, lazy_key.to_s)
      end
    else
      @usages << Usage.new(line)
    end
  end
end

#already_migrated?(usage) ⇒ Boolean

Returns:

  • (Boolean)


72
73
74
75
# File 'lib/copy_tuner_incompatible_search/search_command.rb', line 72

def already_migrated?(usage)
  used_key = lazy? ? usage.lazy_key : key
  usage.initializers? || usage.code.include?("#{used_key}_html")
end

#dynamic?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/copy_tuner_incompatible_search/search_command.rb', line 42

def dynamic?
  @type == :dynamic
end

#full_key_for(usage) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/copy_tuner_incompatible_search/search_command.rb', line 58

def full_key_for(usage)
  if lazy?
    path = usage
           .file
           .sub(%r{^app/views/}, '')
           .sub(/\..+$/, '')
           .sub('/_', '/')
           .gsub('/', '.')
    path + usage.lazy_key.to_s
  else
    key
  end
end

#lazy?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/copy_tuner_incompatible_search/search_command.rb', line 38

def lazy?
  @type == :lazy
end

#static?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/copy_tuner_incompatible_search/search_command.rb', line 34

def static?
  @type == :static
end