Class: SC::Rack::Dev

Inherits:
Object
  • Object
show all
Defined in:
lib/sproutcore/rack/dev.rb

Overview

Hosts general dev environment-related JSON assets.

Instance Method Summary collapse

Constructor Details

#initialize(project) ⇒ Dev

Returns a new instance of Dev.



16
17
18
# File 'lib/sproutcore/rack/dev.rb', line 16

def initialize(project)
  @project = project
end

Instance Method Details

#call(env) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/sproutcore/rack/dev.rb', line 20

def call(env)
  url = env['PATH_INFO']
  case url
  when '/sc/targets.json' # returns description of targets
    return [200, {}, get_targets_json]
  else
    return [404, {}, "not found"]
  end
    
  return [404, {}, "not found"]
end

#get_targets_jsonObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/sproutcore/rack/dev.rb', line 32

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_docs"  => [target.url_root, 'en', target.build_number, 'docs', '-index.json'].join('/'),
      "link_root" => target.url_root
    }
  end
  targets.to_json
end