Class: Nu::Api
- Inherits:
-
Object
- Object
- Nu::Api
- Defined in:
- lib/nu/api.rb
Class Method Summary collapse
- .assert_project_settings ⇒ Object
- .get_setting(name) ⇒ Object
- .install_package(package_name, package_version = nil) ⇒ Object
- .load_project_settings(settings_file) ⇒ Object
- .propose_package(package_name, package_version = nil) ⇒ Object
- .report ⇒ Object
- .retrieve_specification(name, source = {:from => :lib}) ⇒ Object
- .retrieve_specification_with_version(name, version, source = {:from => :lib}) ⇒ Object
- .set_log(logger) ⇒ Object
- .set_out(outer) ⇒ Object
- .store_setting(name, value) ⇒ Object
- .version_string ⇒ Object
Class Method Details
.assert_project_settings ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/nu/api.rb', line 69 def self.assert_project_settings if @project_settings.platform @project_settings.platform = @project_settings.platform.gsub('.','_') if !@platforms.index(@project_settings.platform) out "'#{@project_settings.platform}' is not a valid platform." out "\nChoose one of these:" @platforms.each {|p| disp " #{p}"} out "" exit 1 end end end |
.get_setting(name) ⇒ Object
82 83 84 85 |
# File 'lib/nu/api.rb', line 82 def self.get_setting(name) log "Get Setting called: name=#{name}" @project_settings.get_setting_by_path(name, @log) end |
.install_package(package_name, package_version = nil) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/nu/api.rb', line 92 def self.install_package(package_name, package_version=nil) log "Install called: package_name: #{package_name} package_version: #{package_version}." current_specs = @lib_tools.read_specs_from_lib(@project_settings.lib.location) analyzer = PackageConflictOverlapResolver.new(current_specs, @gem_tools) results = analyzer.analyze_proposal(@gem_tools.remote_spec_for(package_name, package_version)) unless results.conflict? results.suggested_packages.each do |package| loader = Nu::Loader.new(package.name, package.version, @project_settings.lib.location, @project_settings.lib.use_long_names, @out, @log) log "Installing #{package.name} (#{package.version})" if loader.load_gem loader.copy_to_lib end end out "Installed package #{(package_name + " #{package_version}").strip}" else out "Could not install #{package_name} due to conflicts. Run `propose` to see analysis." end return results end |
.load_project_settings(settings_file) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/nu/api.rb', line 29 def self.load_project_settings(settings_file) log "Load Project Settings called: settings_file=#{settings_file}" @settings_file = settings_file @platforms = ['net1_0', 'net1_1', 'net2_0', 'net3_0', 'net3_5', 'net4_0', 'mono1_0', 'mono2_0', 'silverlight_2_0', 'silverlight_3_0', 'silverlight_4_0'] @project_settings = YAML.load_file(@settings_file) if File.exist?(@settings_file) @project_settings = OpenStruct.new if @project_settings == nil Nu::SettingsExtension.mix_in(@project_settings) #set defaults just in case they didn't load @project_settings.lib = OpenStruct.new if @project_settings.lib == nil @project_settings.lib.location = './lib' if @project_settings.lib.location == nil @project_settings.lib.use_long_names = false if @project_settings.lib.use_long_names == nil if @verbose log "Project Settings:" log YAML.dump(@project_settings).gsub('!ruby/object:OpenStruct','').gsub(/\s*table:/,'').gsub('---','') log "" end @lib_tools = Nu::LibTools.new @gem_tools = Nu::GemTools.new end |
.propose_package(package_name, package_version = nil) ⇒ Object
115 116 117 118 119 120 121 122 123 124 |
# File 'lib/nu/api.rb', line 115 def self.propose_package(package_name, package_version=nil) log "Propose Package called. package_name: #{package_name} package_version: #{package_version}" current_specs = @lib_tools.read_specs_from_lib(@project_settings.lib.location) log "Current Package Specs:" current_specs.each{|spec| log "#{spec.name} (#{spec.version})"} analyzer = PackageConflictOverlapResolver.new(current_specs, @gem_tools) analyzer.analyze_proposal(@gem_tools.remote_spec_for(package_name, package_version)) end |
.report ⇒ Object
126 127 128 129 |
# File 'lib/nu/api.rb', line 126 def self.report() log "Report called." @lib_tools.read_specs_from_lib(@project_settings.lib.location) end |
.retrieve_specification(name, source = {:from => :lib}) ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/nu/api.rb', line 144 def self.retrieve_specification(name, source = {:from => :lib}) log "Retrieve Specification called. Name: #{name} Source: #{source}" return case source[:from] when :lib then installed = @lib_tools.read_specs_from_lib(@project_settings.lib.location) installed.select{|spec| spec.name == name}.first when :cache then @gem_tools.spec_for(name) when :remote then @gem_tools.remote_spec_for(name) else raise "source can only be :lib, :cache, or :remote" end end |
.retrieve_specification_with_version(name, version, source = {:from => :lib}) ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/nu/api.rb', line 131 def self.retrieve_specification_with_version(name, version, source = {:from => :lib}) log "Retrieve Specification With Version called. Name: #{name} Version: #{version} Source: #{source}" return case source[:from] when :cache then @gem_tools.spec_for(name, version) when :remote then @gem_tools.remote_spec_for(name, version) else raise "source can only be :cache, or :remote" end end |
.set_log(logger) ⇒ Object
21 22 23 |
# File 'lib/nu/api.rb', line 21 def self.set_log(logger) @log = logger end |
.set_out(outer) ⇒ Object
25 26 27 |
# File 'lib/nu/api.rb', line 25 def self.set_out(outer) @out = outer end |
.store_setting(name, value) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/nu/api.rb', line 57 def self.store_setting(name, value) log "Store Setting called: name=#{name} value=#{value}" @project_settings.set_setting_by_path(name, value, @log) assert_project_settings File.open(@settings_file, 'w') do |out| YAML.dump(@project_settings, out) end load_project_settings(@settings_file) end |
.version_string ⇒ Object
87 88 89 90 |
# File 'lib/nu/api.rb', line 87 def self.version_string nu_spec = @gem_tools.spec_for("nu") "Nubular, version #{nu_spec.version}" end |