Class: Neurogami::Andi
- Inherits:
-
Object
- Object
- Neurogami::Andi
- Defined in:
- lib/andi.rb,
lib/andi/andi.rb
Constant Summary collapse
- VERSION =
:stopdoc:
'0.1.4'
- LIBPATH =
::File.(::File.dirname(__FILE__)) + ::File::SEPARATOR
- PATH =
::File.dirname(LIBPATH) + ::File::SEPARATOR
- REQUIRED_VALUES_ERROR_MSGS =
{ :project_name => "Missing project name.", :base_package => "Missing base package name.", :target => "Missing target." }
Class Method Summary collapse
- .errors ⇒ Object
-
.help(message = nil) ⇒ Object
Need this?.
-
.libpath(*args) ⇒ Object
Returns the library path for the module.
-
.path(*args) ⇒ Object
Returns the lpath for the module.
-
.project(options_hash) ⇒ Object
Useful values: :base_package (i.e. com.neurogami ) :main_activity :target :output_path :project_name.
- .rakefile(options_hash) ⇒ Object
-
.require_all_libs_relative_to(fname, dir = nil) ⇒ Object
Utility method used to require all files ending in .rb that lie in the directory below this file that has the same name as the filename passed in.
- .valid_options?(options_hash) ⇒ Boolean
-
.version ⇒ Object
Returns the version string for the library.
Class Method Details
.errors ⇒ Object
23 24 25 |
# File 'lib/andi/andi.rb', line 23 def self.errors @@errors ||= [] end |
.help(message = nil) ⇒ Object
Need this?
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/andi/andi.rb', line 12 def self.help = nil puts + "\\\n-----------------------------------\\\n" unless .nil? puts %~ Usage: andi <projectName> <MainActivity> [path=./] The project name must be suitable for a Java package name. Allowed characters are: a-z A-Z 0-9 _ ~ end |
.libpath(*args) ⇒ Object
Returns the library path for the module. If any arguments are given, they will be joined to the end of the libray path using File.join
.
21 22 23 |
# File 'lib/andi.rb', line 21 def self.libpath( *args ) args.empty? ? LIBPATH : ::File.join(LIBPATH, args.flatten) end |
.path(*args) ⇒ Object
Returns the lpath for the module. If any arguments are given, they will be joined to the end of the path using File.join
.
29 30 31 |
# File 'lib/andi.rb', line 29 def self.path( *args ) args.empty? ? PATH : ::File.join(PATH, args.flatten) end |
.project(options_hash) ⇒ Object
Useful values:
:base_package (i.e. com.neurogami )
:main_activity
:target
:output_path
:project_name
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/andi/andi.rb', line 42 def self.project [:output_path] = "." if [:output_path].to_s.empty? [:output_path].sub!( /\/$/, '') #options_hash[:main_activity] #options_hash[:target] # cmd = "android create project --package #{[:base_package]}.#{[:project_name]} --activity #{[:main_activity]} --target #{[:target]} --path #{[:output_path]}/#{[:project_name]} " puts `#{cmd}` File.open( "#{[:output_path]}/#{[:project_name]}/Rakefile", 'w'){ |f| f.puts(rakefile )} end |
.rakefile(options_hash) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/andi/andi.rb', line 58 def self.rakefile %~ namespace :avd do desc 'List AVDs' task :list do warn `android avd list` end end namespace :app do desc "uninstall the app" task :uninstall do warn ` adb shell pm uninstall -k #{[:base_package]}.#{[:project_name]}` end desc 'Compile debug version' task :debug do warn `ant debug` end desc 'Compile release version' task :release do warn `ant release` end desc 'Install debug version' task 'install-debug' do warn `adb install ./bin/#{[:main_activity]}-debug.apk ` end desc 'Install release version' task 'install-release' do warn `adb install ./bin/#{[:main_activity]}-unsigned.apk ` end desc 'Re-compile and re-install debug version' task 'debug-reinstall' => [:debug, :uninstall , :'debug-install'] do end desc 'Re-compile and re-install release version' task 'debug-reinstall' => [:release, :uninstall , :'release-install'] do end def save_prefs options File.open(ANDI_CONF, 'w'){ |f| f.puts(options.to_yaml)} end def load_prefs if File.exist? ANDI_CONF YAML.load_file ANDI_CONF else {} end end namespace :avd do desc "Run emulator with avd" task :emu do andi_prefs = load_prefs andi_prefs[:avd] = ENV['AVD'] if ENV['AVD'] save_prefs andi_prefs Thread.new do puts `emulator -avd #{andi_prefs[:avd]} &` end end desc "List available AVDs" task :list do sh %{ android list avd } do |ok, res| if ! ok puts "Problems ! (status = #{res.exitstatus})" end end end end end ~ end |
.require_all_libs_relative_to(fname, dir = nil) ⇒ Object
Utility method used to require all files ending in .rb that lie in the directory below this file that has the same name as the filename passed in. Optionally, a specific directory name can be passed in such that the filename does not have to be equivalent to the directory.
38 39 40 41 42 |
# File 'lib/andi.rb', line 38 def self.require_all_libs_relative_to( fname, dir = nil ) dir ||= ::File.basename(fname, '.*') search_me = ::File.( ::File.join(::File.dirname(fname), dir, '**', '*.rb')) Dir.glob(search_me).sort.each {|rb| require rb} end |
.valid_options?(options_hash) ⇒ Boolean
27 28 29 30 31 32 33 34 |
# File 'lib/andi/andi.rb', line 27 def self. @@errors = [] REQUIRED_VALUES_ERROR_MSGS.each do |val, msg| @@errors << msg unless [val] end @@errors.empty? end |
.version ⇒ Object
Returns the version string for the library.
13 14 15 |
# File 'lib/andi.rb', line 13 def self.version VERSION end |