Class: CanvasApi::Render

Inherits:
Object
  • Object
show all
Includes:
GraphQLHelpers, JsHelpers, RubyHelpers
Defined in:
lib/canvas_api/render.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RubyHelpers

#ruby_api_url

Methods included from JsHelpers

#js_args, #js_url_parts, #key_args, #parameters_doc, #reducer_key

Methods included from GraphQLHelpers

#graphql_fields, #graphql_primitive, #graphql_resolve, #graphql_type, #safe_js

Constructor Details

#initialize(template, api, resource, resource_api, operation, parameters, content, model) ⇒ Render

Returns a new instance of Render.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/canvas_api/render.rb', line 15

def initialize(template, api, resource, resource_api, operation, parameters, content, model)
  @template = File.read(File.expand_path(template, __dir__))
  if api
    @api         = api
    @name        = @api["path"].gsub("/", "").gsub(".json", "")
    @description = @api["description"]
  end
  if resource
    @resource      = resource
    @resource_name = resource["resourcePath"].gsub("/", "")
  end
  if resource_api
    @resource_api = resource_api
    @api_url      = resource_api["path"].gsub("/v1/", "")
    @args         = args(@api_url)
  end
  if operation
    nickname = operation["nickname"]
    nickname = "#{@name}_#{nickname}" if [
      "upload_file",
      "query_by_course",
      "preview_processed_html",
      "create_peer_review_courses",
      "create_peer_review_sections",
      "set_extensions_for_student_quiz_submissions"
    ].include?(nickname)

    @method    = operation["method"]
    @operation = operation
    @nickname  = nickname
    @notes     = operation["notes"].gsub("\n", "\n// ")
    @summary   = operation["summary"]
  end
  if parameters
    @parameters = parameters.map { |p| p.delete("description"); p }
  end
  @content = content
  @model = model
end

Instance Attribute Details

#api ⇒ Object

Returns the value of attribute api.



11
12
13
# File 'lib/canvas_api/render.rb', line 11

def api
  @api
end

#api_url ⇒ Object

Returns the value of attribute api_url.



11
12
13
# File 'lib/canvas_api/render.rb', line 11

def api_url
  @api_url
end

#args(api_url) ⇒ Object

Returns the value of attribute args.



11
12
13
# File 'lib/canvas_api/render.rb', line 11

def args
  @args
end

#content ⇒ Object

Returns the value of attribute content.



11
12
13
# File 'lib/canvas_api/render.rb', line 11

def content
  @content
end

#description ⇒ Object

Returns the value of attribute description.



11
12
13
# File 'lib/canvas_api/render.rb', line 11

def description
  @description
end

#method ⇒ Object

Returns the value of attribute method.



11
12
13
# File 'lib/canvas_api/render.rb', line 11

def method
  @method
end

#model ⇒ Object

Returns the value of attribute model.



11
12
13
# File 'lib/canvas_api/render.rb', line 11

def model
  @model
end

#model_name ⇒ Object

Returns the value of attribute model_name.



11
12
13
# File 'lib/canvas_api/render.rb', line 11

def model_name
  @model_name
end

#name ⇒ Object

Returns the value of attribute name.



11
12
13
# File 'lib/canvas_api/render.rb', line 11

def name
  @name
end

#nickname ⇒ Object

Returns the value of attribute nickname.



11
12
13
# File 'lib/canvas_api/render.rb', line 11

def nickname
  @nickname
end

#notes ⇒ Object

Returns the value of attribute notes.



11
12
13
# File 'lib/canvas_api/render.rb', line 11

def notes
  @notes
end

#operation ⇒ Object

Returns the value of attribute operation.



11
12
13
# File 'lib/canvas_api/render.rb', line 11

def operation
  @operation
end

#resource ⇒ Object

Returns the value of attribute resource.



11
12
13
# File 'lib/canvas_api/render.rb', line 11

def resource
  @resource
end

#resource_api ⇒ Object

Returns the value of attribute resource_api.



11
12
13
# File 'lib/canvas_api/render.rb', line 11

def resource_api
  @resource_api
end

#resource_name ⇒ Object

Returns the value of attribute resource_name.



11
12
13
# File 'lib/canvas_api/render.rb', line 11

def resource_name
  @resource_name
end

#summary ⇒ Object

Returns the value of attribute summary.



11
12
13
# File 'lib/canvas_api/render.rb', line 11

def summary
  @summary
end

#template ⇒ Object

Returns the value of attribute template.



11
12
13
# File 'lib/canvas_api/render.rb', line 11

def template
  @template
end

Instance Method Details

#render ⇒ Object



63
64
65
# File 'lib/canvas_api/render.rb', line 63

def render
  ERB.new(@template, nil, "-").result(binding).strip
end

#save(file) ⇒ Object



67
68
69
# File 'lib/canvas_api/render.rb', line 67

def save(file)
  File.write(file, render)
end