konjure-bundler-fix 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +40 -0
- data/Rakefile +2 -0
- data/konjure.gemspec +23 -0
- data/lib/konjure.rb +11 -0
- data/lib/konjure/define_method.rb +60 -0
- data/lib/konjure/version.rb +3 -0
- metadata +82 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Dave Lee
|
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,40 @@
|
|
1
|
+
# Konjure
|
2
|
+
|
3
|
+
Konjure provides improved metaprogramming facilities to
|
4
|
+
RubyMotion. Currently, Konjure provides a no-hack implementation of
|
5
|
+
`define_method` using the Objective-C runtime.
|
6
|
+
|
7
|
+
More metaprogramming to come. There will be gotchas.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your app's Rakefile:
|
12
|
+
|
13
|
+
require 'konjure'
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
### define_method
|
18
|
+
|
19
|
+
Use define_method only for methods that will be called from within
|
20
|
+
Ruby code, or methods called from Objective-C code that take and
|
21
|
+
return objects. For methods that have alternative signatures, use
|
22
|
+
`objc_define_method`.
|
23
|
+
|
24
|
+
Note: At this time, using define_method with a block that contains
|
25
|
+
mutltiple default values results in undefined behavior.
|
26
|
+
|
27
|
+
### objc_define_method
|
28
|
+
|
29
|
+
As the name suggests, this is an Objective-C variation on
|
30
|
+
`define_method` that allows the caller to precisely declare the method
|
31
|
+
signatures. This method can be used to generate delegate methods or
|
32
|
+
other methods called by Objective-C calling code.
|
33
|
+
|
34
|
+
## Contributing
|
35
|
+
|
36
|
+
1. Fork it
|
37
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
38
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
39
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
40
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/konjure.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/konjure/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.name = 'konjure-bundler-fix'
|
6
|
+
gem.description = 'Konjure endows RubyMotion with greater metaprogramming capabilites'
|
7
|
+
gem.homepage = "https://github.com/kastiglione/#{gem.name}"
|
8
|
+
gem.version = Konjure::VERSION
|
9
|
+
|
10
|
+
gem.authors = ['Dave Lee']
|
11
|
+
gem.email = ['dave@kastiglione.com']
|
12
|
+
|
13
|
+
gem.files = `git ls-files`.split($\)
|
14
|
+
gem.require_paths = ['lib']
|
15
|
+
|
16
|
+
gem.add_dependency 'motion-objc-runtime-bundler-fix'
|
17
|
+
|
18
|
+
gem.summary = <<-END.gsub(/^ +/, '')
|
19
|
+
Konjure provides improved metaprogramming facilities to
|
20
|
+
RubyMotion. Currently, Konjure provides a no-hack implementation
|
21
|
+
of #define_method using the Objective-C runtime.
|
22
|
+
END
|
23
|
+
end
|
data/lib/konjure.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'motion-objc-runtime'
|
2
|
+
|
3
|
+
unless defined? Motion::Project::App
|
4
|
+
raise 'This file must be required within a RubyMotion project Rakefile.'
|
5
|
+
end
|
6
|
+
|
7
|
+
Motion::Project::App.setup do |app|
|
8
|
+
dirname = File.dirname(__FILE__)
|
9
|
+
descendant_ruby_files = Dir["#{dirname}/*/**/*.rb"]
|
10
|
+
app.files.insert(0, *descendant_ruby_files)
|
11
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Module
|
2
|
+
|
3
|
+
# Overwrite the existing useless implementation
|
4
|
+
def define_method(name, &block)
|
5
|
+
raise ArgumentError, 'Block required' if block.nil?
|
6
|
+
|
7
|
+
signature = Konjure::objc_parameter_signature(block)
|
8
|
+
objc_define_method(name, :object, signature, &block)
|
9
|
+
end
|
10
|
+
|
11
|
+
def objc_define_method(name, *types, &block)
|
12
|
+
return_type, *parameter_types = Konjure::encode_objc_types(types)
|
13
|
+
return_type ||= '@'
|
14
|
+
parameter_types.join('')
|
15
|
+
|
16
|
+
signature = "#{return_type}@:#{parameter_types}"
|
17
|
+
class_replaceMethod(self, name.to_sym, block, signature.UTF8String)
|
18
|
+
|
19
|
+
block
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
module Konjure
|
25
|
+
|
26
|
+
def self.encode_objc_types(types)
|
27
|
+
types.flatten.map do |type|
|
28
|
+
TYPE_SHORTCUTS[type] || type
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.objc_parameter_signature(block)
|
33
|
+
'@' * block.arity.abs
|
34
|
+
end
|
35
|
+
|
36
|
+
TYPE_SHORTCUTS = {
|
37
|
+
bool: 'B',
|
38
|
+
boolean: 'B',
|
39
|
+
char: 'c',
|
40
|
+
class: '#',
|
41
|
+
double: 'd',
|
42
|
+
float: 'f',
|
43
|
+
id: '@',
|
44
|
+
int: 'i',
|
45
|
+
long: 'l',
|
46
|
+
long_long: 'q',
|
47
|
+
object: '@',
|
48
|
+
pointer: '^',
|
49
|
+
sel: ':',
|
50
|
+
selector: ':',
|
51
|
+
short: 's',
|
52
|
+
string: '*',
|
53
|
+
uchar: 'C',
|
54
|
+
uint: 'I',
|
55
|
+
ulong: 'L',
|
56
|
+
ulong_long: 'Q',
|
57
|
+
ushort: 'S',
|
58
|
+
}
|
59
|
+
|
60
|
+
end
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: konjure-bundler-fix
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 3
|
9
|
+
version: 0.0.3
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Dave Lee
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2012-08-18 00:00:00 -04:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: motion-objc-runtime-bundler-fix
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
type: :runtime
|
31
|
+
version_requirements: *id001
|
32
|
+
description: Konjure endows RubyMotion with greater metaprogramming capabilites
|
33
|
+
email:
|
34
|
+
- dave@kastiglione.com
|
35
|
+
executables: []
|
36
|
+
|
37
|
+
extensions: []
|
38
|
+
|
39
|
+
extra_rdoc_files: []
|
40
|
+
|
41
|
+
files:
|
42
|
+
- .gitignore
|
43
|
+
- Gemfile
|
44
|
+
- LICENSE
|
45
|
+
- README.md
|
46
|
+
- Rakefile
|
47
|
+
- konjure.gemspec
|
48
|
+
- lib/konjure.rb
|
49
|
+
- lib/konjure/define_method.rb
|
50
|
+
- lib/konjure/version.rb
|
51
|
+
has_rdoc: true
|
52
|
+
homepage: https://github.com/kastiglione/konjure-bundler-fix
|
53
|
+
licenses: []
|
54
|
+
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
segments:
|
65
|
+
- 0
|
66
|
+
version: "0"
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
segments:
|
72
|
+
- 0
|
73
|
+
version: "0"
|
74
|
+
requirements: []
|
75
|
+
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 1.3.6
|
78
|
+
signing_key:
|
79
|
+
specification_version: 3
|
80
|
+
summary: "Konjure provides improved metaprogramming facilities to RubyMotion. Currently, Konjure provides a no-hack implementation of #define_method using the Objective-C runtime."
|
81
|
+
test_files: []
|
82
|
+
|