Class: Relay::Attachment

Inherits:
Object
  • Object
show all
Defined in:
lib/relay/attachment.rb,
lib/relay/attachment/session.rb

Defined Under Namespace

Classes: Session

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name: nil, path: nil, type: nil) ⇒ Attachment

Returns a new instance of Attachment.

Parameters:

  • name (String, nil) (defaults to: nil)
  • path (String, nil) (defaults to: nil)
  • type (String, nil) (defaults to: nil)


20
21
22
23
24
# File 'lib/relay/attachment.rb', line 20

def initialize(name: nil, path: nil, type: nil)
  @name = name.to_s
  @path = path.to_s
  @type = type.to_s
end

Instance Attribute Details

#nameString (readonly)

Returns:

  • (String)


28
29
30
# File 'lib/relay/attachment.rb', line 28

def name
  @name
end

#pathString (readonly)

Returns:

  • (String)


32
33
34
# File 'lib/relay/attachment.rb', line 32

def path
  @path
end

#typeString (readonly)

Returns:

  • (String)


36
37
38
# File 'lib/relay/attachment.rb', line 36

def type
  @type
end

Class Method Details

.session(session:, root:, user: nil, provider: nil) ⇒ Relay::Attachment::Session

Parameters:

  • session (Hash)
  • root (String)
  • user (Object, nil) (defaults to: nil)
  • provider (String, nil) (defaults to: nil)

Returns:



12
13
14
# File 'lib/relay/attachment.rb', line 12

def self.session(session:, root:, user: nil, provider: nil)
  Session.new(session:, root:, user:, provider:)
end

Instance Method Details

#attached?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/relay/attachment.rb', line 46

def attached?
  file?
end

#file?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/relay/attachment.rb', line 40

def file?
  !path.empty? && File.file?(path)
end

#to_hHash<String, String>

Returns:

  • (Hash<String, String>)


52
53
54
# File 'lib/relay/attachment.rb', line 52

def to_h
  {"name" => name, "path" => path, "type" => type}
end