Class: Referee::ViewController

Inherits:
Renderable show all
Defined in:
lib/referee/renderables/viewcontroller.rb

Overview

Renderable implementation for UIViewControllers embedded in storyboards.

Instance Attribute Summary collapse

Attributes inherited from Renderable

#swift_type, #type

Instance Method Summary collapse

Methods inherited from Renderable

#bundle_accessor, #methodize_name, #simple_method_declaration, #simple_method_implementation, #simple_swift_method, #simple_swift_string_case, #swift_bundle_accessor

Constructor Details

#initialize(name, klass, storyboard, config) ⇒ ViewController



6
7
8
9
10
11
12
13
# File 'lib/referee/renderables/viewcontroller.rb', line 6

def initialize(name, klass, storyboard, config)
  @name = name
  @class = klass
  @storyboard = storyboard
  @type = "#{@class} *"
  @swift_type = @class
  @config = config
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



4
5
6
# File 'lib/referee/renderables/viewcontroller.rb', line 4

def config
  @config
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/referee/renderables/viewcontroller.rb', line 4

def name
  @name
end

#storyboardObject

Returns the value of attribute storyboard.



4
5
6
# File 'lib/referee/renderables/viewcontroller.rb', line 4

def storyboard
  @storyboard
end

Instance Method Details

#declarationObject



19
20
21
# File 'lib/referee/renderables/viewcontroller.rb', line 19

def declaration
  simple_method_declaration method_name
end

#implementationObject



23
24
25
26
27
28
# File 'lib/referee/renderables/viewcontroller.rb', line 23

def implementation
  bundle = bundle_accessor(@config.bundle_id)
  body = "(#{@type})[[UIStoryboard storyboardWithName:@\"#{@storyboard}\" bundle:#{bundle}] " \
         "instantiateViewControllerWithIdentifier:@\"#{@name}\"]"
  simple_method_implementation method_name, body
end

#method_nameObject



15
16
17
# File 'lib/referee/renderables/viewcontroller.rb', line 15

def method_name
  "new#{@name}"
end

#swift_implementationObject



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/referee/renderables/viewcontroller.rb', line 30

def swift_implementation
  bundle = swift_bundle_accessor(@config.bundle_id)

  if @swift_type == 'UIViewController'
    cast = ''
  else
    cast = " as! #{@swift_type}"
  end

  body = "UIStoryboard(name: \"#{@storyboard}\", bundle: #{bundle})." \
         "instantiateViewControllerWithIdentifier(\"#{@name}\")#{cast}"
  simple_swift_method method_name, body
end