digital_opera 0.0.10 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/.rspec +1 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +186 -0
- data/Guardfile +15 -0
- data/README.md +35 -0
- data/Rakefile +6 -3
- data/app/helpers/digital_opera/s3_helper.rb +14 -0
- data/digital_opera.gemspec +37 -0
- data/lib/digital_opera/banker.rb +1 -1
- data/lib/digital_opera/builders/s3_form_builder.rb +118 -0
- data/lib/digital_opera/document/base.rb +0 -0
- data/lib/digital_opera/document/fields/standard.rb +185 -0
- data/lib/digital_opera/document.rb +167 -0
- data/lib/digital_opera/engine.rb +9 -0
- data/lib/digital_opera/form_object/base.rb +115 -0
- data/lib/digital_opera/form_object.rb +13 -0
- data/lib/digital_opera/presenter/base.rb +6 -0
- data/lib/digital_opera/presenter/concerns/json_serialization.rb +30 -0
- data/lib/digital_opera/presenter.rb +9 -0
- data/lib/digital_opera/services/s3.rb +148 -0
- data/lib/digital_opera/version.rb +1 -1
- data/lib/digital_opera.rb +8 -1
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +8 -0
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/javascripts/application.js +2 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.keep +0 -0
- data/spec/dummy/app/models/.keep +0 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/views/application/show.html.erb +0 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config/application.rb +23 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +29 -0
- data/spec/dummy/config/environments/production.rb +80 -0
- data/spec/dummy/config/environments/test.rb +36 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +12 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +3 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/schema.rb +16 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/public/404.html +58 -0
- data/spec/dummy/public/422.html +58 -0
- data/spec/dummy/public/500.html +57 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/spec/javascripts/helpers/.gitkeep +0 -0
- data/spec/dummy/spec/javascripts/support/jasmine.yml +116 -0
- data/spec/dummy/spec/javascripts/support/jasmine_helper.rb +10 -0
- data/spec/javascripts/spec/ellipsis_spec.js +10 -28
- data/spec/javascripts/spec/events_spec.js +15 -40
- data/spec/javascripts/spec/preload_images_spec.js +20 -32
- data/spec/javascripts/spec/tables_spec.js +3 -3
- data/spec/{banker_spec.rb → lib/digital_opera/banker_spec.rb} +4 -4
- data/spec/{base_extensions → lib/digital_opera/base_extensions}/object_spec.rb +0 -0
- data/spec/{presenter → lib/digital_opera/presenter}/base_spec.rb +0 -3
- data/spec/lib/digital_opera/services/s3_spec.rb +203 -0
- data/spec/{token_spec.rb → lib/digital_opera/token_spec.rb} +0 -0
- data/spec/spec_helper.rb +11 -5
- data/spec/support/aws.rb +5 -0
- data/spec/support/document.rb +10 -0
- data/tasks/spec.rake +5 -0
- data/tmp/rspec_guard_result +1 -0
- metadata +268 -46
- data/spec/javascripts/SpecRunner.html +0 -62
- data/spec/javascripts/lib/jasmine-1.3.1/MIT.LICENSE +0 -20
- data/spec/javascripts/lib/jasmine-1.3.1/jasmine-html.js +0 -681
- data/spec/javascripts/lib/jasmine-1.3.1/jasmine.css +0 -82
- data/spec/javascripts/lib/jasmine-1.3.1/jasmine.js +0 -2600
- data/spec/javascripts/src/digital_opera.js +0 -149
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
# Declare your gem's dependencies in digital_opera.gemspec.
|
4
|
+
# Bundler will treat runtime dependencies like base dependencies, and
|
5
|
+
# development dependencies will be added by default to the :development group.
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
# Declare any dependencies that are still in development here instead of in
|
9
|
+
# your gemspec. These might include edge Rails or gems from your path or
|
10
|
+
# Git. Remember to move these dependencies to your gemspec before releasing
|
11
|
+
# your gem to rubygems.org.
|
12
|
+
|
13
|
+
# To use debugger
|
14
|
+
# gem 'debugger'
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,186 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
digital_opera (0.0.12)
|
5
|
+
coffee-rails
|
6
|
+
rails (>= 3.1.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
actionmailer (4.0.2)
|
12
|
+
actionpack (= 4.0.2)
|
13
|
+
mail (~> 2.5.4)
|
14
|
+
actionpack (4.0.2)
|
15
|
+
activesupport (= 4.0.2)
|
16
|
+
builder (~> 3.1.0)
|
17
|
+
erubis (~> 2.7.0)
|
18
|
+
rack (~> 1.5.2)
|
19
|
+
rack-test (~> 0.6.2)
|
20
|
+
activemodel (4.0.2)
|
21
|
+
activesupport (= 4.0.2)
|
22
|
+
builder (~> 3.1.0)
|
23
|
+
activerecord (4.0.2)
|
24
|
+
activemodel (= 4.0.2)
|
25
|
+
activerecord-deprecated_finders (~> 1.0.2)
|
26
|
+
activesupport (= 4.0.2)
|
27
|
+
arel (~> 4.0.0)
|
28
|
+
activerecord-deprecated_finders (1.0.3)
|
29
|
+
activesupport (4.0.2)
|
30
|
+
i18n (~> 0.6, >= 0.6.4)
|
31
|
+
minitest (~> 4.2)
|
32
|
+
multi_json (~> 1.3)
|
33
|
+
thread_safe (~> 0.1)
|
34
|
+
tzinfo (~> 0.3.37)
|
35
|
+
arel (4.0.1)
|
36
|
+
atomic (1.1.14)
|
37
|
+
aws-sdk (1.33.0)
|
38
|
+
json (~> 1.4)
|
39
|
+
nokogiri (>= 1.4.4)
|
40
|
+
uuidtools (~> 2.1)
|
41
|
+
builder (3.1.4)
|
42
|
+
celluloid (0.15.2)
|
43
|
+
timers (~> 1.1.0)
|
44
|
+
childprocess (0.4.0)
|
45
|
+
ffi (~> 1.0, >= 1.0.11)
|
46
|
+
coderay (1.1.0)
|
47
|
+
coffee-rails (4.0.1)
|
48
|
+
coffee-script (>= 2.2.0)
|
49
|
+
railties (>= 4.0.0, < 5.0)
|
50
|
+
coffee-script (2.2.0)
|
51
|
+
coffee-script-source
|
52
|
+
execjs
|
53
|
+
coffee-script-source (1.7.0)
|
54
|
+
confstruct (0.2.5)
|
55
|
+
diff-lcs (1.2.5)
|
56
|
+
erubis (2.7.0)
|
57
|
+
execjs (2.0.2)
|
58
|
+
ffi (1.9.3)
|
59
|
+
formatador (0.2.4)
|
60
|
+
guard (2.3.0)
|
61
|
+
formatador (>= 0.2.4)
|
62
|
+
listen (~> 2.1)
|
63
|
+
lumberjack (~> 1.0)
|
64
|
+
pry (>= 0.9.12)
|
65
|
+
thor (>= 0.18.1)
|
66
|
+
guard-rspec (2.3.3)
|
67
|
+
guard (>= 1.1)
|
68
|
+
rspec (~> 2.11)
|
69
|
+
guard-spork (1.5.1)
|
70
|
+
childprocess (>= 0.2.3)
|
71
|
+
guard (>= 1.1)
|
72
|
+
spork (>= 0.8.4)
|
73
|
+
headless (1.0.1)
|
74
|
+
hike (1.2.3)
|
75
|
+
i18n (0.6.9)
|
76
|
+
jasmine (2.0.0)
|
77
|
+
jasmine-core (~> 2.0.0)
|
78
|
+
phantomjs
|
79
|
+
rack (>= 1.2.1)
|
80
|
+
rake
|
81
|
+
jasmine-core (2.0.0)
|
82
|
+
jquery-rails (2.2.2)
|
83
|
+
railties (>= 3.0, < 5.0)
|
84
|
+
thor (>= 0.14, < 2.0)
|
85
|
+
json (1.8.1)
|
86
|
+
listen (2.4.0)
|
87
|
+
celluloid (>= 0.15.2)
|
88
|
+
rb-fsevent (>= 0.9.3)
|
89
|
+
rb-inotify (>= 0.9)
|
90
|
+
lumberjack (1.0.4)
|
91
|
+
mail (2.5.4)
|
92
|
+
mime-types (~> 1.16)
|
93
|
+
treetop (~> 1.4.8)
|
94
|
+
metaclass (0.0.2)
|
95
|
+
method_source (0.8.2)
|
96
|
+
mime-types (1.25.1)
|
97
|
+
mini_portile (0.5.2)
|
98
|
+
minitest (4.7.5)
|
99
|
+
mocha (0.13.3)
|
100
|
+
metaclass (~> 0.0.1)
|
101
|
+
multi_json (1.8.4)
|
102
|
+
nokogiri (1.6.1)
|
103
|
+
mini_portile (~> 0.5.0)
|
104
|
+
phantomjs (1.9.2.1)
|
105
|
+
polyglot (0.3.3)
|
106
|
+
pry (0.9.12.6)
|
107
|
+
coderay (~> 1.0)
|
108
|
+
method_source (~> 0.8)
|
109
|
+
slop (~> 3.4)
|
110
|
+
rack (1.5.2)
|
111
|
+
rack-test (0.6.2)
|
112
|
+
rack (>= 1.0)
|
113
|
+
rails (4.0.2)
|
114
|
+
actionmailer (= 4.0.2)
|
115
|
+
actionpack (= 4.0.2)
|
116
|
+
activerecord (= 4.0.2)
|
117
|
+
activesupport (= 4.0.2)
|
118
|
+
bundler (>= 1.3.0, < 2.0)
|
119
|
+
railties (= 4.0.2)
|
120
|
+
sprockets-rails (~> 2.0.0)
|
121
|
+
railties (4.0.2)
|
122
|
+
actionpack (= 4.0.2)
|
123
|
+
activesupport (= 4.0.2)
|
124
|
+
rake (>= 0.8.7)
|
125
|
+
thor (>= 0.18.1, < 2.0)
|
126
|
+
rake (10.1.1)
|
127
|
+
rb-fsevent (0.9.4)
|
128
|
+
rb-inotify (0.9.3)
|
129
|
+
ffi (>= 0.5.0)
|
130
|
+
rspec (2.14.1)
|
131
|
+
rspec-core (~> 2.14.0)
|
132
|
+
rspec-expectations (~> 2.14.0)
|
133
|
+
rspec-mocks (~> 2.14.0)
|
134
|
+
rspec-core (2.14.7)
|
135
|
+
rspec-expectations (2.14.5)
|
136
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
137
|
+
rspec-mocks (2.14.5)
|
138
|
+
rspec-rails (2.14.1)
|
139
|
+
actionpack (>= 3.0)
|
140
|
+
activemodel (>= 3.0)
|
141
|
+
activesupport (>= 3.0)
|
142
|
+
railties (>= 3.0)
|
143
|
+
rspec-core (~> 2.14.0)
|
144
|
+
rspec-expectations (~> 2.14.0)
|
145
|
+
rspec-mocks (~> 2.14.0)
|
146
|
+
slop (3.4.7)
|
147
|
+
spork (0.9.2)
|
148
|
+
sprockets (2.10.1)
|
149
|
+
hike (~> 1.2)
|
150
|
+
multi_json (~> 1.0)
|
151
|
+
rack (~> 1.0)
|
152
|
+
tilt (~> 1.1, != 1.3.0)
|
153
|
+
sprockets-rails (2.0.1)
|
154
|
+
actionpack (>= 3.0)
|
155
|
+
activesupport (>= 3.0)
|
156
|
+
sprockets (~> 2.8)
|
157
|
+
sqlite3 (1.3.8)
|
158
|
+
thor (0.18.1)
|
159
|
+
thread_safe (0.1.3)
|
160
|
+
atomic
|
161
|
+
tilt (1.4.1)
|
162
|
+
timers (1.1.0)
|
163
|
+
treetop (1.4.15)
|
164
|
+
polyglot
|
165
|
+
polyglot (>= 0.3.1)
|
166
|
+
tzinfo (0.3.38)
|
167
|
+
uuidtools (2.1.4)
|
168
|
+
|
169
|
+
PLATFORMS
|
170
|
+
ruby
|
171
|
+
|
172
|
+
DEPENDENCIES
|
173
|
+
aws-sdk (~> 1.0)
|
174
|
+
bundler (~> 1.3)
|
175
|
+
confstruct (~> 0.2.5)
|
176
|
+
digital_opera!
|
177
|
+
guard-rspec (~> 2.3.0)
|
178
|
+
guard-spork (~> 1.5.0)
|
179
|
+
headless
|
180
|
+
jasmine
|
181
|
+
jquery-rails (~> 2.2.0)
|
182
|
+
mocha (~> 0.13.1)
|
183
|
+
rake (~> 10.1.0)
|
184
|
+
rspec-rails (~> 2.14.1)
|
185
|
+
sqlite3
|
186
|
+
thor
|
data/Guardfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard 'spork', :rspec_env => { 'RAILS_ENV' => 'test' } do
|
5
|
+
watch('Gemfile')
|
6
|
+
watch('Guardfile')
|
7
|
+
watch('Gemfile.lock')
|
8
|
+
watch('spec/spec_helper.rb') { :rspec }
|
9
|
+
watch(%r{^spec/support/.+\.rb$})
|
10
|
+
watch(%r{^lib/digital_opera/(.+)\.rb$}) { :rspec }
|
11
|
+
end
|
12
|
+
|
13
|
+
guard :rspec, :all_after_pass => false, :all_on_start => false, :cli => '--drb' do
|
14
|
+
watch(%r{^spec/.+_spec\.rb$})
|
15
|
+
end
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
![Digital Opera, LLC](http://digitalopera.com/wp-content/uploads/2013/10/large-logo.png)
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/digital_opera.png)](http://badge.fury.io/rb/digital_opera)
|
4
|
+
|
5
|
+
This Gem was created to store all of the crazy tricks, hacks and practices used by Digital Opera in various Ruby
|
6
|
+
based projects. We figured it was easier to throw them all in a Gem than to keep copying them into projects
|
7
|
+
independently, and then we thought...maybe someone else would find them useful too!
|
8
|
+
|
9
|
+
If you do find this Gem to be useful, please let us know.
|
10
|
+
|
11
|
+
### Version 0.0.10
|
12
|
+
- Bug fix in [ellipsis.js.coffee](https://github.com/noiseunion/do-toolbox/wiki/ellipsis.js.coffee)
|
13
|
+
|
14
|
+
### Version 0.0.9
|
15
|
+
- [digital_opera.js](https://github.com/noiseunion/do-toolbox/wiki/digital_opera.js)
|
16
|
+
- [ellipsis.js.coffee](https://github.com/noiseunion/do-toolbox/wiki/ellipsis.js.coffee)
|
17
|
+
- [events.js.coffee](https://github.com/noiseunion/do-toolbox/wiki/events.js.coffee)
|
18
|
+
- [forms.js.coffee](https://github.com/noiseunion/do-toolbox/wiki/forms.js.coffee)
|
19
|
+
- [preload_images.js.coffee](https://github.com/noiseunion/do-toolbox/wiki/preload_images.js.coffee)
|
20
|
+
- [strings.js.coffee](https://github.com/noiseunion/do-toolbox/wiki/strings.js.coffee)
|
21
|
+
- [tables.js.coffee](https://github.com/noiseunion/do-toolbox/wiki/tables.js.coffee)
|
22
|
+
|
23
|
+
### Version 0.0.8
|
24
|
+
- [DigitalOpera::Presenter::Base](https://github.com/noiseunion/do-toolbox/wiki/DigitalOpera::Presenter::Base) now delegates method_missing to source
|
25
|
+
|
26
|
+
### Version 0.0.7
|
27
|
+
|
28
|
+
- [DigitalOpera::Presenter::Base](https://github.com/noiseunion/do-toolbox/wiki/DigitalOpera::Presenter::Base)
|
29
|
+
- [DigitalOpera::Token](https://github.com/noiseunion/do-toolbox/wiki/Token-Builder)
|
30
|
+
- [DigitalOpera::Banker](https://github.com/noiseunion/do-toolbox/wiki/DigitalOpera::Banker)
|
31
|
+
- nil_or_zero?
|
32
|
+
|
33
|
+
### Licensing
|
34
|
+
|
35
|
+
This project rocks and uses MIT-LICENSE.
|
data/Rakefile
CHANGED
@@ -1,17 +1,20 @@
|
|
1
|
-
#!/usr/bin/env rake
|
2
|
-
|
3
1
|
begin
|
4
2
|
require 'bundler/setup'
|
5
3
|
rescue LoadError
|
6
4
|
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
7
5
|
end
|
8
6
|
|
7
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
8
|
+
load 'rails/tasks/engine.rake'
|
9
|
+
|
9
10
|
Bundler::GemHelper.install_tasks
|
10
11
|
|
12
|
+
require 'rspec/core'
|
11
13
|
require 'rspec/core/rake_task'
|
12
14
|
|
13
15
|
Dir[File.join(File.dirname(__FILE__), 'tasks/**/*.rake')].each {|f| load f }
|
14
16
|
|
15
17
|
desc "Run all specs in spec directory (excluding plugin specs)"
|
16
18
|
RSpec::Core::RakeTask.new
|
17
|
-
task :default => :spec
|
19
|
+
task :default => :spec
|
20
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module DigitalOpera
|
2
|
+
module S3Helper
|
3
|
+
def s3_uploader_form(options = {}, &block)
|
4
|
+
options[:post_authenticity_token] = form_authenticity_token
|
5
|
+
builder = DigitalOpera::Builders::S3FormBuilder.new options
|
6
|
+
|
7
|
+
form_tag(builder.url, builder.form_options) do
|
8
|
+
builder.fields.map do |name, value|
|
9
|
+
hidden_field_tag(name, value)
|
10
|
+
end.join.html_safe + capture(&block)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
# Maintain your gem's version:
|
4
|
+
require "digital_opera/version"
|
5
|
+
|
6
|
+
# Describe your gem and declare its dependencies:
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "digital_opera"
|
9
|
+
s.version = DigitalOpera::VERSION
|
10
|
+
s.authors = ["JD Hendrickson", "Grant Klinsing"]
|
11
|
+
s.email = ["support@digitalopera.com"]
|
12
|
+
s.homepage = "http://www.digitalopera.com/"
|
13
|
+
s.summary = "Tools and utilities for helping out in developing Ruby applications"
|
14
|
+
s.description = "Tools and utilities for helping out in developing Ruby applications"
|
15
|
+
s.license = 'MIT'
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = s.files.grep(%r{^spec/})
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_dependency "rails", ">= 3.1.0"
|
22
|
+
s.add_dependency 'coffee-rails'
|
23
|
+
|
24
|
+
s.add_development_dependency 'aws-sdk', '~> 1.0'
|
25
|
+
s.add_development_dependency 'bundler', '~> 1.3'
|
26
|
+
s.add_development_dependency 'rake', '~> 10.1.0'
|
27
|
+
s.add_development_dependency "rspec-rails", '~> 2.14.1'
|
28
|
+
s.add_development_dependency 'mocha', '~> 0.13.1'
|
29
|
+
s.add_development_dependency 'guard-rspec', '~> 2.3.0'
|
30
|
+
s.add_development_dependency 'guard-spork', '~> 1.5.0'
|
31
|
+
s.add_development_dependency 'sqlite3'
|
32
|
+
s.add_development_dependency 'confstruct', '~> 0.2.5'
|
33
|
+
s.add_development_dependency 'thor'
|
34
|
+
s.add_development_dependency 'jasmine'
|
35
|
+
s.add_development_dependency 'headless'
|
36
|
+
s.add_development_dependency 'jquery-rails', '~> 2.2.0'
|
37
|
+
end
|
data/lib/digital_opera/banker.rb
CHANGED
@@ -36,7 +36,7 @@ module DigitalOpera
|
|
36
36
|
def banker_convert_currency(value, conversion)
|
37
37
|
case conversion.to_sym
|
38
38
|
when :to_cents
|
39
|
-
return (value.to_s.gsub(/,/, '').
|
39
|
+
return (value.to_s.gsub(/,/, '').to_d * 100).to_i
|
40
40
|
when :to_dollars
|
41
41
|
return "%0.2f" % (value.to_f / 100)
|
42
42
|
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
##
|
2
|
+
## https://github.com/railscasts/383-uploading-to-amazon-s3/blob/master/gallery-jquery-fileupload/app/helpers/upload_helper.rb
|
3
|
+
##
|
4
|
+
module DigitalOpera
|
5
|
+
module Builders
|
6
|
+
class S3FormBuilder
|
7
|
+
def initialize(options)
|
8
|
+
|
9
|
+
|
10
|
+
@options = {
|
11
|
+
id: "file_upload",
|
12
|
+
aws_access_key_id: ENV["S3_ACCESS_KEY"],
|
13
|
+
aws_secret_access_key: ENV["S3_SECRET_ACCESS_KEY"],
|
14
|
+
bucket: S3Uploader.bucket,
|
15
|
+
acl: "authenticated-read",
|
16
|
+
expiration: 10.hours.from_now.to_time.iso8601,
|
17
|
+
max_file_size: nil,
|
18
|
+
as: "file",
|
19
|
+
post_method: 'post',
|
20
|
+
class: '',
|
21
|
+
success_action_redirect: nil,
|
22
|
+
data: {}
|
23
|
+
}.merge(options)
|
24
|
+
end
|
25
|
+
|
26
|
+
def form_options
|
27
|
+
hash = {
|
28
|
+
id: @options[:id],
|
29
|
+
method: "post",
|
30
|
+
authenticity_token: false,
|
31
|
+
multipart: true,
|
32
|
+
class: @options[:class],
|
33
|
+
data: {
|
34
|
+
post: @options[:post],
|
35
|
+
as: @options[:as],
|
36
|
+
post_method: @options[:post_method],
|
37
|
+
post_authenticity_token: @options[:post_authenticity_token]
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
hash[:data][:max_file_size] = @options[:max_file_size] if @options[:max_file_size].present?
|
42
|
+
@options[:data].each do |k,v|
|
43
|
+
hash[:data][k] = v
|
44
|
+
end
|
45
|
+
|
46
|
+
hash
|
47
|
+
end
|
48
|
+
|
49
|
+
def fields
|
50
|
+
hash = {
|
51
|
+
:key => key,
|
52
|
+
:acl => @options[:acl],
|
53
|
+
:policy => policy,
|
54
|
+
:signature => signature,
|
55
|
+
"AWSAccessKeyId" => @options[:aws_access_key_id]
|
56
|
+
#:success_action_redirect => @options[:post]
|
57
|
+
}
|
58
|
+
if @options[:success_action_redirect].present?
|
59
|
+
hash[:success_action_redirect] = @options[:success_action_redirect]
|
60
|
+
end
|
61
|
+
|
62
|
+
hash
|
63
|
+
end
|
64
|
+
|
65
|
+
def key
|
66
|
+
@key ||= "accounts/#{@account.id.to_s}/#{@options[:type]}/#{SecureRandom.hex}/${filename}"
|
67
|
+
end
|
68
|
+
|
69
|
+
def url
|
70
|
+
S3Uploader.url
|
71
|
+
end
|
72
|
+
|
73
|
+
def policy
|
74
|
+
Base64.encode64(policy_data.to_json).gsub("\n", "")
|
75
|
+
end
|
76
|
+
|
77
|
+
def policy_data
|
78
|
+
hash = {
|
79
|
+
expiration: @options[:expiration],
|
80
|
+
conditions: [
|
81
|
+
["starts-with", "$utf8", ""],
|
82
|
+
["starts-with", "$key", ""],
|
83
|
+
# ["content-length-range", 0, @options[:max_file_size]],
|
84
|
+
{bucket: @options[:bucket]},
|
85
|
+
{acl: @options[:acl]}
|
86
|
+
]
|
87
|
+
}
|
88
|
+
|
89
|
+
if @options[:max_file_size].present?
|
90
|
+
hash[:conditions].push( ["content-length-range", 0, @options[:max_file_size]] )
|
91
|
+
end
|
92
|
+
|
93
|
+
if @options[:success_action_redirect].present?
|
94
|
+
hash[:conditions].push( { success_action_redirect: @options[:success_action_redirect] } )
|
95
|
+
end
|
96
|
+
|
97
|
+
hash
|
98
|
+
end
|
99
|
+
|
100
|
+
def signature
|
101
|
+
Base64.encode64(
|
102
|
+
OpenSSL::HMAC.digest(
|
103
|
+
OpenSSL::Digest::Digest.new('sha1'),
|
104
|
+
@options[:aws_secret_access_key], policy
|
105
|
+
)
|
106
|
+
).gsub("\n", "")
|
107
|
+
end
|
108
|
+
|
109
|
+
def self.url
|
110
|
+
"https://#{S3Uploader.bucket}.s3.amazonaws.com/"
|
111
|
+
end
|
112
|
+
|
113
|
+
def self.bucket
|
114
|
+
ENV["S3_BUCKET_NAME"]
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
File without changes
|
@@ -0,0 +1,185 @@
|
|
1
|
+
module DigitalOpera
|
2
|
+
module Document
|
3
|
+
module Fields
|
4
|
+
class Standard
|
5
|
+
# Defines the behaviour for defined fields in the document.
|
6
|
+
# Set readers for the instance variables.
|
7
|
+
attr_accessor :default_val,
|
8
|
+
:label,
|
9
|
+
:name,
|
10
|
+
:options
|
11
|
+
|
12
|
+
# Evaluate the default value and return it. Will handle the
|
13
|
+
# serialization, proc calls, and duplication if necessary.
|
14
|
+
#
|
15
|
+
# @example Evaluate the default value.
|
16
|
+
# field.eval_default(document)
|
17
|
+
#
|
18
|
+
# @param [ Document ] doc The document the field belongs to.
|
19
|
+
#
|
20
|
+
# @return [ Object ] The serialized default value.
|
21
|
+
#
|
22
|
+
# @since 2.1.8
|
23
|
+
def eval_default(doc)
|
24
|
+
if fields = Threaded.selection(doc.criteria_instance_id)
|
25
|
+
evaluated_default(doc) if included?(fields)
|
26
|
+
else
|
27
|
+
evaluated_default(doc)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# Create the new field with a name and optional additional options.
|
32
|
+
#
|
33
|
+
# @example Create the new field.
|
34
|
+
# Field.new(:name, :type => String)
|
35
|
+
#
|
36
|
+
# @param [ Hash ] options The field options.
|
37
|
+
#
|
38
|
+
# @option options [ Class ] :type The class of the field.
|
39
|
+
# @option options [ Object ] :default The default value for the field.
|
40
|
+
# @option options [ String ] :label The field's label.
|
41
|
+
#
|
42
|
+
# @since 3.0.0
|
43
|
+
def initialize(name, options = {})
|
44
|
+
@name = name
|
45
|
+
@options = options
|
46
|
+
@label = options[:label]
|
47
|
+
@default_val = options[:default]
|
48
|
+
|
49
|
+
# @todo: Durran, change API in 4.0 to take the class as a parameter.
|
50
|
+
# This is here temporarily to address #2529 without changing the
|
51
|
+
# constructor signature.
|
52
|
+
if default_val.respond_to?(:call)
|
53
|
+
define_default_method(options[:klass])
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# Does the field pre-process its default value?
|
58
|
+
#
|
59
|
+
# @example Does the field pre-process the default?
|
60
|
+
# field.pre_processed?
|
61
|
+
#
|
62
|
+
# @return [ true, false ] If the field's default is pre-processed.
|
63
|
+
#
|
64
|
+
# @since 3.0.0
|
65
|
+
def pre_processed?
|
66
|
+
@pre_processed ||=
|
67
|
+
(options[:pre_processed] || (default_val && !default_val.is_a?(::Proc)))
|
68
|
+
end
|
69
|
+
|
70
|
+
# Get the type of this field - inferred from the class name.
|
71
|
+
#
|
72
|
+
# @example Get the type.
|
73
|
+
# field.type
|
74
|
+
#
|
75
|
+
# @return [ Class ] The name of the class.
|
76
|
+
#
|
77
|
+
# @since 2.1.0
|
78
|
+
def type
|
79
|
+
@type ||= options[:type] || Object
|
80
|
+
end
|
81
|
+
|
82
|
+
private # -----------------------------------------
|
83
|
+
|
84
|
+
# Get the name of the default method for this field.
|
85
|
+
#
|
86
|
+
# @api private
|
87
|
+
#
|
88
|
+
# @example Get the default name.
|
89
|
+
# field.default_name
|
90
|
+
#
|
91
|
+
# @return [ String ] The method name.
|
92
|
+
#
|
93
|
+
# @since 3.0.0
|
94
|
+
def default_name
|
95
|
+
@default_name ||= "__#{name}_default__"
|
96
|
+
end
|
97
|
+
|
98
|
+
# Define the method for getting the default on the document.
|
99
|
+
#
|
100
|
+
# @api private
|
101
|
+
#
|
102
|
+
# @example Define the method.
|
103
|
+
# field.define_default_method(doc)
|
104
|
+
#
|
105
|
+
# @note Ruby's instance_exec was just too slow.
|
106
|
+
#
|
107
|
+
# @param [ Class, Module ] object The class or module the field is
|
108
|
+
# defined on.
|
109
|
+
#
|
110
|
+
# @since 3.0.0
|
111
|
+
def define_default_method(object)
|
112
|
+
object.__send__(:define_method, default_name, default_val)
|
113
|
+
end
|
114
|
+
|
115
|
+
# Is the field included in the fields that were returned from the
|
116
|
+
# database? We can apply the default if:
|
117
|
+
# 1. The field is included in an only limitation (field: 1)
|
118
|
+
# 2. The field is not excluded in a without limitation (field: 0)
|
119
|
+
#
|
120
|
+
# @example Is the field included?
|
121
|
+
# field.included?(fields)
|
122
|
+
#
|
123
|
+
# @param [ Hash ] fields The field limitations.
|
124
|
+
#
|
125
|
+
# @return [ true, false ] If the field was included.
|
126
|
+
#
|
127
|
+
# @since 2.4.4
|
128
|
+
def included?(fields)
|
129
|
+
(fields.values.first == 1 && fields[name.to_s] == 1) ||
|
130
|
+
(fields.values.first == 0 && !fields.has_key?(name.to_s))
|
131
|
+
end
|
132
|
+
|
133
|
+
# Get the evaluated default.
|
134
|
+
#
|
135
|
+
# @example Get the evaluated default.
|
136
|
+
# field.evaluated_default.
|
137
|
+
#
|
138
|
+
# @param [ Document ] doc The doc being applied to.
|
139
|
+
#
|
140
|
+
# @return [ Object ] The default value.
|
141
|
+
#
|
142
|
+
# @since 2.4.4
|
143
|
+
def evaluated_default(doc)
|
144
|
+
if default_val.respond_to?(:call)
|
145
|
+
evaluate_default_proc(doc)
|
146
|
+
else
|
147
|
+
serialize_default(default_val.__deep_copy__)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
# Evaluate the default proc. In some cases we need to instance exec,
|
152
|
+
# in others we don't.
|
153
|
+
#
|
154
|
+
# @example Eval the default proc.
|
155
|
+
# field.evaluate_default_proc(band)
|
156
|
+
#
|
157
|
+
# @param [ Document ] doc The document.
|
158
|
+
#
|
159
|
+
# @return [ Object ] The called proc.
|
160
|
+
#
|
161
|
+
# @since 3.0.0
|
162
|
+
def evaluate_default_proc(doc)
|
163
|
+
serialize_default(doc.__send__(default_name))
|
164
|
+
end
|
165
|
+
|
166
|
+
# This is used when default values need to be serialized. Most of the
|
167
|
+
# time just return the object.
|
168
|
+
#
|
169
|
+
# @api private
|
170
|
+
#
|
171
|
+
# @example Serialize the default value.
|
172
|
+
# field.serialize_default(obj)
|
173
|
+
#
|
174
|
+
# @param [ Object ] object The default.
|
175
|
+
#
|
176
|
+
# @return [ Object ] The serialized default.
|
177
|
+
#
|
178
|
+
# @since 3.0.0
|
179
|
+
def serialize_default(object)
|
180
|
+
mongoize(object)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|