Module: Boson::Commands::WebCore
Defined Under Namespace
Classes: Get
Class Method Summary collapse
-
.def_which_requires(meth, *libs, &block) ⇒ Object
Requires libraries only once before defining method with given block.
Instance Method Summary collapse
-
#browser(*urls) ⇒ Object
non-mac users should override this with the launchy gem.
-
#config ⇒ Object
:nodoc:.
-
#install(url, options = {}) ⇒ Object
:nodoc:.
Class Method Details
.def_which_requires(meth, *libs, &block) ⇒ Object
Requires libraries only once before defining method with given block
24 25 26 27 28 29 |
# File 'lib/boson/commands/web_core.rb', line 24 def self.def_which_requires(meth, *libs, &block) define_method(meth) do |*args| libs.each {|e| require e } define_method(meth, block).call(*args) end end |
Instance Method Details
#browser(*urls) ⇒ Object
non-mac users should override this with the launchy gem
65 66 67 |
# File 'lib/boson/commands/web_core.rb', line 65 def browser(*urls) system('open', *urls) end |
#config ⇒ Object
:nodoc:
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/boson/commands/web_core.rb', line 4 def config #:nodoc: commands = { 'get'=>{ :desc=>"Gets the body of a url", :args=>[['url'],['options', {}]]}, 'post'=>{ :desc=>'Posts to a url', :args=>[['url'],['options', {}]]}, 'build_url'=>{ :desc=>"Builds a url, escaping the given params", :args=>[['url'],['params']]}, 'browser'=>{ :desc=>"Opens urls in a browser on a Mac"}, 'install'=>{ :desc=>"Installs a library by url. Library should then be loaded with load_library.", :args=>[['url'],['options', {}]], :options=> { :name=>{:type=>:string, :desc=>"Library name to save to"}, :force=>{:type=>:boolean, :desc=>'Overwrites an existing library'}, :default=>{:type=>:boolean, :desc=>'Adds library as a default library to main config file'}, :module_wrap=>{:type=>:boolean, :desc=>"Wraps a module around install using library name"}, :method_wrap=>{:type=>:boolean, :desc=>"Wraps a method and module around installed library using library name"}} } } {:library_file=>File.(__FILE__), :commands=>commands, :namespace=>false} end |
#install(url, options = {}) ⇒ Object
:nodoc:
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/boson/commands/web_core.rb', line 49 def install(url, ={}) #:nodoc: [:name] ||= strip_name_from_url(url) return puts("Please give a library name for this url.") if [:name].empty? filename = File.join ::Boson.repo.commands_dir, "#{[:name]}.rb" return puts("Library name #{[:name]} already exists. Try a different name.") if File.exists?(filename) && ![:force] file_string = get(url) or raise "Unable to fetch url" file_string = "# Originally from #{url}\n"+file_string file_string = wrap_install(file_string, ) if [:method_wrap] || [:module_wrap] File.open(filename, 'w') {|f| f.write file_string } Boson.repo.update_config {|c| (c[:defaults] ||= []) << [:name] } if [:default] puts "Saved to #{filename}." end |