Class: Avm::EacRubyBase1::Rubygems::Gemspec::AddOrReplaceGemLine
- Inherits:
-
Object
- Object
- Avm::EacRubyBase1::Rubygems::Gemspec::AddOrReplaceGemLine
- Defined in:
- lib/avm/eac_ruby_base1/rubygems/gemspec/add_or_replace_gem_line.rb
Constant Summary collapse
- DEPENDENCY_PREFIX =
' s.add%<dependency_type>s_dependency \'%<gem_name>s\''
Instance Method Summary collapse
- #add_line ⇒ Object
- #add_line_index ⇒ Object
- #existing_gem_line_index ⇒ Integer
- #gem_line_prefix ⇒ String
- #gems_lines_start_index ⇒ Integer
- #new_gem_line ⇒ Object
- #quoted_gem_specs ⇒ Object
- #replace_line ⇒ Object
- #result ⇒ Object
Instance Method Details
#add_line ⇒ Object
35 36 37 |
# File 'lib/avm/eac_ruby_base1/rubygems/gemspec/add_or_replace_gem_line.rb', line 35 def add_line lines.insert(add_line_index, new_gem_line) end |
#add_line_index ⇒ Object
39 40 41 42 43 44 |
# File 'lib/avm/eac_ruby_base1/rubygems/gemspec/add_or_replace_gem_line.rb', line 39 def add_line_index (gems_lines_start_index..(lines.count - 1)).each do |e| return e if new_gem_line < lines[e] end lines.count end |
#existing_gem_line_index ⇒ Integer
20 21 22 23 24 25 |
# File 'lib/avm/eac_ruby_base1/rubygems/gemspec/add_or_replace_gem_line.rb', line 20 def existing_gem_line_index lines.index do |line| ::Avm::EacRubyBase1::Rubygems::Gemspec::DEPENDENCY_LINE_PARSER.parse(line) .if_present(&:first) == gem_name end end |
#gem_line_prefix ⇒ String
56 57 58 |
# File 'lib/avm/eac_ruby_base1/rubygems/gemspec/add_or_replace_gem_line.rb', line 56 def gem_line_prefix format(DEPENDENCY_PREFIX, { dependency_type: dependency_type, gem_name: gem_name }) end |
#gems_lines_start_index ⇒ Integer
47 48 49 |
# File 'lib/avm/eac_ruby_base1/rubygems/gemspec/add_or_replace_gem_line.rb', line 47 def gems_lines_start_index existing_gem_line_index || (lines.count - 1) end |
#new_gem_line ⇒ Object
51 52 53 |
# File 'lib/avm/eac_ruby_base1/rubygems/gemspec/add_or_replace_gem_line.rb', line 51 def new_gem_line ([gem_line_prefix] + quoted_gem_specs).join(', ') end |
#quoted_gem_specs ⇒ Object
64 65 66 |
# File 'lib/avm/eac_ruby_base1/rubygems/gemspec/add_or_replace_gem_line.rb', line 64 def quoted_gem_specs gem_specs.map { |gem_spec| "'#{gem_spec}'" } end |
#replace_line ⇒ Object
60 61 62 |
# File 'lib/avm/eac_ruby_base1/rubygems/gemspec/add_or_replace_gem_line.rb', line 60 def replace_line lines[existing_gem_line_index] = new_gem_line end |
#result ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/avm/eac_ruby_base1/rubygems/gemspec/add_or_replace_gem_line.rb', line 27 def result if existing_gem_line_index.present? replace_line else add_line end end |