Class: SC::Rack::Dev
Overview
Hosts general dev environment-related JSON assets.
Instance Method Summary collapse
- #call(env) ⇒ Object
- #get_greenhouse_configs(env) ⇒ Object
- #get_targets_json ⇒ Object
-
#initialize(project) ⇒ Dev
constructor
A new instance of Dev.
-
#root_dir ⇒ Object
TODO: dry this up…also exists in SC::Rack::Filesystem.
Constructor Details
#initialize(project) ⇒ Dev
Returns a new instance of Dev.
15 16 17 |
# File 'lib/sproutcore/rack/dev.rb', line 15 def initialize(project) @project = project end |
Instance Method Details
#call(env) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/sproutcore/rack/dev.rb', line 27 def call(env) url = env['PATH_INFO'] case url when '/sc/targets.json' # returns description of targets return [200, {}, get_targets_json] when '/sc/greenhouseconf.json' #returns json of all valid design objects return [200, {}, get_greenhouse_configs(env)] else return [404, {}, "not found"] end return [404, {}, "not found"] end |
#get_greenhouse_configs(env) ⇒ 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 |
# File 'lib/sproutcore/rack/dev.rb', line 58 def get_greenhouse_configs(env) rqust = ::Rack::Request.new(env) params = rqust.params app = params['app'] ? params['app'].to_sym : '' app_target = @project.target_for(app) ret = [] if(app_target) path = app_target.source_root + "/.greenhouseconf" json = File.exists?(path) ? JSON.parse(File.read(path)) : {} json[:path] = path.gsub(root_dir, "") json[:name] = app_target.target_name json[:canEdit] = true ret << json app_target..each do |target| path = target.source_root + "/.greenhouseconf" json = File.exists?(path) ? JSON.parse(File.read(path)) : {} if(path.include?(root_dir)) json[:path] = path.gsub(root_dir, "") json[:canEdit] = true else json[:canEdit] = false json[:path] = path end json[:name] = target.target_name ret << json end end return ret.to_json end |
#get_targets_json ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/sproutcore/rack/dev.rb', line 42 def get_targets_json targets = @project.targets.values.map do |target| target.prepare! parent = target.parent_target parent = parent.kind_of?(SC::Target) ? parent[:target_name] : '' { "name" => target[:target_name], "kind" => target[:target_type], "parent" => parent, "link_tests" => [target[:url_root], 'en', target[:build_number], 'tests', '-index.json'].join('/'), "link_root" => target[:url_root] } end targets.to_json end |
#root_dir ⇒ Object
TODO: dry this up…also exists in SC::Rack::Filesystem
20 21 22 23 24 25 |
# File 'lib/sproutcore/rack/dev.rb', line 20 def root_dir unless @root_dir @root_dir = @project.project_root end return @root_dir end |