nkpart-prohax 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,6 @@
1
+ 1770 Captain Cook landed on the East coast of Australia.
2
+
3
+ == 0.0.1 2008-11-12
4
+
5
+ * 1 major enhancement:
6
+ * Initial release
@@ -0,0 +1,28 @@
1
+ History.txt
2
+ Manifest.txt
3
+ PostInstall.txt
4
+ README.txt
5
+ Rakefile
6
+ coverage/index.html
7
+ coverage/lib-prohax-box_rb.html
8
+ coverage/lib-prohax-either_rb.html
9
+ coverage/lib-prohax-let_in_rb.html
10
+ coverage/lib-prohax-strucked_rb.html
11
+ coverage/lib-prohax_rb.html
12
+ lib/prohax.rb
13
+ lib/prohax/box.rb
14
+ lib/prohax/either.rb
15
+ lib/prohax/let_in.rb
16
+ lib/prohax/strucked.rb
17
+ prohax.gemspec
18
+ script/console
19
+ script/destroy
20
+ script/generate
21
+ spec/box_spec.rb
22
+ spec/either_spec.rb
23
+ spec/let_in_syntax_spec.rb
24
+ spec/spec.opts
25
+ spec/spec_helper.rb
26
+ spec/strucked_spec.rb
27
+ tasks/rspec.rake
28
+ test_gem.sh
@@ -0,0 +1 @@
1
+ Because hax is pro and pro is good.
@@ -0,0 +1,71 @@
1
+ = prohax
2
+
3
+ * http://github.com/nkpart/prohax
4
+
5
+ == What?
6
+
7
+ Just some hax that I use.
8
+
9
+ == Contents
10
+
11
+ * Let-in - a neat syntax that's a bit like haskell. Contents of the hash supplied to `let()`
12
+ are defined as functions on a container, on which the block passed to `in` is instance_eval'd with.
13
+
14
+ let( :awesome => proc { |n| "#{n} is awesome." }).in { [1,2,3].map { |e| awesome(e) }
15
+
16
+ * Strucked - a class builder, that just instantiates instance vars
17
+
18
+ # before
19
+ class Foo
20
+ def initialize a, b
21
+ @a = a
22
+ @b = b
23
+ end
24
+ end
25
+
26
+ # after
27
+ class Foo < Strucked.build(:a, :b)
28
+ end
29
+
30
+ * Kernel#either - a kind of either-like thing.
31
+
32
+ # If no exceptions are thrown, `failure` will be nil and `success` will be the result of the block.
33
+ # Otherwise, success will be nil and failure will hold the exception
34
+ success, failure = either {
35
+ raise "fail"
36
+ }
37
+ failure # <= RuntimeError('fail')
38
+
39
+ success, failure = either { 5 }
40
+ success # <= 5
41
+
42
+
43
+
44
+ == SYNOPSIS:
45
+
46
+ FIX (code sample of usage)
47
+
48
+ == LICENSE:
49
+
50
+ (The MIT License)
51
+
52
+ Copyright (c) 2008 FIXME full name
53
+
54
+ Permission is hereby granted, free of charge, to any person obtaining
55
+ a copy of this software and associated documentation files (the
56
+ 'Software'), to deal in the Software without restriction, including
57
+ without limitation the rights to use, copy, modify, merge, publish,
58
+ distribute, sublicense, and/or sell copies of the Software, and to
59
+ permit persons to whom the Software is furnished to do so, subject to
60
+ the following conditions:
61
+
62
+ The above copyright notice and this permission notice shall be
63
+ included in all copies or substantial portions of the Software.
64
+
65
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
66
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
67
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
68
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
69
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
70
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
71
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,20 @@
1
+ %w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f }
2
+ require File.dirname(__FILE__) + '/lib/prohax'
3
+
4
+ # Generate all the Rake tasks
5
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
6
+ $hoe = Hoe.new('prohax', Prohax::VERSION) do |p|
7
+ p.developer('Nick Partridge', 'nkpart@gmail.com')
8
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
9
+ p.rubyforge_name = p.name # TODO this is default value
10
+ p.clean_globs |= %w[**/.DS_Store tmp *.log]
11
+ path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
12
+ p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
13
+ p.rsync_args = '-av --delete --ignore-errors'
14
+ end
15
+
16
+ require 'newgem/tasks' # load /tasks/*.rake
17
+ Dir['tasks/**/*.rake'].each { |t| load t }
18
+
19
+ task "build" => ["spec", "verify_rcov"]
20
+ task :default => [:build]
@@ -0,0 +1,10 @@
1
+ $: << File.expand_path(File.dirname(__FILE__))
2
+
3
+ module Prohax
4
+ VERSION = '1.0.1'
5
+ end
6
+
7
+ require 'prohax/strucked'
8
+ require 'prohax/let_in'
9
+ require 'prohax/either'
10
+ require 'prohax/box'
@@ -0,0 +1,5 @@
1
+ class Object
2
+ def box
3
+ self.is_a?(Array) ? self : [self]
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ module Kernel
2
+ def either
3
+ [yield, nil]
4
+ rescue Exception => e
5
+ [nil, e]
6
+ end
7
+ end
@@ -0,0 +1,32 @@
1
+ require 'prohax/strucked'
2
+
3
+ class Container
4
+ def initialize defines
5
+ defines.each do |key, value|
6
+ if value.respond_to? :call then
7
+ self.class.class_eval {
8
+ define_method(key) { |*args| value.call *args }
9
+ }
10
+ else
11
+ self.class.class_eval {
12
+ define_method(key) { value }
13
+ }
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+ class LetProxy < Strucked.build(:defines)
20
+ # def initialize defines
21
+ # @defines = defines
22
+ # end
23
+ def in &blk
24
+ Container.new(@defines).instance_eval &blk
25
+ end
26
+ end
27
+
28
+ module Kernel
29
+ def let defines
30
+ LetProxy.new(defines)
31
+ end
32
+ end
@@ -0,0 +1,21 @@
1
+
2
+ class Strucked
3
+ def self.build *fields
4
+ cls = Class.new
5
+ cls.class_eval <<EOS
6
+ def self.fields
7
+ #{fields.inspect}
8
+ end
9
+
10
+ def initialize *values
11
+ if self.class.fields.size != values.size
12
+ raise ArgumentError.new("Wrong number of arguments, expected \#\{self.class.fields.size\} got \#\{values.size\}")
13
+ end
14
+ self.class.fields.zip(values).each do |fld, value|
15
+ self.instance_variable_set("@\#\{fld\}", value)
16
+ end
17
+ end
18
+ EOS
19
+ cls
20
+ end
21
+ end
@@ -0,0 +1,34 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{prohax}
5
+ s.version = "1.0.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Nick Partridge"]
9
+ s.date = %q{2008-11-18}
10
+ s.description = %q{}
11
+ s.email = ["nkpart@gmail.com"]
12
+ s.extra_rdoc_files = ["History.txt", "Manifest.txt", "PostInstall.txt", "README.txt"]
13
+ s.files = ["History.txt", "Manifest.txt", "PostInstall.txt", "README.txt", "Rakefile", "coverage/index.html", "coverage/lib-prohax-box_rb.html", "coverage/lib-prohax-either_rb.html", "coverage/lib-prohax-let_in_rb.html", "coverage/lib-prohax-strucked_rb.html", "coverage/lib-prohax_rb.html", "lib/prohax.rb", "lib/prohax/box.rb", "lib/prohax/either.rb", "lib/prohax/let_in.rb", "lib/prohax/strucked.rb", "prohax.gemspec", "script/console", "script/destroy", "script/generate", "spec/box_spec.rb", "spec/either_spec.rb", "spec/let_in_syntax_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "spec/strucked_spec.rb", "tasks/rspec.rake", "test_gem.sh"]
14
+ s.has_rdoc = true
15
+ s.homepage = %q{http://github.com/nkpart/prohax}
16
+ s.rdoc_options = ["--main", "README.txt"]
17
+ s.require_paths = ["lib"]
18
+ s.rubyforge_project = %q{prohax}
19
+ s.rubygems_version = %q{1.3.1}
20
+ s.summary = %q{}
21
+
22
+ if s.respond_to? :specification_version then
23
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
+ s.specification_version = 2
25
+
26
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
27
+ s.add_development_dependency(%q<hoe>, [">= 1.8.0"])
28
+ else
29
+ s.add_dependency(%q<hoe>, [">= 1.8.0"])
30
+ end
31
+ else
32
+ s.add_dependency(%q<hoe>, [">= 1.8.0"])
33
+ end
34
+ end
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/prohax.rb'}"
9
+ puts "Loading prohax gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
@@ -0,0 +1,13 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe "the box function" do
4
+ it "should wrap singles in arrays" do
5
+ 5.box.should == [5]
6
+ {}.box.should == [{}]
7
+ end
8
+
9
+ it "should leave arrays alone" do
10
+ [1].box.should == [1]
11
+ end
12
+ end
13
+
@@ -0,0 +1,17 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe "the either function" do
4
+ it "should be [nil, exception] in case of failure" do
5
+ f = ArgumentError.new "fail"
6
+ left, right = either { raise f }
7
+ left.should be_nil
8
+ right.should == f
9
+ end
10
+
11
+ it "should be [result, nil] in case of success" do
12
+ left, right = either { 5 }
13
+ left.should == 5
14
+ right.should be_nil
15
+ end
16
+ end
17
+
@@ -0,0 +1,19 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe "The let().in {} syntax" do
4
+ it "should be let-like and in-ish" do
5
+ let(:foo => 5 ).in { foo }.should == 5
6
+ end
7
+
8
+ it "should be mad" do
9
+ x = 5
10
+ let(
11
+ :plus => proc { |a,b| a + b },
12
+ :times => proc { |a,b| a * b },
13
+ :five => proc { 5 },
14
+ :fast_five => 5
15
+ ).in {
16
+ plus(x, times(five, plus(1, fast_five)))
17
+ }.should == 35
18
+ end
19
+ end
@@ -0,0 +1 @@
1
+ --colour
@@ -0,0 +1,10 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ gem 'rspec'
6
+ require 'spec'
7
+ end
8
+
9
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
10
+ require 'prohax'
@@ -0,0 +1,34 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe Strucked do
4
+ it "should create a class with instance variables set" do
5
+ x = Strucked.build(:foo).new 5
6
+ x.instance_variable_get("@foo").should == 5
7
+ end
8
+
9
+ it "should fail on create if the number of args is wrong" do
10
+ proc {
11
+ Strucked.build(:foo, :bar).new("a")
12
+ }.should raise_error
13
+ end
14
+
15
+ it "should not fail if multiple Struckeds are used" do
16
+ f = Strucked.build(:f)
17
+ a = Strucked.build(:a, :b)
18
+
19
+ f.new(1).instance_variable_get("@f").should == 1
20
+ a.new(1,2).instance_variable_get("@b").should == 2
21
+ end
22
+
23
+ it "should work with inheritance" do
24
+ class C < Strucked.build(:c); end
25
+ C.fields.should == [:c]
26
+ C.new(5).instance_variable_get("@c").should == 5
27
+ end
28
+
29
+ it "does not create accessors" do
30
+ proc { Strucked.new(:foo).new(5).foo }.should raise_error
31
+ end
32
+
33
+ end
34
+
@@ -0,0 +1,29 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ require 'spec'
6
+ end
7
+ begin
8
+ require 'spec/rake/spectask'
9
+ require 'spec/rake/verify_rcov'
10
+ rescue LoadError
11
+ puts <<-EOS
12
+ To use rspec for testing you must install rspec gem:
13
+ gem install rspec
14
+ EOS
15
+ exit(0)
16
+ end
17
+
18
+ desc "coverage"
19
+ RCov::VerifyTask.new do |t|
20
+ t.threshold = 100
21
+ end
22
+
23
+ desc "Run the specs under spec/models"
24
+ Spec::Rake::SpecTask.new do |t|
25
+ t.spec_opts = ['--options', "spec/spec.opts"]
26
+ t.spec_files = FileList['spec/**/*_spec.rb']
27
+ t.rcov_opts = ['--exclude', 'spec']
28
+ t.rcov = true
29
+ end
@@ -0,0 +1,3 @@
1
+ rake manifest
2
+ rake package
3
+ sudo gem install pkg/prohax-1.0.1.gem
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nkpart-prohax
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Nick Partridge
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-11-18 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoe
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.8.0
23
+ version:
24
+ description: ""
25
+ email:
26
+ - nkpart@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - History.txt
33
+ - Manifest.txt
34
+ - PostInstall.txt
35
+ - README.txt
36
+ files:
37
+ - History.txt
38
+ - Manifest.txt
39
+ - PostInstall.txt
40
+ - README.txt
41
+ - Rakefile
42
+ - coverage/index.html
43
+ - coverage/lib-prohax-box_rb.html
44
+ - coverage/lib-prohax-either_rb.html
45
+ - coverage/lib-prohax-let_in_rb.html
46
+ - coverage/lib-prohax-strucked_rb.html
47
+ - coverage/lib-prohax_rb.html
48
+ - lib/prohax.rb
49
+ - lib/prohax/box.rb
50
+ - lib/prohax/either.rb
51
+ - lib/prohax/let_in.rb
52
+ - lib/prohax/strucked.rb
53
+ - prohax.gemspec
54
+ - script/console
55
+ - script/destroy
56
+ - script/generate
57
+ - spec/box_spec.rb
58
+ - spec/either_spec.rb
59
+ - spec/let_in_syntax_spec.rb
60
+ - spec/spec.opts
61
+ - spec/spec_helper.rb
62
+ - spec/strucked_spec.rb
63
+ - tasks/rspec.rake
64
+ - test_gem.sh
65
+ has_rdoc: true
66
+ homepage: http://github.com/nkpart/prohax
67
+ post_install_message:
68
+ rdoc_options:
69
+ - --main
70
+ - README.txt
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: "0"
78
+ version:
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: "0"
84
+ version:
85
+ requirements: []
86
+
87
+ rubyforge_project: prohax
88
+ rubygems_version: 1.2.0
89
+ signing_key:
90
+ specification_version: 2
91
+ summary: ""
92
+ test_files: []
93
+