class Ember::Generators::InstallGenerator
Constants
- ConflictingOptions
- InsufficientOptions
- InvalidChannel
Public Class Methods
new(args = [], options = {}, config = {})
click to toggle source
Calls superclass method
# File lib/generators/ember/install_generator.rb, line 43 def initialize(args = [], options = {}, config = {}) super(args, options, config) check_options process_options end
Public Instance Methods
ember()
click to toggle source
# File lib/generators/ember/install_generator.rb, line 49 def ember unless options.ember_data_only? get_ember_js_for(:development) get_ember_js_for(:production) end rescue Thor::Error say('WARNING: no ember files on this channel or tag', :yellow) end
ember_data()
click to toggle source
# File lib/generators/ember/install_generator.rb, line 58 def ember_data unless options.ember_only? get_ember_data_for(:development) get_ember_data_for(:production) end rescue Thor::Error say('WARNING: no ember-data files on this channel or tag', :yellow) end
Private Instance Methods
base_url()
click to toggle source
# File lib/generators/ember/install_generator.rb, line 140 def base_url 'http://builds.emberjs.com' end
channel()
click to toggle source
# File lib/generators/ember/install_generator.rb, line 144 def channel @channel ||= if options.channel options[:channel] else :release end end
check_options()
click to toggle source
# File lib/generators/ember/install_generator.rb, line 111 def check_options say('WARNING: --head option is deprecated in favor of --channel=canary', :yellow) if options.head? if options.head? && options.channel? say 'ERROR: conflicting options. --head and --channel. Use either --head or --channel=<channel>', :red raise ConflictingOptions end if options.channel? && !%w[release beta canary].include?(options[:channel]) say 'ERROR: channel can either be release, beta or canary', :red raise InvalidChannel end if options.channel? && options.tag? say 'ERROR: conflicting options. --tag and --channel. --tag is incompatible with other options', :red raise ConflictingOptions end if options.head? && options.tag? say 'ERROR: conflicting options. --tag and --head. --tag is incompatible with other options', :red raise ConflictingOptions end if options.tag? && !(options.ember_only? || options.ember_data_only?) say 'ERROR: insufficient options. --tag needs to be combined with eithe --ember or --ember-data', :red raise InsufficientOptions end end
fetch(from, to, prepend_verbose = true)
click to toggle source
# File lib/generators/ember/install_generator.rb, line 152 def fetch(from, to, prepend_verbose = true) message = "#{from} -> #{to}" say_status('downloading:', message, :green) uri = URI(from) output = StringIO.new if prepend_verbose output.puts "// Fetched from channel: #{channel}, with url " + uri.to_s output.puts "// Fetched on: #{Time.now.utc.iso8601}" end response = Net::HTTP.get_response(uri) case response.code when '404' say "ERROR: Error reading the content from the channel with url #{from}. File not found", :red raise Thor::Error when '200' output.puts response.body.force_encoding('UTF-8') else say "ERROR: Unexpected error with status #{response.code} reading the content from the channel with url #{from}.", :red raise Thor::Error end output.rewind output.read end
get_ember_data_for(environment)
click to toggle source
# File lib/generators/ember/install_generator.rb, line 69 def get_ember_data_for(environment) create_file "vendor/assets/ember/#{environment}/ember-data.js" do fetch url_for(channel, 'ember-data', environment), "vendor/assets/ember/#{environment}/ember-data.js" end sourcemap_url = "#{base_url}/#{channel}/ember-data.js.map" if resource_exist?(sourcemap_url) create_file "vendor/assets/ember/#{environment}/ember-data.js.map" do fetch sourcemap_url, "vendor/assets/ember/#{environment}/ember-data.js.map", false end end end
get_ember_js_for(environment)
click to toggle source
# File lib/generators/ember/install_generator.rb, line 82 def get_ember_js_for(environment) create_file "vendor/assets/ember/#{environment}/ember.js" do fetch url_for(channel, 'ember', environment), "vendor/assets/ember/#{environment}/ember.js" end compiler_url = "#{base_url}/#{channel}/ember-template-compiler.js" if resource_exist?(compiler_url) create_file "vendor/assets/ember/#{environment}/ember-template-compiler.js" do fetch "#{base_url}/#{channel}/ember-template-compiler.js", "vendor/assets/ember/#{environment}/ember-template-compiler.js" end end end
process_options()
click to toggle source
# File lib/generators/ember/install_generator.rb, line 135 def process_options @channel = :canary if options.head? @channel = "tags/#{options.tag}" if options.tag? end
resource_exist?(target)
click to toggle source
# File lib/generators/ember/install_generator.rb, line 179 def resource_exist?(target) uri = URI(target) response = Net::HTTP.new(uri.host, uri.port).head(uri.path) response.code == '200' end
url_for(channel, component, environment)
click to toggle source
# File lib/generators/ember/install_generator.rb, line 96 def url_for(channel, component, environment) base = "#{base_url}/#{channel}/#{component}" case environment when :production "#{base}.prod.js" when :development if resource_exist?("#{base}.debug.js") "#{base}.debug.js" # Ember.js 1.10.0.beta.1 or later else "#{base}.js" end end end