viper 0.1.0
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.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +9 -0
- data/LICENSE.txt +22 -0
- data/README.md +42 -0
- data/Rakefile +15 -0
- data/app/app_delegate.rb +2 -0
- data/lib/viper.rb +9 -0
- data/lib/viper/snake_case.rb +29 -0
- data/lib/viper/version.rb +3 -0
- data/spec/helpers/dummy.rb +3 -0
- data/spec/respond_to_spec.rb +32 -0
- data/spec/snake_case_spec.rb +32 -0
- data/viper.gemspec +23 -0
- metadata +90 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 57fb9a793bbe0cb37398c7dece916c5252f827ee
|
4
|
+
data.tar.gz: 6542f737b764df5686ab9cd3113d58ab109446d6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 145bcec3ca6730da0bcb6244b8d87aaace847fd4ce02605eca5120d7c0ebcc0d048a9ed8d86ed37babf8f04d1619f9e97dfbb959aef7c20f62ff9636c3199fc5
|
7
|
+
data.tar.gz: 79efc08b204feebf2f6bec2783dc0766251e712c46e41d5684df30aeadb308c0ad588e5bbc682ef769bb5dd36c221b30d162ec71d470406380d00c672317b532
|
data/.gitignore
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
viper
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.0.0
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Jamon Holmgren
|
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,42 @@
|
|
1
|
+
# Viper
|
2
|
+
|
3
|
+
Automatic snake case for Objective-C methods in RubyMotion.
|
4
|
+
|
5
|
+
v = UIView.new # => #<UIView:0xaa45260>
|
6
|
+
v.background_color = UIColor.white_color # => #<UICachedDeviceWhiteColor:0xaa41180>
|
7
|
+
v.backgroundColor => #<UICachedDeviceWhiteColor:0x967c2e0>
|
8
|
+
v.asdf # => #<NoMethodError: asdf>
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
gem 'viper', "~> 0.0.1"
|
15
|
+
|
16
|
+
## Usage
|
17
|
+
|
18
|
+
class MyView < UIView
|
19
|
+
include Viper::SnakeCase
|
20
|
+
end
|
21
|
+
class MyColor < UIColor
|
22
|
+
include Viper::SnakeCase
|
23
|
+
end
|
24
|
+
|
25
|
+
v = MyView.new
|
26
|
+
v.background_color = MyColor.white_color
|
27
|
+
|
28
|
+
Or...
|
29
|
+
|
30
|
+
class NSObject
|
31
|
+
include Viper::SnakeCase
|
32
|
+
end
|
33
|
+
|
34
|
+
# Now everything has snake case...
|
35
|
+
|
36
|
+
## Contributing
|
37
|
+
|
38
|
+
1. Fork it
|
39
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
40
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
41
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
42
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
$:.unshift("/Library/RubyMotion/lib")
|
2
|
+
require 'motion/project'
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
Bundler.setup
|
5
|
+
Bundler.require
|
6
|
+
|
7
|
+
Motion::Project::App.setup do |app|
|
8
|
+
app.name = 'ViperTest'
|
9
|
+
app.version = "0.99.0"
|
10
|
+
app.redgreen_style = :focused # :focused, :full
|
11
|
+
|
12
|
+
# Devices
|
13
|
+
app.deployment_target = "5.0"
|
14
|
+
app.detect_dependencies = true
|
15
|
+
end
|
data/app/app_delegate.rb
ADDED
data/lib/viper.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
unless defined?(Motion::Project::Config)
|
2
|
+
raise "This file must be required within a RubyMotion project Rakefile."
|
3
|
+
end
|
4
|
+
|
5
|
+
require "viper/version"
|
6
|
+
|
7
|
+
Motion::Project::App.setup do |app|
|
8
|
+
app.files += FileList[File.join(File.dirname(__FILE__), 'viper/**/*.rb')].to_a
|
9
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Viper
|
2
|
+
module SnakeCase
|
3
|
+
def method_missing(meth, *args)
|
4
|
+
obj_c_meth = objective_c_method_name(meth)
|
5
|
+
if respond_to?(obj_c_meth)
|
6
|
+
send obj_c_meth, *args
|
7
|
+
else
|
8
|
+
raise NoMethodError.new(meth.to_s)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def respond_to?(meth, *a)
|
13
|
+
super || super(objective_c_method_name(meth), *a)
|
14
|
+
end
|
15
|
+
|
16
|
+
# respond_to_missing? doesn't seem to work this way.
|
17
|
+
# Just don't use .method() with snake case method names.
|
18
|
+
# def respond_to_missing?(meth, *a)
|
19
|
+
# super || super(objective_c_method_name(meth), *a)
|
20
|
+
# end
|
21
|
+
|
22
|
+
protected
|
23
|
+
|
24
|
+
def objective_c_method_name(meth)
|
25
|
+
meth.split('_').inject([]){ |buffer,e| buffer.push(buffer.empty? ? e : e.capitalize) }.join
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
describe "viper snake case module - respond_to?" do
|
2
|
+
before {
|
3
|
+
@view = UIView.new
|
4
|
+
@view.extend Viper::SnakeCase
|
5
|
+
}
|
6
|
+
|
7
|
+
it "should respond_to? valid snake case methods" do
|
8
|
+
@view.respond_to?(:background_color).should == true
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should not respond_to? invalid snake case methods" do
|
12
|
+
@view.respond_to?(:asdf).should == false
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should still respond_to? valid camelCase methods" do
|
16
|
+
@view.respond_to?(:backgroundColor).should == true
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should not respond_to? invalid camelCase methods" do
|
20
|
+
@view.respond_to?(:asdfAsdf).should == false
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should allow method on valid snake_case methods" do
|
24
|
+
@view.method(:backgroundColor).is_a?(Method).should == true
|
25
|
+
end
|
26
|
+
|
27
|
+
# Doesn't work. Use camelCase if you're using `method`.
|
28
|
+
# it "should allow method on valid snake_case methods" do
|
29
|
+
# @view.method(:background_color).should == true
|
30
|
+
# end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
describe "viper snake case module" do
|
2
|
+
before {
|
3
|
+
@view = UIView.new
|
4
|
+
@view.extend Viper::SnakeCase
|
5
|
+
}
|
6
|
+
|
7
|
+
it "should have 'Viper' module" do
|
8
|
+
should.not.raise(NameError) { Viper }
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should have 'Viper::SnakeCase' module" do
|
12
|
+
should.not.raise(NameError) { Viper::SnakeCase }
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should allow inclusion into any Objective-C class" do
|
16
|
+
should.not.raise(StandardError) { @view.extend Viper::SnakeCase }
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should allow `background_color` instead of `backgroundColor`" do
|
20
|
+
@view.background_color.should == nil
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should allow assigning the backgroundColor using snake case" do
|
24
|
+
@view.background_color = UIColor.redColor
|
25
|
+
@view.backgroundColor.should == UIColor.redColor
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should not affect other classes" do
|
29
|
+
r = UIColor.red_color rescue nil
|
30
|
+
r.should == nil
|
31
|
+
end
|
32
|
+
end
|
data/viper.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'viper/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "viper"
|
8
|
+
spec.version = Viper::VERSION
|
9
|
+
spec.authors = ["Jamon Holmgren"]
|
10
|
+
spec.email = ["jamon@clearsightstudio.com"]
|
11
|
+
spec.description = %q{Auto snake case for Objective-C methods in RubyMotion}
|
12
|
+
spec.summary = %q{Auto snake case for Objective-C methods in RubyMotion}
|
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
|
+
end
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: viper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jamon Holmgren
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-04-29 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
|
+
description: Auto snake case for Objective-C methods in RubyMotion
|
42
|
+
email:
|
43
|
+
- jamon@clearsightstudio.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- .ruby-gemset
|
50
|
+
- .ruby-version
|
51
|
+
- Gemfile
|
52
|
+
- LICENSE.txt
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- app/app_delegate.rb
|
56
|
+
- lib/viper.rb
|
57
|
+
- lib/viper/snake_case.rb
|
58
|
+
- lib/viper/version.rb
|
59
|
+
- spec/helpers/dummy.rb
|
60
|
+
- spec/respond_to_spec.rb
|
61
|
+
- spec/snake_case_spec.rb
|
62
|
+
- viper.gemspec
|
63
|
+
homepage: ''
|
64
|
+
licenses:
|
65
|
+
- MIT
|
66
|
+
metadata: {}
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 2.0.0
|
84
|
+
signing_key:
|
85
|
+
specification_version: 4
|
86
|
+
summary: Auto snake case for Objective-C methods in RubyMotion
|
87
|
+
test_files:
|
88
|
+
- spec/helpers/dummy.rb
|
89
|
+
- spec/respond_to_spec.rb
|
90
|
+
- spec/snake_case_spec.rb
|