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'
Instance Method Summary collapse
- #add_line ⇒ Object
- #add_line_index ⇒ Object
- #existing_gem_line_index ⇒ Object
- #gem_line_prefix ⇒ Object
- #gems_lines_start_index ⇒ Object
- #new_gem_line ⇒ Object
- #quoted_gem_specs ⇒ Object
- #replace_line ⇒ Object
- #result ⇒ Object
Instance Method Details
#add_line ⇒ Object
28 29 30 |
# File 'lib/avm/eac_ruby_base1/rubygems/gemspec/add_or_replace_gem_line.rb', line 28 def add_line lines.insert(add_line_index, new_gem_line) end |
#add_line_index ⇒ Object
32 33 34 35 36 37 |
# File 'lib/avm/eac_ruby_base1/rubygems/gemspec/add_or_replace_gem_line.rb', line 32 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 ⇒ Object
16 17 18 |
# File 'lib/avm/eac_ruby_base1/rubygems/gemspec/add_or_replace_gem_line.rb', line 16 def existing_gem_line_index lines.index { |line| line.start_with?(gem_line_prefix) } end |
#gem_line_prefix ⇒ Object
47 48 49 |
# File 'lib/avm/eac_ruby_base1/rubygems/gemspec/add_or_replace_gem_line.rb', line 47 def gem_line_prefix "#{DEPENDENCY_PREFIX} '#{gem_name}'" end |
#gems_lines_start_index ⇒ Object
39 40 41 |
# File 'lib/avm/eac_ruby_base1/rubygems/gemspec/add_or_replace_gem_line.rb', line 39 def gems_lines_start_index lines.index { |line| line.start_with?(DEPENDENCY_PREFIX) } || lines.count end |
#new_gem_line ⇒ Object
43 44 45 |
# File 'lib/avm/eac_ruby_base1/rubygems/gemspec/add_or_replace_gem_line.rb', line 43 def new_gem_line ([gem_line_prefix] + quoted_gem_specs).join(', ') end |
#quoted_gem_specs ⇒ Object
55 56 57 |
# File 'lib/avm/eac_ruby_base1/rubygems/gemspec/add_or_replace_gem_line.rb', line 55 def quoted_gem_specs gem_specs.map { |gem_spec| "'#{gem_spec}'" } end |
#replace_line ⇒ Object
51 52 53 |
# File 'lib/avm/eac_ruby_base1/rubygems/gemspec/add_or_replace_gem_line.rb', line 51 def replace_line lines[existing_gem_line_index] = new_gem_line end |
#result ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/avm/eac_ruby_base1/rubygems/gemspec/add_or_replace_gem_line.rb', line 20 def result if existing_gem_line_index.present? replace_line else add_line end end |