mediumable 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
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
18
+ *.sw?
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mediumable.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Giorgos Koumparoulis
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
+ # Mediumable
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'mediumable'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install mediumable
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/lib/mediumable.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "mediumable/version"
2
+ require 'mediumable/active_record_extensions'
3
+
4
+ module Mediumable
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,52 @@
1
+ module Mediumable
2
+ module ActiveRecordExtensions
3
+ module ClassMethods
4
+ def acts_as_mediumable
5
+ make_it_mediumable! unless included_modules.include?(InstanceMethods)
6
+ end
7
+
8
+ private
9
+
10
+ def make_it_mediumable!
11
+ include InstanceMethods
12
+ before_save :position_media
13
+ has_many :media, :as => :mediumable, :order => :position
14
+ has_many :images, :class_name => "Medium", :as => :mediumable, :order => :position, :conditions => "data_content_type LIKE '%image%'"
15
+ has_many :files, :class_name => "Medium", :as => :mediumable, :order => :position, :conditions => "data_content_type NOT LIKE '%image%'"
16
+ end
17
+ end
18
+
19
+ module InstanceMethods
20
+
21
+ def position_media
22
+ self.media.each_with_index do |m, i|
23
+ m.update_attributes :position => i+1
24
+ end
25
+ end
26
+
27
+ def thumb
28
+ (@model_images ||= images).first
29
+ end
30
+
31
+ def has_thumb?
32
+ !thumb.nil?
33
+ end
34
+
35
+ def concatenated_media_ids=(ids)
36
+ ids = ids.split(",").compact.reject(&:blank?)
37
+ self.media.each do |medium|
38
+ medium.mark_for_destruction unless ids.include?(medium.id.to_s)
39
+ end
40
+ ms = Medium.find_all_by_id(ids)
41
+ ms.each{ |m| m.update_attribute(:position, (ids.index(m.id.to_s) + 1)) }
42
+ self.media = ms
43
+ end
44
+
45
+ def concatenated_media_ids
46
+ self.media.map(&:id).join(',')
47
+ end
48
+ end
49
+ end
50
+ end
51
+
52
+ ActiveRecord::Base.extend Mediumable::ActiveRecordExtensions::ClassMethods
@@ -0,0 +1,3 @@
1
+ module Mediumable
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mediumable/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "mediumable"
8
+ gem.version = Mediumable::VERSION
9
+ gem.authors = ["John Tsiligkakis", "George Koumparoulis"]
10
+ gem.email = ["george.koumparoulis@gmail.com", 'gtsiligkakis@gmail.com']
11
+ gem.description = %q{Adds mediumable functionality to models through acts_as_mediumable}
12
+ gem.summary = %q{Mediumable functionality}
13
+ gem.homepage = "https://github.com/Geokoumpa/mediumable.git"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mediumable
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - John Tsiligkakis
14
+ - George Koumparoulis
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2013-06-12 00:00:00 Z
20
+ dependencies: []
21
+
22
+ description: Adds mediumable functionality to models through acts_as_mediumable
23
+ email:
24
+ - george.koumparoulis@gmail.com
25
+ - gtsiligkakis@gmail.com
26
+ executables: []
27
+
28
+ extensions: []
29
+
30
+ extra_rdoc_files: []
31
+
32
+ files:
33
+ - .gitignore
34
+ - Gemfile
35
+ - LICENSE.txt
36
+ - README.md
37
+ - Rakefile
38
+ - lib/mediumable.rb
39
+ - lib/mediumable/active_record_extensions.rb
40
+ - lib/mediumable/version.rb
41
+ - mediumable.gemspec
42
+ homepage: https://github.com/Geokoumpa/mediumable.git
43
+ licenses: []
44
+
45
+ post_install_message:
46
+ rdoc_options: []
47
+
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ hash: 3
56
+ segments:
57
+ - 0
58
+ version: "0"
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ hash: 3
65
+ segments:
66
+ - 0
67
+ version: "0"
68
+ requirements: []
69
+
70
+ rubyforge_project:
71
+ rubygems_version: 1.8.24
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: Mediumable functionality
75
+ test_files: []
76
+