Class: Hem::Plugins
- Inherits:
-
Object
- Object
- Hem::Plugins
- Defined in:
- lib/hem/plugins.rb
Instance Method Summary collapse
- #check ⇒ Object
- #define(&block) ⇒ Object
-
#initialize(path, gemfile, lockfile = nil) ⇒ Plugins
constructor
A new instance of Plugins.
- #install(options = {}) ⇒ Object
- #require ⇒ Object
- #setup ⇒ Object
- #setup? ⇒ Boolean
- #update(unlock = true, options = {}) ⇒ Object
Constructor Details
#initialize(path, gemfile, lockfile = nil) ⇒ Plugins
Returns a new instance of Plugins.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/hem/plugins.rb', line 8 def initialize(path, gemfile, lockfile = nil) @is_setup = false @gemfile = gemfile @definitionBlocks = [] if lockfile.nil? @lockfile = "#{gemfile}.lock" else @lockfile = lockfile end @old_root = Bundler.method(:root) def Bundler.root(path = nil) @root = Pathname.new(path) if path @root end Bundler.root path @definition = nil end |
Instance Method Details
#check ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/hem/plugins.rb', line 46 def check return false unless File.exist?(File.join(Bundler.root, @lockfile)) begin missing_specs = definition.missing_specs.any? rescue Bundler::GemNotFound, Bundler::VersionConflict, Bundler::GitError missing_specs = true end # clear the definition after the check, so install/upgrade re-evaluates @definition = nil return !missing_specs end |
#define(&block) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/hem/plugins.rb', line 39 def define(&block) raise Hem::PluginsAlreadySetupError if @is_setup @definitionBlocks << block self end |
#install(options = {}) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/hem/plugins.rb', line 58 def install( = {}) return self if definition.dependencies.empty? opts = .dup opts[:system] = true ui = opts.delete(:ui) { Bundler::UI::Shell.new } Bundler.ui = ui begin ENV["BUNDLE_GEMFILE"] = File.join(Bundler.root, @gemfile) Bundler::Installer.install(Bundler.root, definition, opts) ENV.delete("BUNDLE_GEMFILE") Bundler::Installer..each do |name, | Hem.ui.info "Post-install message from #{name}:\n#{}" end rescue Bundler::GemNotFound => e raise e, e..sub('Gemfile', 'Hemfile'), e.backtrace rescue Bundler::GitError => e raise e, e..sub('bundle install', 'hem plugin install'), e.backtrace end self end |
#require ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/hem/plugins.rb', line 89 def require runtime = Bundler::Runtime.new(nil, definition) def runtime.clean_load_path(*); end def runtime.setup_environment(*); end; def runtime.lock(*); end; runtime.setup definition.lock(File.join(Bundler.root, @lockfile), :preserve_bundled_with => true) unless @lockfile === false runtime.require self end |
#setup ⇒ Object
28 29 30 31 32 33 |
# File 'lib/hem/plugins.rb', line 28 def setup raise Hem::PluginsAlreadySetupError if @is_setup @is_setup = true install unless check require end |
#setup? ⇒ Boolean
35 36 37 |
# File 'lib/hem/plugins.rb', line 35 def setup? @is_setup end |
#update(unlock = true, options = {}) ⇒ Object
82 83 84 85 86 87 |
# File 'lib/hem/plugins.rb', line 82 def update(unlock = true, = {}) opts = .dup opts['update'] = true definition(unlock) install(opts) end |