Skip to content

Commit 05a62d9

Browse files
committed
Merge pull request #47 from Shuttlerock/override-max-size-attribute
Allow to pass max_size attribute
2 parents 58d8aff + 1733c47 commit 05a62d9

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

lib/transloadit/rails/engine.rb

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,25 +45,38 @@ def self.configuration
4545
#
4646
# Returns the Transloadit authentication object.
4747
#
48-
def self.transloadit
48+
# options - The Hash options used to refine the auth params (default: {}):
49+
# :max_size - The Integer maximum size an upload can have in bytes (optional).
50+
def self.transloadit(options = {})
4951
Transloadit.new(
5052
:key => self.configuration['auth']['key'],
5153
:secret => self.configuration['auth']['secret'],
5254
:duration => self.configuration['auth']['duration'],
53-
:max_size => self.configuration['auth']['max_size']
55+
:max_size => options[:max_size] || self.configuration['auth']['max_size']
5456
)
5557
end
5658

5759
#
5860
# Creates an assembly for the named template.
5961
#
62+
# name - The String or Symbol template name.
63+
# options - The Hash options used to refine the Assembly (default: {}):
64+
# :steps - The Hash with Assembly Steps (optional).
65+
# :max_size - The Integer maximum size an upload can have in bytes (optional).
6066
def self.template(name, options = {})
67+
transloadit = self.transloadit(
68+
:max_size => options.delete(:max_size)
69+
)
70+
6171
template = self.configuration['templates'].try(:fetch, name.to_s)
72+
assembly_options = case template
73+
when String
74+
{ :template_id => template }.merge(options)
75+
when Hash
76+
template.merge(options)
77+
end
6278

63-
self.transloadit.assembly case template
64-
when String then { :template_id => template }.merge(options)
65-
when Hash then template .merge(options)
66-
end
79+
transloadit.assembly(assembly_options)
6780
end
6881

6982
#

lib/transloadit/rails/view_helper.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ module Transloadit::Rails::ViewHelper
55
# Inserts hidden fields specifying and signing the template for Transloadit
66
# to process.
77
#
8+
# template - The String or Symbol template name.
9+
# options - The Hash options used to refine the Assembly (default: {}):
10+
# :steps - The Hash with Assembly Steps (optional).
11+
# :max_size - The Integer maximum size an upload can have in bytes (optional).
812
def transloadit(template, options = {})
913
params = Transloadit::Rails::Engine.template(template, options).to_json
1014
fields = hidden_field_tag(:params, params, :id => nil)

0 commit comments

Comments
 (0)