rayt 0.0.1

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.
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "http://rubygems.org"
2
+ gemspec
@@ -0,0 +1,26 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rays (0.0.1)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.1.3)
10
+ rake (0.9.2.2)
11
+ rspec (2.10.0)
12
+ rspec-core (~> 2.10.0)
13
+ rspec-expectations (~> 2.10.0)
14
+ rspec-mocks (~> 2.10.0)
15
+ rspec-core (2.10.0)
16
+ rspec-expectations (2.10.0)
17
+ diff-lcs (~> 1.1.3)
18
+ rspec-mocks (2.10.1)
19
+
20
+ PLATFORMS
21
+ ruby
22
+
23
+ DEPENDENCIES
24
+ rake
25
+ rays!
26
+ rspec
@@ -0,0 +1,27 @@
1
+ Ruby As You Talk
2
+ ================
3
+
4
+ Rayt allows you to easily write Ruby that sounds as you talk. As a picture is worth thousand words, here is an example :
5
+
6
+ require "rayt"
7
+ require "some_library"
8
+
9
+ Rayt.define.add_access_to(:resource).for_the_user(:user) do |args|
10
+ args.user.add_access(args.resource)
11
+ end
12
+
13
+ res = Resource.first
14
+ tom = User.find_by_name("Tom")
15
+ john = User.find_by_name("John")
16
+
17
+ Rayt.add_access_to(res).for_the_user(tom)
18
+ Rayt.add_access_to(res).for_the_user(john)
19
+
20
+ Running tests
21
+ -------------
22
+
23
+ To run the specs, just user the followings :
24
+
25
+ gem install bundler
26
+ bundle install
27
+ rake spec
@@ -0,0 +1,5 @@
1
+ require "rspec/core/rake_task"
2
+
3
+ $:.unshift File.expand_path('lib', __FILE__)
4
+
5
+ RSpec::Core::RakeTask.new {}
@@ -0,0 +1,18 @@
1
+ require "rayt"
2
+
3
+ class Animal
4
+ def initialize(name)
5
+ @name = name
6
+ end
7
+
8
+ def paint(colour)
9
+ puts "The #{@name} is now #{colour}."
10
+ end
11
+ end
12
+
13
+ Rayt.define.the(:animal).is(:colour) do |args|
14
+ args.animal.paint(args.colour)
15
+ end
16
+
17
+ cat = Animal.new "cat"
18
+ Rayt.the(cat).is("blue") # will show "The cat is now blue."
@@ -0,0 +1,10 @@
1
+ require "rayt/constants"
2
+ require "rayt/chained_methods_definition"
3
+
4
+ module Rayt
5
+ class << self
6
+ def define
7
+ Rayt::ChainedMethodsDefinition.new
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ module Rayt
2
+ class ChainedMethodsArguments
3
+
4
+ end
5
+ end
@@ -0,0 +1,42 @@
1
+ require "rayt/chained_methods_arguments"
2
+
3
+ module Rayt
4
+ class ChainedMethodsDefinition
5
+ attr_reader :chained_methods_arguments
6
+
7
+ def initialize(parent = nil)
8
+ @parent = parent || Rayt
9
+
10
+ @chained_methods_arguments = parent ?
11
+ parent.chained_methods_arguments :
12
+ Rayt::ChainedMethodsArguments.new
13
+ end
14
+
15
+ ##
16
+ # All the magic is here.
17
+
18
+ def method_missing(method_name, *arg_names, &block)
19
+ (class << @chained_methods_arguments; self; end).instance_eval do
20
+ arg_names.each do |arg_name|
21
+ attr_accessor arg_name
22
+ end
23
+ end
24
+
25
+ (class << @parent; self; end).instance_exec(@chained_methods_arguments, self) do |args, definition|
26
+ define_method method_name do |*passed_arguments|
27
+ passed_arguments.each_with_index do |pa, i|
28
+ args.instance_variable_set(("@" + arg_names[i].to_s), pa)
29
+ end
30
+
31
+ if block
32
+ block.call args
33
+ else
34
+ definition
35
+ end
36
+ end
37
+ end
38
+
39
+ Rayt::ChainedMethodsDefinition.new self
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,3 @@
1
+ module Rayt
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,21 @@
1
+ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
2
+ require "rayt/constants"
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "rayt"
6
+ s.version = Rayt::VERSION
7
+ s.authors = ["Thomas Feron"]
8
+ s.description = "Ruby As You Talk"
9
+ s.summary = "rayt-#{s.version}"
10
+ s.email = "tho.feron@gmail.com"
11
+ s.homepage = "http://www.lf-creation.com"
12
+
13
+ s.platform = Gem::Platform::RUBY
14
+
15
+ s.add_development_dependency "rspec"
16
+ s.add_development_dependency "rake"
17
+
18
+ s.files = `git ls-files`.split("\n").reject { |path| path =~ /\.gitignore$/ }
19
+ s.test_files = `git ls-files -- {spec,features}/*`.split("\n")
20
+ s.require_path = "lib"
21
+ end
@@ -0,0 +1,9 @@
1
+ require "rayt/chained_methods_definition"
2
+
3
+ describe Rayt::ChainedMethodsDefinition do
4
+ describe "#method_missing" do
5
+ it "should return a new instance of Rayt::ChainedMethodsDefinition" do
6
+ subject.anything.should be_a(Rayt::ChainedMethodsDefinition)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,34 @@
1
+ require "rayt"
2
+
3
+ describe Rayt do
4
+ context "general use of chained methods" do
5
+ it "should works as in the example 'basics'" do
6
+ obj = Object.new
7
+ obj.should_receive(:callback).with(/The cat is blue/)
8
+ Rayt.define.the(:animal).is(:colour) do |args|
9
+ obj.callback "The #{args.animal} is #{args.colour}"
10
+ end
11
+ Rayt.the("cat").is("blue")
12
+ end
13
+ end
14
+
15
+ describe ".define" do
16
+ it "should return a Rayt::ChainedMethodsDefinition instance" do
17
+ Rayt.define.should be_a(Rayt::ChainedMethodsDefinition)
18
+ end
19
+
20
+ it "should add a method to the Rayt context if called on it" do
21
+ Rayt.define.a_method { }
22
+ expect {
23
+ Rayt.a_method
24
+ }.not_to raise_error
25
+ end
26
+
27
+ it "should define methods for arguments" do
28
+ Rayt.define.a_method(:first, :second) do |args|
29
+ args.first + args.second
30
+ end
31
+ Rayt.a_method(2, 3).should == 5
32
+ end
33
+ end
34
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rayt
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Thomas Feron
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &17201928880 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *17201928880
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &17201928460 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *17201928460
36
+ description: Ruby As You Talk
37
+ email: tho.feron@gmail.com
38
+ executables: []
39
+ extensions: []
40
+ extra_rdoc_files: []
41
+ files:
42
+ - Gemfile
43
+ - Gemfile.lock
44
+ - README.md
45
+ - Rakefile
46
+ - examples/basics.rb
47
+ - lib/rayt.rb
48
+ - lib/rayt/chained_methods_arguments.rb
49
+ - lib/rayt/chained_methods_definition.rb
50
+ - lib/rayt/constants.rb
51
+ - rays.gemspec
52
+ - spec/lib/rayt/chained_methods_definition_spec.rb
53
+ - spec/lib/rayt_spec.rb
54
+ homepage: http://www.lf-creation.com
55
+ licenses: []
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubyforge_project:
74
+ rubygems_version: 1.8.11
75
+ signing_key:
76
+ specification_version: 3
77
+ summary: rayt-0.0.1
78
+ test_files: []