Class: Attachie::Attachment

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

Defined Under Namespace

Classes: Version

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, name, options) ⇒ Attachment

Returns a new instance of Attachment.



123
124
125
126
127
# File 'lib/attachie.rb', line 123

def initialize(object, name, options)
  self.object = object
  self.name = name
  self.options = options
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



139
140
141
142
143
# File 'lib/attachie.rb', line 139

def method_missing(method_name, *args, &block)
  return options[method_name.to_sym] if options.key?(method_name.to_sym)

  super
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



121
122
123
# File 'lib/attachie.rb', line 121

def name
  @name
end

#objectObject

Returns the value of attribute object.



121
122
123
# File 'lib/attachie.rb', line 121

def object
  @object
end

#optionsObject

Returns the value of attribute options.



121
122
123
# File 'lib/attachie.rb', line 121

def options
  @options
end

Instance Method Details

#inspectObject



149
150
151
# File 'lib/attachie.rb', line 149

def inspect
  to_s
end

#respond_to_missing?(method_name, *args) ⇒ Boolean

Returns:

  • (Boolean)


145
146
147
# File 'lib/attachie.rb', line 145

def respond_to_missing?(method_name, *args)
  options.key?(method_name.to_sym)
end

#version(version_name, opts = {}) ⇒ Object

Raises:



129
130
131
132
133
# File 'lib/attachie.rb', line 129

def version(version_name, opts = {})
  raise(NoSuchVersion, "No such version: #{version_name}") unless options[:versions][version_name]

  Version.new self, version_name, opts
end

#versionsObject



135
136
137
# File 'lib/attachie.rb', line 135

def versions
  options[:versions].collect { |version_name, _| version version_name }
end