Class: MVCLI::BundleProvider
- Inherits:
-
Object
- Object
- MVCLI::BundleProvider
- Defined in:
- lib/mvcli/plugins/providers/bundle_provider.rb
Instance Method Summary collapse
- #activate! ⇒ Object
- #activatefile ⇒ Object
- #builder ⇒ Object
- #dir ⇒ Object
- #gemfile ⇒ Object
- #lock ⇒ Object
- #lockfile ⇒ Object
- #plugins ⇒ Object
- #remove(gem_name) ⇒ Object
- #replace(name, options = {}) ⇒ Object
- #setupfile ⇒ Object
- #update!(name) ⇒ Object
- #value ⇒ Object
- #write! ⇒ Object
Instance Method Details
#activate! ⇒ Object
8 9 10 |
# File 'lib/mvcli/plugins/providers/bundle_provider.rb', line 8 def activate! require activatefile if activatefile.exist? end |
#activatefile ⇒ Object
55 56 57 |
# File 'lib/mvcli/plugins/providers/bundle_provider.rb', line 55 def activatefile dir.join 'activate.rb' end |
#builder ⇒ Object
63 64 65 66 67 |
# File 'lib/mvcli/plugins/providers/bundle_provider.rb', line 63 def builder @builder ||= Bundler::Dsl.new.tap do |builder| builder.eval_gemfile gemfile end end |
#dir ⇒ Object
59 60 61 |
# File 'lib/mvcli/plugins/providers/bundle_provider.rb', line 59 def dir config.directory('plugins') end |
#gemfile ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/mvcli/plugins/providers/bundle_provider.rb', line 37 def gemfile dir.join('Gemfile').tap do |path| unless path.exist? path.open "wb" do |file| file.puts "source 'https://rubygems.org'" end end end end |
#lock ⇒ Object
69 70 71 72 |
# File 'lib/mvcli/plugins/providers/bundle_provider.rb', line 69 def lock require 'bundler' Bundler::LockfileParser.new lockfile.read end |
#lockfile ⇒ Object
47 48 49 |
# File 'lib/mvcli/plugins/providers/bundle_provider.rb', line 47 def lockfile dir.join 'Gemfile.lock' end |
#plugins ⇒ Object
31 32 33 34 35 |
# File 'lib/mvcli/plugins/providers/bundle_provider.rb', line 31 def plugins lock.specs.select do |spec| builder.dependencies.detect { |dep| dep.name == spec.name } end end |
#remove(gem_name) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/mvcli/plugins/providers/bundle_provider.rb', line 21 def remove(gem_name) require 'bundler' dep = builder.dependencies.find { |d| d.name == gem_name } fail "#{gem_name} is not an installed plugin" unless dep builder.dependencies.reject! { |d| d == dep } update! gem_name write! return dep end |
#replace(name, options = {}) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/mvcli/plugins/providers/bundle_provider.rb', line 12 def replace(name, = {}) require 'bundler' builder.dependencies.reject! { |dep| dep.name == name } dep, *rest = builder.gem name, update! name write! return dep end |
#setupfile ⇒ Object
51 52 53 |
# File 'lib/mvcli/plugins/providers/bundle_provider.rb', line 51 def setupfile dir.join 'bundle/bundler/setup.rb' end |
#update!(name) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/mvcli/plugins/providers/bundle_provider.rb', line 100 def update!(name) path = Bundler.settings[:path] original_definition_method = Bundler.method(:definition) Bundler.with_clean_env do ENV['BUNDLE_GEMFILE'] = gemfile.to_s definition = builder.to_definition(lockfile, name => true) Bundler.settings[:path] = dir.join('bundle').to_s Dir.chdir dir do Bundler.define_singleton_method(:definition) { definition } Bundler::Installer.install dir, definition, standalone: [], "update" => true end end ensure Bundler.define_singleton_method(:definition, &original_definition_method) Bundler.settings[:path] = path end |
#value ⇒ Object
4 5 6 |
# File 'lib/mvcli/plugins/providers/bundle_provider.rb', line 4 def value self end |
#write! ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/mvcli/plugins/providers/bundle_provider.rb', line 74 def write! gemfile.open "w" do |file| file.puts "source 'https://rubygems.org'" builder.dependencies.each do |dep| file << %|gem "#{dep.name}"| if req = dep.requirements_list.first file << %|, "#{req}"| end = dep.source ? dep.source. || {} : {} = Hash[.map { |k, v| [k,v.to_s]}] .merge! "require" => dep.autorequire if dep.autorequire file << %|, #{.inspect}| file << "\n" end end activatefile.open "w" do |file| file.puts "require #{setupfile.to_s.inspect}" builder.dependencies.each do |dep| require_names = dep.autorequire || [dep.name] require_names.each do |name| file.puts "require #{name.inspect}" end end end end |