haraway 0.1.0.dev.41

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 07235cd8361db9b168d38887ad4c929e3eb72ee6
4
+ data.tar.gz: f6da1d4fc5a130089809a8777f30a71826713d97
5
+ SHA512:
6
+ metadata.gz: aea1ac0d3d4c3e8a94b8740e5ce03f4753b6b4832db32835ddb2e0a7474104a0997588dac7e964a798585c3ba4a87c74c97da8b98b2415bf549d7de391522ac9
7
+ data.tar.gz: 8daf42b95201a79797a29d8be972b9ee8b981a1812755d3687f5f2bfe6dd074b87b594c40b3f2ef36d2073d37ed9d98c7165c1172c6c73c042e851d0cb069caf
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in haraway.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Simon Menke
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Haraway
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'haraway'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install haraway
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/haraway.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'haraway/lib_version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "haraway"
8
+ spec.version = Haraway::BUILD_VERSION
9
+ spec.authors = ["Simon Menke"]
10
+ spec.email = ["simon.menke@gmail.com"]
11
+ spec.description = %q{Haraway is a simple to use assets handling service.}
12
+ spec.summary = %q{The client library for haraway}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+
24
+ spec.add_runtime_dependency "json"
25
+ end
@@ -0,0 +1,16 @@
1
+ module Haraway::ActiveAdmin::Head
2
+
3
+ def build(*args)
4
+ super
5
+ build_haraway_head
6
+ end
7
+
8
+ private
9
+
10
+ def build_haraway_head
11
+ within @head do
12
+ text_node Haraway::TagsHelper.render(Haraway.configuration).html_safe
13
+ end
14
+ end
15
+
16
+ end
@@ -0,0 +1,9 @@
1
+ module Haraway::ActiveAdmin::ShowPage
2
+
3
+ def default_attribute_table_rows
4
+ c = super
5
+ c.delete(:haraway_metadata)
6
+ c
7
+ end
8
+
9
+ end
@@ -0,0 +1,12 @@
1
+ module Haraway::ActiveAdmin
2
+ require "haraway/active_admin/head"
3
+ require "haraway/active_admin/show_page"
4
+ end
5
+
6
+ ActionDispatch::Reloader.to_prepare do
7
+ ::ActiveAdmin::Views::Pages::Base.send :include, Haraway::ActiveAdmin::Head
8
+ end
9
+
10
+ ActiveAdmin.after_load do
11
+ ActiveAdmin::Views::Pages::Show.send(:include, Haraway::ActiveAdmin::ShowPage)
12
+ end
@@ -0,0 +1,47 @@
1
+ class Haraway::ActiveRecord::Asset
2
+
3
+ attr_reader :id
4
+
5
+ def initialize(attributes)
6
+ @id = attributes[:id]
7
+ @_destroy = (attributes[:_destroy] == "t" || attributes[:_destroy] == "1")
8
+
9
+ @attributes = attributes.except(:id, :_destroy)
10
+ end
11
+
12
+ def destroy?
13
+ !!@_destroy
14
+ end
15
+
16
+ def url(version=nil)
17
+ if version.nil?
18
+ self.url("original")
19
+ else
20
+ "//" + File.join(
21
+ "c."+Haraway.configuration.endpoint,
22
+ @id,
23
+ version.to_s)
24
+ end
25
+ end
26
+
27
+ def update_attributes(attributes)
28
+ @_destroy = (attributes[:_destroy] == "t" || attributes[:_destroy] == "1" || attributes[:_destroy] == 1)
29
+ @attributes = attributes.except(:id, :_destroy)
30
+ end
31
+
32
+ def method_missing(m, *a, &b)
33
+ case m.to_s
34
+
35
+ when /^[a-z_][a-z0-9_]*$/
36
+ @attributes[m]
37
+
38
+ when /^[a-z_][a-z0-9_]*[=]$/
39
+ @attributes[m] = a[0]
40
+
41
+ else
42
+ super
43
+
44
+ end
45
+ end
46
+
47
+ end
@@ -0,0 +1,174 @@
1
+ module Haraway::ActiveRecord::Macro
2
+ extend ActiveSupport::Concern
3
+
4
+ private
5
+
6
+ def haraway_write_assets(section, attributes)
7
+ section = section.to_s
8
+
9
+ old_assets = haraway_read_assets(section).index_by(&:id)
10
+ new_assets = []
11
+
12
+ attributes.each do |attrs|
13
+ asset_id = attrs[:id]
14
+ asset = old_assets.delete(asset_id)
15
+
16
+ if asset.nil?
17
+ asset = Haraway::ActiveRecord::Asset.new(attrs)
18
+ unless asset.destroy?
19
+ self.haraway_uploaded_assets.push(asset_id)
20
+ new_assets.push(asset)
21
+ end
22
+ else
23
+ asset.update_attributes(attrs)
24
+ if asset.destroy?
25
+ self.haraway_deleted_assets.push(asset_id)
26
+ else
27
+ new_assets.push(asset)
28
+ end
29
+ end
30
+ end
31
+
32
+ old_assets.keys.each do |asset_id|
33
+ self.haraway_deleted_assets.push(asset_id)
34
+ end
35
+
36
+ if self.haraway_metadata.blank?
37
+ self.haraway_metadata = {}
38
+ end
39
+
40
+ self.haraway_metadata[section] = new_assets
41
+ end
42
+
43
+ def haraway_read_assets(section)
44
+ section = section.to_s
45
+
46
+ if self.haraway_metadata.blank?
47
+ return []
48
+ else
49
+ return (self.haraway_metadata[section] || [])
50
+ end
51
+ end
52
+
53
+ module ClassMethods
54
+
55
+ def content_columns
56
+ super.reject do |c|
57
+ c.name == "haraway_metadata"
58
+ end
59
+ end
60
+
61
+ def haraway_assets
62
+ @haraway_assets ||= (superclass.haraway_assets.dup rescue {})
63
+ end
64
+
65
+ def has_many_assets(name, profile)
66
+ name = name.to_s
67
+ profile = profile.to_s
68
+
69
+ haraway_assets[name] = profile
70
+
71
+ include Haraway::ActiveRecord::Macro::MetaData
72
+
73
+ include Module.new.class_eval <<-RUBY, __FILE__, __LINE__+1
74
+
75
+ def #{name}
76
+ haraway_read_assets(#{name.inspect})
77
+ end
78
+
79
+ def #{name}=(value)
80
+ haraway_write_assets(#{name.inspect}, value || [])
81
+ end
82
+
83
+ self
84
+ RUBY
85
+
86
+ end
87
+
88
+ def has_one_asset(name, profile)
89
+ name = name.to_s
90
+ profile = profile.to_s
91
+
92
+ haraway_assets[name] = profile
93
+
94
+ include Haraway::ActiveRecord::Macro::MetaData
95
+
96
+ include Module.new.class_eval <<-RUBY, __FILE__, __LINE__+1
97
+
98
+ def #{name}
99
+ haraway_read_assets(#{name.inspect}).first
100
+ end
101
+
102
+ def #{name}=(value)
103
+ haraway_write_assets(#{name.inspect}, [value])
104
+ end
105
+
106
+ self
107
+ RUBY
108
+
109
+ end
110
+
111
+ end
112
+
113
+ module MetaData
114
+ extend ActiveSupport::Concern
115
+
116
+ included do
117
+ serialize :haraway_metadata
118
+ before_validation :clean_haraway_assets
119
+ after_save :commit_haraway_assets
120
+ after_save :delete_haraway_assets
121
+ end
122
+
123
+ def haraway_uploaded_assets
124
+ @_haraway_uploaded_assets ||= []
125
+ end
126
+
127
+ def haraway_deleted_assets
128
+ @_haraway_deleted_assets ||= []
129
+ end
130
+
131
+ private
132
+
133
+ def clean_haraway_assets
134
+ self.haraway_metadata ||= {}
135
+ self.haraway_metadata.each do |section, _|
136
+ if haraway_metadata[section].blank?
137
+ self.haraway_metadata_will_change!
138
+ self.haraway_metadata.delete(section)
139
+ end
140
+ end
141
+ end
142
+
143
+ def commit_haraway_assets
144
+ return if self.haraway_uploaded_assets.blank?
145
+
146
+ asset_ids = []
147
+
148
+ self.haraway_uploaded_assets.uniq.each do |id|
149
+ asset_ids.push(id)
150
+ end
151
+
152
+ if asset_ids.size > 0
153
+ Haraway::Committer.new(Haraway.configuration, asset_ids).commit!
154
+ @_haraway_uploaded_assets = nil
155
+ end
156
+ end
157
+
158
+ def delete_haraway_assets
159
+ return self.haraway_deleted_assets.blank?
160
+
161
+ asset_ids = []
162
+
163
+ self.haraway_deleted_assets.uniq.each do |id|
164
+ asset_ids.push(id)
165
+ end
166
+
167
+ if asset_ids.size > 0
168
+ Haraway::Deleter.new(Haraway.configuration, asset_ids).delete!
169
+ @_haraway_deleted_assets = nil
170
+ end
171
+ end
172
+
173
+ end
174
+ end
@@ -0,0 +1,10 @@
1
+ module Haraway::ActiveRecord
2
+
3
+ require 'haraway/active_record/macro'
4
+ require 'haraway/active_record/asset'
5
+
6
+ end
7
+
8
+ ActiveSupport.on_load(:active_record) do
9
+ include Haraway::ActiveRecord::Macro
10
+ end
@@ -0,0 +1,28 @@
1
+ class Haraway::Committer
2
+
3
+ require 'json'
4
+ require 'net/http'
5
+
6
+ def initialize(config, assets)
7
+ @config = config
8
+ @assets = assets || []
9
+ end
10
+
11
+ def commit!
12
+ creds = @config.credentials
13
+ token = creds.make_authentication_message("manager")
14
+
15
+ Net::HTTP.start("api."+@config.endpoint, :use_ssl => @config.use_ssl) do |http|
16
+ req = Net::HTTP::Post.new("/commit")
17
+ req["Content-Type"] = "text/json; charset=utf-8"
18
+ req["Authorization"] = "haraway-token #{token}"
19
+ req.body = JSON.dump({ :asset_ids => @assets })
20
+
21
+ resp = http.request(req)
22
+ if resp.code != "200"
23
+ raise "Commit failed: #{resp.code} #{resp.message}\n#{resp.body}"
24
+ end
25
+ end
26
+ end
27
+
28
+ end
@@ -0,0 +1,51 @@
1
+ class Haraway::Config
2
+
3
+ attr_reader :profiles, :credentials
4
+ attr_accessor :use_ssl, :endpoint, :access_key, :secret_key, :pusher_key
5
+
6
+ def initialize
7
+ @profiles = {}
8
+ @credentials = Haraway::Credentials.new(self)
9
+ @use_ssl = true
10
+
11
+ yield(Builder.new(self)) if block_given?
12
+ end
13
+
14
+ def deploy!
15
+ Haraway::Deployer.new(self).deploy!
16
+ end
17
+
18
+ class Builder
19
+
20
+ def initialize(config)
21
+ @config = config
22
+ end
23
+
24
+ def use_ssl=(v)
25
+ @config.use_ssl = v
26
+ end
27
+
28
+ def endpoint=(v)
29
+ @config.endpoint = v
30
+ end
31
+
32
+ def access_key=(v)
33
+ @config.access_key = v
34
+ end
35
+
36
+ def secret_key=(v)
37
+ @config.secret_key = v
38
+ end
39
+
40
+ def pusher_key=(v)
41
+ @config.pusher_key = v
42
+ end
43
+
44
+ def profile(name, &block)
45
+ profile = Haraway::Profile.new(name, &block)
46
+ @config.profiles[name] = profile
47
+ end
48
+
49
+ end
50
+
51
+ end
@@ -0,0 +1,88 @@
1
+ class Haraway::Credentials
2
+
3
+ require "base64"
4
+ require "json"
5
+ require "openssl"
6
+ require "securerandom"
7
+
8
+ def initialize(config)
9
+ @config = config
10
+ end
11
+
12
+ def make_authentication_message(role, expiration=nil, nonce=nil)
13
+ expiration ||= (Time.now + (60*60)).to_i
14
+ nonce ||= SecureRandom.base64(64)
15
+ digest = OpenSSL::Digest::SHA256.new
16
+
17
+ signature = "#{@config.access_key}\n#{expiration}\n#{role}\n#{nonce}\n"
18
+ signature = OpenSSL::HMAC.digest(digest, @config.secret_key, signature)
19
+ signature = Base64.strict_encode64(signature)
20
+
21
+ message = {
22
+ "access_key" => @config.access_key,
23
+ "expiration" => expiration,
24
+ "role" => role,
25
+ "nonce" => nonce,
26
+ "signature" => signature
27
+ }
28
+ message = JSON.dump(message)
29
+ message = Base64.strict_encode64(message)
30
+ end
31
+
32
+ def verify_authentication_message(role, message)
33
+ unless String === message and message.size > 0
34
+ return false
35
+ end
36
+
37
+ message = Base64.strict_decode64(message)
38
+ message = JSON.parse(message)
39
+
40
+ unless Hash === message
41
+ return false
42
+ end
43
+
44
+ access_key_b = message["access_key"]
45
+ expiration_b = message["expiration"]
46
+ role_b = message["role"]
47
+ nonce_b = message["nonce"]
48
+ signature_b = message["signature"]
49
+
50
+ unless String === access_key_b
51
+ return false
52
+ end
53
+
54
+ unless Integer === expiration_b
55
+ return false
56
+ end
57
+
58
+ unless String === nonce_b
59
+ return false
60
+ end
61
+
62
+ unless String === role_b
63
+ return false
64
+ end
65
+
66
+ unless String === signature_b
67
+ return false
68
+ end
69
+
70
+ if Time.now.to_i > expiration_b
71
+ return false
72
+ end
73
+
74
+ digest = OpenSSL::Digest::SHA256.new
75
+ signature_a = "#{@config.access_key}\n#{expiration_b}\n#{role}\n#{nonce_b}\n"
76
+ signature_a = OpenSSL::HMAC.digest(digest, @config.secret_key, signature_a)
77
+ signature_a = Base64.strict_encode64(signature_a)
78
+ if signature_a != signature_b
79
+ return false
80
+ end
81
+
82
+ return true
83
+
84
+ rescue Object
85
+ return false
86
+ end
87
+
88
+ end
@@ -0,0 +1,27 @@
1
+ class Haraway::Deleter
2
+
3
+ require 'json'
4
+ require 'net/http'
5
+
6
+ def initialize(config, assets)
7
+ @config = config
8
+ @assets = assets || []
9
+ end
10
+
11
+ def delete!
12
+ creds = @config.credentials
13
+ token = creds.make_authentication_message("manager")
14
+
15
+ Net::HTTP.start("api."+@config.endpoint, :use_ssl => @config.use_ssl) do |http|
16
+ req = Net::HTTP::Post.new("/v1/#{@config.access_key}/delete?token="+token)
17
+ req["Content-Type"] = "text/json; charset=utf-8"
18
+ req.body = JSON.dump(@assets)
19
+
20
+ resp = http.request(req)
21
+ if resp.code != "200"
22
+ raise "Delete failed: #{resp.code} #{resp.message}\n#{resp.body}"
23
+ end
24
+ end
25
+ end
26
+
27
+ end
@@ -0,0 +1,50 @@
1
+ class Haraway::Deployer
2
+
3
+ require 'json'
4
+ require 'net/http'
5
+
6
+ def initialize(config)
7
+ @config = config
8
+ end
9
+
10
+ def deploy!
11
+ creds = @config.credentials
12
+ @token = creds.make_authentication_message("manager")
13
+
14
+ Net::HTTP.start("api."+@config.endpoint, :use_ssl => @config.use_ssl) do |http|
15
+ upload_profile(http)
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def upload_profile(http)
22
+ req = Net::HTTP::Put.new("/profiles")
23
+ req["Content-Type"] = "text/json; charset=utf-8"
24
+ req["Authorization"] = "haraway-token #{@token}"
25
+ req.body = JSON.dump(format_request)
26
+
27
+ http.request(req) do |resp|
28
+ if resp.code != "200"
29
+ raise "Deploy failed: #{resp.code} #{resp.message}\n#{resp.body}"
30
+ end
31
+
32
+ resp.read_body do |segment|
33
+ segment.gsub!("\x00", "")
34
+ $stdout.print segment
35
+ $stdout.flush
36
+ end
37
+
38
+ puts "done."
39
+ end
40
+ end
41
+
42
+ def format_request
43
+ profiles = {}
44
+ @config.profiles.each do |n, p|
45
+ profiles[n] = p.format_as_json
46
+ end
47
+ { profiles: profiles }
48
+ end
49
+
50
+ end
@@ -0,0 +1,2 @@
1
+
2
+ ::Formtastic::Helpers::InputsHelper::SKIPPED_COLUMNS.push(:haraway_metadata)
@@ -0,0 +1,5 @@
1
+ module Haraway::Formtastic
2
+
3
+ require 'haraway/formtastic/inputs_helper'
4
+
5
+ end
@@ -0,0 +1,10 @@
1
+ module Haraway
2
+ VERSION = "0.1.0"
3
+ BUILD = "41"
4
+
5
+ if BUILD != ("{{BUILD_NUMBER" + "}}") # prevent sed replacement (see script/ci)
6
+ BUILD_VERSION = "#{VERSION}.dev.#{BUILD}"
7
+ else
8
+ BUILD_VERSION = VERSION
9
+ end
10
+ end
@@ -0,0 +1,51 @@
1
+ class Haraway::Profile
2
+
3
+ attr_reader :name, :versions, :accepted_file_types
4
+ attr_accessor :max_file_size
5
+
6
+ def initialize(name)
7
+ @name = name
8
+ @max_file_size = 1024 * 1024 * 5
9
+ @accepted_file_types = []
10
+ @versions = {}
11
+ yield(Builder.new(self)) if block_given?
12
+ end
13
+
14
+ class Builder
15
+
16
+ def initialize(profile)
17
+ @profile = profile
18
+ end
19
+
20
+ def accept(type)
21
+ @profile.accepted_file_types << type.to_s
22
+ end
23
+
24
+ def max_file_size=(size)
25
+ @profile.max_file_size = size
26
+ end
27
+
28
+ def version(name, &block)
29
+ version = Haraway::Version.new(name, &block)
30
+ version.validate!
31
+ @profile.versions[name] = version
32
+ end
33
+
34
+ end
35
+
36
+ def format_as_json
37
+ versions = {}
38
+
39
+ @versions.each do |n, v|
40
+ versions[n] = v.format_as_json
41
+ end
42
+
43
+ {
44
+ :name => @name,
45
+ :max_file_size => @max_file_size,
46
+ :accepted_types => @accepted_file_types,
47
+ :versions => versions
48
+ }
49
+ end
50
+
51
+ end
@@ -0,0 +1,15 @@
1
+ class Haraway::Engine < ::Rails::Engine
2
+
3
+ rake_tasks do
4
+ namespace :haraway do
5
+
6
+ desc "Deploy the haraway profiles."
7
+ task :deploy => :environment do
8
+ puts "Deploying new profiles to #{Haraway.configuration.endpoint}"
9
+ Haraway::Deployer.new(Haraway.configuration).deploy!
10
+ end
11
+
12
+ end
13
+ end
14
+
15
+ end
@@ -0,0 +1,5 @@
1
+ module Haraway::Rails
2
+
3
+ require 'haraway/rails/engine'
4
+
5
+ end
@@ -0,0 +1,27 @@
1
+ module Haraway::TagsHelper
2
+
3
+ def self.render(config, ttl=nil)
4
+ creds = config.credentials
5
+ scheme = config.use_ssl ? "https" : "http"
6
+ ttl = ttl || 900
7
+
8
+ mac = creds.make_authentication_message("uploader", (Time.now + ttl).to_i)
9
+
10
+ <<-HTML.gsub(/^[ \t]+/, "").strip
11
+ <meta name="haraway_endpoint" content="#{scheme}://api.#{config.endpoint}" />
12
+ <meta name="haraway_token" content="#{mac}" />
13
+ <script src="//s.#{config.endpoint}/haraway.js"></script>
14
+ HTML
15
+ end
16
+
17
+ def haraway_header_tags(config, ttl=nil)
18
+ html = Haraway::TagsHelper.render(config, ttl)
19
+
20
+ if responds_to?(:raw)
21
+ html = raw(html)
22
+ end
23
+
24
+ html
25
+ end
26
+
27
+ end
@@ -0,0 +1,102 @@
1
+ class Haraway::Version
2
+
3
+ attr_reader :name, :steps
4
+
5
+ def initialize(name)
6
+ @name = name
7
+ @steps = []
8
+ yield(Builder.new(self)) if block_given?
9
+ end
10
+
11
+ def validate!
12
+ if name == nil or name == ""
13
+ raise "Haraway::Version name must not be blank"
14
+ end
15
+
16
+ if name == "original"
17
+ raise "Haraway::Version name must not be 'original'"
18
+ end
19
+
20
+ unless /^[a-z][a-z0-9_-]*$/ === name
21
+ raise "Haraway::Version name must match /[a-z][a-z0-9_-]*/"
22
+ end
23
+
24
+ if @steps.empty?
25
+ raise "Haraway::Version must have at least 1 step"
26
+ end
27
+ end
28
+
29
+ def format_as_json
30
+ @steps
31
+ end
32
+
33
+ class Builder
34
+
35
+ def initialize(version)
36
+ @version = version
37
+ end
38
+
39
+ # @param [String] text The annotation text.
40
+ # @param [Hash] params The options.
41
+ # @option params [Integer] :x
42
+ # @option params [Integer] :y
43
+ # @option params [Integer] :point_size
44
+ # @option params [Integer] :dropshadow_offset
45
+ # @option params [String] :color
46
+ # @option params [String] :style
47
+ # @option params [String] :font_weight
48
+ # @option params [String] :font_family
49
+ # @option params [String] :stroke
50
+ # @option params [String] :dropshadow_color
51
+ # @option params [String] :gravity
52
+ # @option params [Float] :kerning
53
+ def annotate(text, params={})
54
+ params = params.dup
55
+ params["text"] = text
56
+ push("blitline", "annotate", params)
57
+ end
58
+
59
+ def auto_level
60
+ push("blitline", "auto_level", {})
61
+ end
62
+
63
+ def auto_gamma
64
+ push("blitline", "auto_gamma", {})
65
+ end
66
+
67
+ # @param [Hash] params The options.
68
+ # @option params [Float] :sigma
69
+ # @option params [Float] :radius
70
+ def blur(params={})
71
+ push("blitline", "blur", params)
72
+ end
73
+
74
+ # @param [Hash] params The options.
75
+ # @option params [String] :color
76
+ def background_color(params={})
77
+ push("blitline", "background_color", params)
78
+ end
79
+
80
+ def resize_to_fill(width, height, params={})
81
+ params = params.dup
82
+ params["width"] = width
83
+ params["height"] = height
84
+ push("blitline", "resize_to_fill", params)
85
+ end
86
+
87
+ def resize_to_fit(width, height, params={})
88
+ params = params.dup
89
+ params["width"] = width
90
+ params["height"] = height
91
+ push("blitline", "resize_to_fit", params)
92
+ end
93
+
94
+ private
95
+
96
+ def push(provider, type, params={})
97
+ @version.steps.push({ "provider" => provider, "type" => type, "params" => params.dup })
98
+ end
99
+
100
+ end
101
+
102
+ end
data/lib/haraway.rb ADDED
@@ -0,0 +1,45 @@
1
+ module Haraway
2
+ require "haraway/lib_version"
3
+
4
+ require "haraway/version"
5
+ require "haraway/config"
6
+ require "haraway/credentials"
7
+ require "haraway/tags_helper"
8
+ require "haraway/profile"
9
+ require "haraway/deployer"
10
+ require "haraway/committer"
11
+ require "haraway/deleter"
12
+
13
+ begin # Load the Rails adapter
14
+ require "rails/engine"
15
+ require "haraway/rails"
16
+ rescue LoadError
17
+ end
18
+
19
+ begin # Load the ActiveRecord adapter
20
+ require "active_record"
21
+ require "haraway/active_record"
22
+ rescue LoadError
23
+ end
24
+
25
+ begin # Load the Formtastic adapter
26
+ require "formtastic"
27
+ require "haraway/formtastic"
28
+ rescue LoadError
29
+ end
30
+
31
+ begin # Load the ActiveAdmin adapter
32
+ require "active_admin"
33
+ require "haraway/active_admin"
34
+ rescue LoadError
35
+ end
36
+
37
+ def self.configuration
38
+ @configuration
39
+ end
40
+
41
+ def self.configure(&block)
42
+ @configuration = Haraway::Config.new(&block)
43
+ end
44
+
45
+ end
data/script/ci-release ADDED
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -e
4
+ set -o pipefail
5
+
6
+ export HARAWAY_BUILD_VERSION="$(git rev-list HEAD --count)"
7
+
8
+ { # set the build version
9
+ cd lib/haraway
10
+ mv lib_version.rb lib_version.rb_
11
+ cat lib_version.rb_ | sed "s|{{BUILD_NUMBER}}|$HARAWAY_BUILD_VERSION|" > lib_version.rb
12
+ rm lib_version.rb_
13
+ cd -
14
+ } > /dev/null
15
+
16
+ rake build
17
+
18
+ mkdir -p "$HOME/.gem/"
19
+ touch "$HOME/.gem/credentials"
20
+ chmod 0600 "$HOME/.gem/credentials"
21
+ echo -e "---\n:rubygems_api_key: ${RUBYGEMS_API_KEY}" > "$HOME/.gem/credentials"
22
+
23
+ gem push pkg/haraway-[0-9]*.gem
data/wercker.yml ADDED
@@ -0,0 +1,13 @@
1
+ box: wercker/ruby
2
+
3
+ build:
4
+ steps:
5
+ - script:
6
+ name: Test
7
+ code: 'echo "none"'
8
+
9
+ deploy:
10
+ steps:
11
+ - script:
12
+ name: Deploy to rubygems
13
+ code: script/ci-release
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: haraway
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.dev.41
5
+ platform: ruby
6
+ authors:
7
+ - Simon Menke
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Haraway is a simple to use assets handling service.
56
+ email:
57
+ - simon.menke@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - .ruby-version
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - haraway.gemspec
69
+ - lib/haraway.rb
70
+ - lib/haraway/active_admin.rb
71
+ - lib/haraway/active_admin/head.rb
72
+ - lib/haraway/active_admin/show_page.rb
73
+ - lib/haraway/active_record.rb
74
+ - lib/haraway/active_record/asset.rb
75
+ - lib/haraway/active_record/macro.rb
76
+ - lib/haraway/committer.rb
77
+ - lib/haraway/config.rb
78
+ - lib/haraway/credentials.rb
79
+ - lib/haraway/deleter.rb
80
+ - lib/haraway/deployer.rb
81
+ - lib/haraway/formtastic.rb
82
+ - lib/haraway/formtastic/inputs_helper.rb
83
+ - lib/haraway/lib_version.rb
84
+ - lib/haraway/profile.rb
85
+ - lib/haraway/rails.rb
86
+ - lib/haraway/rails/engine.rb
87
+ - lib/haraway/tags_helper.rb
88
+ - lib/haraway/version.rb
89
+ - script/ci-release
90
+ - wercker.yml
91
+ homepage: ''
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - '>'
107
+ - !ruby/object:Gem::Version
108
+ version: 1.3.1
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.0.14
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: The client library for haraway
115
+ test_files: []