Class: CopyTunerIncompatibleSearch::SearchCommand::Result
- Inherits:
-
Object
- Object
- CopyTunerIncompatibleSearch::SearchCommand::Result
- Defined in:
- lib/copy_tuner_incompatible_search/search_command.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#usages ⇒ Object
readonly
Returns the value of attribute usages.
Instance Method Summary collapse
- #add_usage(grep_result) ⇒ Object
- #already_migrated?(usage) ⇒ Boolean
- #dynamic? ⇒ Boolean
- #full_key_for(usage) ⇒ Object
-
#initialize(type, key) ⇒ Result
constructor
A new instance of Result.
- #lazy? ⇒ Boolean
- #static? ⇒ Boolean
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
#key ⇒ Object (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 |
#type ⇒ Object (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 |
#usages ⇒ Object (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
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
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
38 39 40 |
# File 'lib/copy_tuner_incompatible_search/search_command.rb', line 38 def lazy? @type == :lazy end |
#static? ⇒ Boolean
34 35 36 |
# File 'lib/copy_tuner_incompatible_search/search_command.rb', line 34 def static? @type == :static end |