brototype 0.9.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 81577f0e2d734bb19ee551bced1b8a43fdc7a1b3
4
+ data.tar.gz: 9508802d6a24df70ec201e31d230f77f35bab2f3
5
+ SHA512:
6
+ metadata.gz: 43a16b9818cb34996f4b4e254bed2a659beac7e9670495affd418d72641ed0ea4e445baa07daf07616bc6114b67561bf3bdcedb119a0b3c05f652b5f6b6cf968
7
+ data.tar.gz: 7c8aaaec5046d3279fd2674b035303fd7f7208274b9fc4c62a55415834e4cf9626ba4f18d191df46448f8baef6efd2d1efc776710dbefacec1ab512ef2373446
Binary file
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in brototype.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Eric
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.
@@ -0,0 +1,29 @@
1
+ # Brototype
2
+
3
+ Bro, do you even Ruby?
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'brototype'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install brototype
20
+
21
+
22
+ ## Contributing
23
+
24
+ 1. Fork it ( https://github.com/[my-github-username]/brototype/fork )
25
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
26
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
27
+ 4. Push to the branch (`git push origin my-new-feature`)
28
+ 5. Create a new Pull Request
29
+
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'brototype/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "brototype"
8
+ spec.version = Brototype::VERSION
9
+ spec.authors = ["Eric"]
10
+ spec.email = ["ericschleeper@gmail.com"]
11
+ spec.summary = %q{Bro, do you even Ruby?}
12
+ spec.description = %q{Ruby port of the popular brototypejs library.}
13
+ spec.homepage = "https://github.com/eschleeper/brototype"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency 'rspec'
24
+ end
@@ -0,0 +1,3 @@
1
+ require "brototype/version"
2
+ require "brototype/bro"
3
+ require "brototype/bromise"
@@ -0,0 +1,56 @@
1
+ module Brototype
2
+ class Bro
3
+
4
+ TOTALLY = true
5
+ NOWAY = false
6
+
7
+ def initialize(obj)
8
+ @obj = obj;
9
+ end
10
+
11
+ def is_that_even_a_thing
12
+ (@obj.nil? || @obj.empty?) ? false : true
13
+ end
14
+
15
+ def do_you_even(key, options = {})
16
+ options_bro = Bro.new(options || {})
17
+ bro = self.i_can_haz(key)
18
+ if Bro.new(bro).is_that_even_a_thing == TOTALLY
19
+ TOTALLY;
20
+ else
21
+ NOWAY
22
+ end
23
+
24
+ end
25
+
26
+ def i_can_haz(key)
27
+ # TODO if key is an array, return all
28
+ if @obj.is_a?(Hash)
29
+ key.split('.').inject(@obj) do |c, v|
30
+ c.respond_to?(:keys) ? c[v] : nil
31
+ end
32
+ else
33
+ if @obj.respond_to?(key)
34
+ @obj.send(key)
35
+ elsif key.start_with?("@")
36
+ @obj.instance_variable_get(key)
37
+ else
38
+ nil
39
+ end
40
+ end
41
+ end
42
+
43
+ def all_the_things
44
+ # TODO
45
+ end
46
+
47
+ def i_dont_always(methodString)
48
+ Bromise.new(@obj, methodString)
49
+ end
50
+
51
+ def brace_yourself(methodString)
52
+ Bromise.new(@obj, methodString)
53
+ end
54
+
55
+ end
56
+ end
@@ -0,0 +1,40 @@
1
+ module Brototype
2
+
3
+ # Bromise... it's stronger than a Promise
4
+ class Bromise
5
+
6
+ def initialize(object, method=nil, args=[])
7
+ @object = object
8
+ @method = method
9
+ @args = args.count > 1 ? args.slice(1) : []
10
+ end
11
+
12
+ def but_when_i_do(callback=nil)
13
+ if @object.respond_to? @method
14
+ return_value = @object.send(@method)
15
+ if return_value
16
+ (callback || (lambda {|x|1})).call return_value
17
+ end
18
+ end
19
+ end
20
+
21
+ def here_come_the_errors(callback=nil)
22
+ if @object.respond_to? @method
23
+ begin
24
+ @object.send(@method)
25
+ rescue Exception => e
26
+ callback.call e
27
+ end
28
+ else
29
+ callback(@method + ' is not a proc');
30
+ end
31
+ end
32
+
33
+ def errors_are_coming
34
+ self.here_come_the_errors.call
35
+ end
36
+
37
+ end
38
+
39
+ end
40
+
@@ -0,0 +1,3 @@
1
+ module Brototype
2
+ VERSION = "0.9.0"
3
+ end
@@ -0,0 +1,111 @@
1
+ require 'spec_helper'
2
+
3
+ describe Brototype do
4
+
5
+ before do
6
+ @bro = Brototype::Bro.new('foo' => {'bar' => 'baz'})
7
+ @anon_class = Foo.new
8
+ end
9
+
10
+ describe '#do_you_even' do
11
+
12
+ it 'should return true for defined properties' do
13
+ expect(@bro.do_you_even('foo')).to be true
14
+ end
15
+
16
+ it 'should return true for nested properties' do
17
+ expect(@bro.do_you_even('foo.bar')).to be true
18
+ end
19
+
20
+ it 'should return false for undefined properties' do
21
+ expect(@bro.do_you_even('foo.nada')).to be false
22
+ end
23
+
24
+ end
25
+
26
+ describe '#i_can_haz' do
27
+
28
+ it 'should return the value of the deep property' do
29
+ expect(@bro.i_can_haz('foo.bar')).to eq('baz')
30
+ end
31
+
32
+ it 'should return nil for missing property' do
33
+ expect(@bro.i_can_haz('foo.nada')).to be_nil
34
+ end
35
+
36
+ end
37
+
38
+ describe '#all_the_things' do
39
+
40
+ it 'should return an object\'s keys' do
41
+ keys = @bro.all_the_things
42
+
43
+
44
+ end
45
+
46
+ it 'should return the keys in order' do
47
+ # TODO
48
+ end
49
+
50
+ end
51
+
52
+ describe '#i_dont_always' do
53
+
54
+ it 'should check that the requested method is a function' do
55
+ success = false
56
+ @anon_bro = Brototype::Bro.new(@anon_class)
57
+
58
+ @anon_bro.i_dont_always('bar').but_when_i_do(lambda { |x|
59
+ success = true
60
+ })
61
+ expect(success).to be false
62
+
63
+ @anon_bro.i_dont_always('foo').but_when_i_do(lambda { |x|
64
+ success = true
65
+ })
66
+ expect(success).to be true
67
+ end
68
+
69
+ it 'should run the requested method if a function' do
70
+
71
+ fn = lambda {|x|1}
72
+ @anon_bro = Brototype::Bro.new(@anon_class)
73
+
74
+ @anon_bro.i_dont_always('bar').but_when_i_do(fn)
75
+ expect(@anon_bro.i_can_haz('fired')).to be false
76
+
77
+ @anon_bro.i_dont_always('foo').but_when_i_do(fn)
78
+ expect(@anon_bro.i_can_haz('fired')).to be true
79
+ end
80
+
81
+ it 'should pass the method\'s return value as param to callback' do
82
+ param = nil
83
+ Brototype::Bro.new(@anon_class).i_dont_always('foo').but_when_i_do(lambda { |x|
84
+ param = x
85
+ })
86
+ expect(param).to be 91
87
+ end
88
+
89
+ end
90
+
91
+ describe '#brace_yourself' do
92
+
93
+ it 'should fire the callback when an exception is thrown' do
94
+ success = false
95
+ Brototype::Bro.new(@anon_class).brace_yourself('throws_error').here_come_the_errors(lambda { |x|
96
+ success = true
97
+ })
98
+ expect(success).to be true
99
+ end
100
+
101
+ it 'should pass the error to the callback' do
102
+ error = nil
103
+ Brototype::Bro.new(@anon_class).brace_yourself('throws_error').here_come_the_errors(lambda { |x|
104
+ error = x
105
+ })
106
+ expect(error.class).to eq(ArgumentError)
107
+ end
108
+
109
+ end
110
+
111
+ end
@@ -0,0 +1,22 @@
1
+ require 'brototype'
2
+
3
+ class Foo
4
+ attr_accessor :fired
5
+
6
+ def initialize
7
+ @fired = false
8
+ @success = false
9
+ @param = nil
10
+ @bar = 3
11
+ end
12
+
13
+ def foo
14
+ @fired = true
15
+ 91
16
+ end
17
+
18
+ def throws_error
19
+ throw :an_error
20
+ end
21
+
22
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: brototype
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ platform: ruby
6
+ authors:
7
+ - Eric
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-25 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.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Ruby port of the popular brototypejs library.
56
+ email:
57
+ - ericschleeper@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .DS_Store
63
+ - .gitignore
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - brototype.gemspec
69
+ - lib/brototype.rb
70
+ - lib/brototype/bro.rb
71
+ - lib/brototype/bromise.rb
72
+ - lib/brototype/version.rb
73
+ - spec/brototype_spec.rb
74
+ - spec/spec_helper.rb
75
+ homepage: https://github.com/eschleeper/brototype
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.2.2
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Bro, do you even Ruby?
99
+ test_files:
100
+ - spec/brototype_spec.rb
101
+ - spec/spec_helper.rb