motional 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +20 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/Guardfile +13 -0
- data/LICENSE.txt +22 -0
- data/README.md +128 -0
- data/Rakefile +15 -0
- data/app/app_delegate.rb +14 -0
- data/lib/motional.rb +11 -0
- data/lib/motional/asset.rb +426 -0
- data/lib/motional/assets.rb +95 -0
- data/lib/motional/assets_filter.rb +33 -0
- data/lib/motional/core.rb +84 -0
- data/lib/motional/group.rb +245 -0
- data/lib/motional/library.rb +32 -0
- data/lib/motional/representation.rb +101 -0
- data/lib/motional/representations.rb +55 -0
- data/lib/motional/version.rb +3 -0
- data/motional.gemspec +24 -0
- data/resources/sample.jpg +0 -0
- data/resources/sample.mp4 +0 -0
- data/spec/motional/asset_spec.rb +274 -0
- data/spec/motional/assets_spec.rb +53 -0
- data/spec/motional/group_spec.rb +137 -0
- data/spec/motional/library_spec.rb +18 -0
- data/spec/motional/representation_spec.rb +57 -0
- data/spec/motional/representations_spec.rb +43 -0
- data/spec/spec_helper.rb +45 -0
- metadata +130 -0
@@ -0,0 +1,53 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
|
3
|
+
describe MotionAL::Assets do
|
4
|
+
before do
|
5
|
+
MotionAL::Asset.find_all do |asset, error|
|
6
|
+
@existent_asset = asset if asset.asset_type == :photo && @no_group_asset.nil?
|
7
|
+
end
|
8
|
+
wait_async
|
9
|
+
|
10
|
+
MotionAL::Asset.create(@existent_asset.full_resolution_image) do |created|
|
11
|
+
@no_group_asset = created
|
12
|
+
end
|
13
|
+
|
14
|
+
@test_group_name = 'MotionAL'
|
15
|
+
MotionAL::Group.find_all do |group, error|
|
16
|
+
@test_group = group if group.name == TEST_GROUP_NAME
|
17
|
+
end
|
18
|
+
wait_async
|
19
|
+
|
20
|
+
MotionAL::Group.find_camera_roll do |group, error|
|
21
|
+
@saved_photos = group
|
22
|
+
end
|
23
|
+
wait_async(0.5)
|
24
|
+
|
25
|
+
@all_assets = @saved_photos.assets
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "#count" do
|
29
|
+
it "should work assets filter" do
|
30
|
+
@all_assets.count(:photo).should.not.equal @all_assets.count(:video)
|
31
|
+
@all_assets.count(:photo).should.not.equal @all_assets.count(:all)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should return Fixnum" do
|
35
|
+
@all_assets.count(:all).should.instance_of Fixnum
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "#each" do
|
40
|
+
it "should return assets in the group" do
|
41
|
+
test_assets = []
|
42
|
+
|
43
|
+
@test_group.assets.each {|a| test_assets << a }
|
44
|
+
wait_async
|
45
|
+
|
46
|
+
@test_group.assets.count(:all).should.equal test_assets.size
|
47
|
+
end
|
48
|
+
|
49
|
+
it "cannot specify :group option" do
|
50
|
+
Proc.new { @test_group.assets.each(:group => @saved_photos) }.should.raise StandardError
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
|
3
|
+
describe MotionAL::Group do
|
4
|
+
before do
|
5
|
+
MotionAL::Group.find_all do |group, error|
|
6
|
+
@test_group = group if group.name == TEST_GROUP_NAME
|
7
|
+
end
|
8
|
+
|
9
|
+
MotionAL::Group.find_camera_roll do |group, error|
|
10
|
+
@camera_roll = group
|
11
|
+
end
|
12
|
+
|
13
|
+
MotionAL::Asset.find_all do |asset, error|
|
14
|
+
@test_asset = asset
|
15
|
+
end
|
16
|
+
wait_async(0.5)
|
17
|
+
end
|
18
|
+
|
19
|
+
# '.create' already tested by before section.
|
20
|
+
|
21
|
+
describe ".all" do
|
22
|
+
before do
|
23
|
+
@group = nil
|
24
|
+
@groups = []
|
25
|
+
MotionAL::Group.find_all do |group, error|
|
26
|
+
@group = group
|
27
|
+
@groups << group
|
28
|
+
end
|
29
|
+
wait_async
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should return Group object" do
|
33
|
+
@groups.size.should > 0
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should return Group object" do
|
37
|
+
@group.should.instance_of MotionAL::Group
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe ".find_by_url" do
|
42
|
+
it "should return Group object" do
|
43
|
+
MotionAL::Group.find_by_url(@test_group.url) do |group, error|
|
44
|
+
@group = group
|
45
|
+
end
|
46
|
+
wait_async
|
47
|
+
@group.url.should.equal @test_group.url
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should accept url string" do
|
51
|
+
MotionAL::Group.find_by_url(@test_group.url.absoluteString) do |group, error|
|
52
|
+
@group = group
|
53
|
+
end
|
54
|
+
wait_async
|
55
|
+
@group.url.should.equal @test_group.url
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe ".find_by_name" do
|
60
|
+
before do
|
61
|
+
if UIDevice.currentDevice.model =~ /simulator/i
|
62
|
+
@camera_roll_name = 'Saved Photos'
|
63
|
+
else
|
64
|
+
@camera_roll_name = 'Camera Roll'
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
it "can find 'Saved Photos'" do
|
69
|
+
@group = nil
|
70
|
+
MotionAL::Group.find_by_name(@camera_roll_name) do |group, error|
|
71
|
+
@group = group
|
72
|
+
end
|
73
|
+
|
74
|
+
wait_async
|
75
|
+
@group.name.should.equal @camera_roll_name
|
76
|
+
end
|
77
|
+
|
78
|
+
it "regexp" do
|
79
|
+
@group = nil
|
80
|
+
MotionAL::Group.find_by_name(/Saved Photos|Camera Roll/) do |group, error|
|
81
|
+
@group = group
|
82
|
+
end
|
83
|
+
|
84
|
+
wait_async
|
85
|
+
@group.name.should.equal @camera_roll_name
|
86
|
+
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe "#url" do
|
91
|
+
it "should return NSURL object" do
|
92
|
+
@test_group.url.should.instance_of NSURL
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe "#asset_group_type" do
|
97
|
+
it "should be human readable" do
|
98
|
+
@test_group.asset_group_type.should.instance_of Symbol
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe "#editable?" do
|
103
|
+
it "group is created by this App should be editable" do
|
104
|
+
@test_group.should.be.editable
|
105
|
+
end
|
106
|
+
|
107
|
+
it "default group (not created by this App) should not be editable" do
|
108
|
+
@camera_roll.should.not.be.editable
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe "#assets" do
|
113
|
+
describe ".create" do
|
114
|
+
it "should create new asset and add that to group" do
|
115
|
+
call_assets_create = Proc.new do
|
116
|
+
original_asset = @test_asset
|
117
|
+
@test_group.assets.create(original_asset.full_resolution_image, original_asset.metadata) {|a| "do nothing" }
|
118
|
+
end
|
119
|
+
call_assets_create.should.change { wait_async; @test_group.assets.count }
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
describe "#add_asset" do
|
125
|
+
it "should add an asset to the group." do
|
126
|
+
call_asset_save_new_and_add_group = Proc.new do
|
127
|
+
new_asset = nil
|
128
|
+
@test_asset.save_new(@test_asset.data) {|a| new_asset = a }
|
129
|
+
wait_async(0.5)
|
130
|
+
|
131
|
+
@test_group.add_asset(new_asset)
|
132
|
+
end
|
133
|
+
call_asset_save_new_and_add_group.should.change { wait_async; @test_group.assets.count }
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
describe MotionAL::Library do
|
4
|
+
before do
|
5
|
+
@library = MotionAL.library
|
6
|
+
|
7
|
+
MotionAL::Group.find_all do |group, error|
|
8
|
+
@test_group = group if group.name == TEST_GROUP_NAME
|
9
|
+
end
|
10
|
+
wait_async
|
11
|
+
end
|
12
|
+
|
13
|
+
describe ".groups" do
|
14
|
+
it "should be alias of MotionAL::Group" do
|
15
|
+
@library.groups.should == MotionAL::Group
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
|
3
|
+
describe MotionAL::Representation do
|
4
|
+
before do
|
5
|
+
MotionAL::Group.find_camera_roll do |group, error|
|
6
|
+
@saved_photos = group
|
7
|
+
end
|
8
|
+
wait_async(0.5)
|
9
|
+
|
10
|
+
@saved_photos.assets.each(filter: :photo) do |asset|
|
11
|
+
@asset = asset
|
12
|
+
end
|
13
|
+
wait_async(0.5)
|
14
|
+
|
15
|
+
@rep = @asset.rep
|
16
|
+
end
|
17
|
+
|
18
|
+
describe ".data" do
|
19
|
+
it "should return NSConcreteData(kind of NSData)" do
|
20
|
+
@rep.data.should.kind_of NSData
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe ".cg_image" do
|
25
|
+
it "should return something except nil. maybe CGImageRef" do
|
26
|
+
@rep.cg_image.should.not.nil
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe ".filename" do
|
31
|
+
it "should return filename" do
|
32
|
+
@rep.filename.should.match /jpg$|png$|mp4$/i
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# what's UTI?
|
37
|
+
describe ".UTI" do
|
38
|
+
it "should return public.jpeg?" do
|
39
|
+
@rep.UTI.should.match /public.jpeg|public.mpeg-4/i
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe ".metadata" do
|
44
|
+
it "should return metadata" do
|
45
|
+
@rep.metadata.should.kind_of Hash
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
describe ".url" do
|
51
|
+
it "should return NSURL object" do
|
52
|
+
@rep.url.should.kind_of NSURL
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# TODO: meta will be more handy
|
57
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
|
3
|
+
describe MotionAL::Representations do
|
4
|
+
before do
|
5
|
+
MotionAL::Group.find_camera_roll do |group, error|
|
6
|
+
@saved_photos = group
|
7
|
+
end
|
8
|
+
wait_async(1)
|
9
|
+
|
10
|
+
@saved_photos.assets.each do |asset|
|
11
|
+
@asset = asset
|
12
|
+
end
|
13
|
+
wait_async(1)
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#find_by_uti" do
|
17
|
+
it "should return Representation object" do
|
18
|
+
@asset.representations.find_by_uti(@asset.rep.UTI) do |rep|
|
19
|
+
@rep = rep
|
20
|
+
|
21
|
+
end
|
22
|
+
@rep.should.instance_of MotionAL::Representation
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should return nil when unknown UTI given" do
|
26
|
+
rep = @asset.representations.find_by_uti("hoge")
|
27
|
+
rep.should.be.nil
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#find_all" do
|
32
|
+
before do
|
33
|
+
@reps = []
|
34
|
+
@asset.representations.find_all do |rep|
|
35
|
+
@reps << rep
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should return array" do
|
40
|
+
@reps.first.should.instance_of MotionAL::Representation
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
|
3
|
+
# first run after reset ios simurator settings is fail. need before_script travis ci?
|
4
|
+
#
|
5
|
+
# rake spec files=spec_helper
|
6
|
+
#
|
7
|
+
|
8
|
+
TEST_GROUP_NAME = 'MotionAL'
|
9
|
+
|
10
|
+
describe "prepare" do
|
11
|
+
before do
|
12
|
+
library = MotionAL.library
|
13
|
+
|
14
|
+
image_url = NSURL.fileURLWithPath("#{NSBundle.mainBundle.resourcePath}/sample.jpg")
|
15
|
+
cg_image_source = CGImageSourceCreateWithURL(image_url, nil);
|
16
|
+
meta = CGImageSourceCopyPropertiesAtIndex(cg_image_source, 0, nil)
|
17
|
+
cg_image = CGImageSourceCreateImageAtIndex(cg_image_source, 0, nil)
|
18
|
+
MotionAL::Asset.create(cg_image, meta) {|a| @test_asset = a }
|
19
|
+
|
20
|
+
video_url = NSBundle.mainBundle.URLForResource('sample', withExtension:"mp4")
|
21
|
+
MotionAL::Asset.create(video_url)
|
22
|
+
|
23
|
+
library.groups.find_by_name(TEST_GROUP_NAME) {|g| @test_group = g }
|
24
|
+
wait_async
|
25
|
+
|
26
|
+
if !@test_group
|
27
|
+
MotionAL::Group.create(TEST_GROUP_NAME) {|g| @test_group = g }
|
28
|
+
end
|
29
|
+
|
30
|
+
MotionAL::Group.find_camera_roll {|g| @camera_roll = g }
|
31
|
+
wait_async(0.5)
|
32
|
+
|
33
|
+
@test_group.assets << @test_asset
|
34
|
+
end
|
35
|
+
|
36
|
+
it "dummy spec for waiting creating test files" do
|
37
|
+
1.should == 1
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
WAIT_ASYNC_DEFAULT_DURATION = 0.1
|
42
|
+
|
43
|
+
def wait_async(duration = WAIT_ASYNC_DEFAULT_DURATION, &block)
|
44
|
+
CFRunLoopRunInMode(KCFRunLoopDefaultMode, duration, false)
|
45
|
+
end
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: motional
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- akahigeg
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-07-26 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: motion-redgreen
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: AssetLibrary framework wrapper for RubyMotion
|
63
|
+
email:
|
64
|
+
- akahigeg@gmail.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- .travis.yml
|
71
|
+
- Gemfile
|
72
|
+
- Guardfile
|
73
|
+
- LICENSE.txt
|
74
|
+
- README.md
|
75
|
+
- Rakefile
|
76
|
+
- app/app_delegate.rb
|
77
|
+
- lib/motional.rb
|
78
|
+
- lib/motional/asset.rb
|
79
|
+
- lib/motional/assets.rb
|
80
|
+
- lib/motional/assets_filter.rb
|
81
|
+
- lib/motional/core.rb
|
82
|
+
- lib/motional/group.rb
|
83
|
+
- lib/motional/library.rb
|
84
|
+
- lib/motional/representation.rb
|
85
|
+
- lib/motional/representations.rb
|
86
|
+
- lib/motional/version.rb
|
87
|
+
- motional.gemspec
|
88
|
+
- resources/sample.jpg
|
89
|
+
- resources/sample.mp4
|
90
|
+
- spec/motional/asset_spec.rb
|
91
|
+
- spec/motional/assets_spec.rb
|
92
|
+
- spec/motional/group_spec.rb
|
93
|
+
- spec/motional/library_spec.rb
|
94
|
+
- spec/motional/representation_spec.rb
|
95
|
+
- spec/motional/representations_spec.rb
|
96
|
+
- spec/spec_helper.rb
|
97
|
+
homepage: https://github.com/akahigeg/motional
|
98
|
+
licenses:
|
99
|
+
- MIT
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
none: false
|
112
|
+
requirements:
|
113
|
+
- - ! '>='
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
requirements: []
|
117
|
+
rubyforge_project:
|
118
|
+
rubygems_version: 1.8.23
|
119
|
+
signing_key:
|
120
|
+
specification_version: 3
|
121
|
+
summary: AssetLibrary framework wrapper for RubyMotion
|
122
|
+
test_files:
|
123
|
+
- spec/motional/asset_spec.rb
|
124
|
+
- spec/motional/assets_spec.rb
|
125
|
+
- spec/motional/group_spec.rb
|
126
|
+
- spec/motional/library_spec.rb
|
127
|
+
- spec/motional/representation_spec.rb
|
128
|
+
- spec/motional/representations_spec.rb
|
129
|
+
- spec/spec_helper.rb
|
130
|
+
has_rdoc:
|