Class: OrganizeGemfile::Builder
- Inherits:
-
Object
- Object
- OrganizeGemfile::Builder
- Defined in:
- lib/organize_gemfile/builder.rb
Instance Attribute Summary collapse
-
#lines ⇒ Object
Returns the value of attribute lines.
Instance Method Summary collapse
- #available_groups ⇒ Object
- #build ⇒ Object
- #default_group ⇒ Object
-
#initialize(gemfile_path, ruby_version:, groups:) ⇒ Builder
constructor
A new instance of Builder.
Constructor Details
#initialize(gemfile_path, ruby_version:, groups:) ⇒ Builder
Returns a new instance of Builder.
5 6 7 8 9 10 |
# File 'lib/organize_gemfile/builder.rb', line 5 def initialize(gemfile_path, ruby_version:, groups:) @gemfile_path = gemfile_path @ruby_version = ruby_version @groups = groups new_gemfile_code = build end |
Instance Attribute Details
#lines ⇒ Object
Returns the value of attribute lines.
3 4 5 |
# File 'lib/organize_gemfile/builder.rb', line 3 def lines @lines end |
Instance Method Details
#available_groups ⇒ Object
40 41 42 |
# File 'lib/organize_gemfile/builder.rb', line 40 def available_groups @groups.keys end |
#build ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/organize_gemfile/builder.rb', line 12 def build lines = [] lines << "source \"https://rubygems.org\"" lines << "git_source(:github) { |repo| \"https://github.com/\#{repo}.git\" }" lines << "" lines << "ruby \"#{@ruby_version}\"" lines << "" before_default_group = @groups["before_default"] if before_default_group lines << before_default_group.to_gemfile_lines lines << "" end default_group = @groups["default"] if default_group lines << default_group.to_gemfile_lines lines << "" end @groups.select { |name, _group| name != "before_default" && name != "default" }.each do |_name, group| lines << group.to_gemfile_lines lines << "" end lines.join("\n") end |
#default_group ⇒ Object
44 45 46 |
# File 'lib/organize_gemfile/builder.rb', line 44 def default_group @groups["default"] end |