Class: Scryglass::ViewWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/scryglass/view_wrapper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, string: nil, string_lambda: nil) ⇒ ViewWrapper

Returns a new instance of ViewWrapper.



7
8
9
10
11
12
13
14
15
16
# File 'lib/scryglass/view_wrapper.rb', line 7

def initialize(model, string: nil, string_lambda: nil)
  unless !!string ^ !!string_lambda
    raise ArgumentError, 'Must provide either `string` or `string_lambda`, ' \
                         'but not both.'
  end

  self.model = model
  self.string = string
  self.string_lambda = string_lambda
end

Instance Attribute Details

#modelObject

Returns the value of attribute model.



5
6
7
# File 'lib/scryglass/view_wrapper.rb', line 5

def model
  @model
end

#stringObject

Returns the value of attribute string.



5
6
7
# File 'lib/scryglass/view_wrapper.rb', line 5

def string
  @string
end

#string_lambdaObject

Returns the value of attribute string_lambda.



5
6
7
# File 'lib/scryglass/view_wrapper.rb', line 5

def string_lambda
  @string_lambda
end

Instance Method Details

#to_sObject



18
19
20
21
# File 'lib/scryglass/view_wrapper.rb', line 18

def to_s
  return string if string
  return string_lambda.call(model) if string_lambda
end