lay 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +19 -0
- data/Manifest +5 -0
- data/Rakefile +38 -0
- data/lib/lay.rb +35 -0
- data/test/test_lay.rb +33 -0
- metadata +51 -0
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2007 Christian Carter & Craig Muth
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/Manifest
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
DIR = File.dirname(__FILE__)
|
5
|
+
|
6
|
+
begin
|
7
|
+
require 'rake/clean'
|
8
|
+
gem 'echoe', '>= 1.2'
|
9
|
+
require 'echoe'
|
10
|
+
require 'fileutils'
|
11
|
+
include FileUtils
|
12
|
+
|
13
|
+
CLEAN.include ['*.gem']
|
14
|
+
|
15
|
+
echoe = Echoe.new("lay", "0.1") do |p|
|
16
|
+
p.author = ["Christian Carter", "Craig Muth"]
|
17
|
+
p.rubyforge_name = "metacampsite"
|
18
|
+
p.name = "lay"
|
19
|
+
p.description = "An object initialization helper with nested hiearchies in mind"
|
20
|
+
p.email = "cdcarter at gmail dot com"
|
21
|
+
p.summary = p.description
|
22
|
+
p.url = "http://metacampsite.com"
|
23
|
+
p.need_tar = false
|
24
|
+
p.need_tar_gz = true
|
25
|
+
p.test_globs = ["*_test.rb"]
|
26
|
+
p.clean_globs = CLEAN
|
27
|
+
end
|
28
|
+
|
29
|
+
rescue LoadError => boom
|
30
|
+
puts "You are missing a dependency required for meta-operations on this gem."
|
31
|
+
puts "#{boom.to_s.capitalize}."
|
32
|
+
|
33
|
+
desc 'Run tests.'
|
34
|
+
desc 'Run the test suite.'
|
35
|
+
task :test do
|
36
|
+
system "ruby -Ibin:lib:test test/test_gcal.rb" # or whatever
|
37
|
+
end
|
38
|
+
end
|
data/lib/lay.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
#
|
2
|
+
# Summary:
|
3
|
+
# For creating nested object hierarchies.
|
4
|
+
#
|
5
|
+
# Usage:
|
6
|
+
# Person.lay(["Aye"], :name => "Bob", :_salary => 10)
|
7
|
+
# The previous line does the following:
|
8
|
+
# - instantiates Person
|
9
|
+
# - passes "Aye" to its constructor
|
10
|
+
# - sets "name" attr to "Bob"
|
11
|
+
# - sets "salary" member variable to 10
|
12
|
+
# - returns the new instance
|
13
|
+
#
|
14
|
+
class Class
|
15
|
+
def lay(args = [], attrs = {})
|
16
|
+
# If only first arg passed, it's the attrs
|
17
|
+
args, attrs = nil, args if attrs == {}
|
18
|
+
|
19
|
+
# Use args list as constructor args if passed
|
20
|
+
o = self.new *args if args
|
21
|
+
o = self.new unless args
|
22
|
+
|
23
|
+
# Set attrs as member variables
|
24
|
+
attrs.each do |k,v|
|
25
|
+
# If it begins with :_, use instance_eval
|
26
|
+
if k.to_s =~ /^_/
|
27
|
+
o.instance_variable_set(k.to_s.sub("_", "@"), v)
|
28
|
+
# Else, set parameter
|
29
|
+
else
|
30
|
+
o.send("#{k}=", v)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
o
|
34
|
+
end
|
35
|
+
end
|
data/test/test_lay.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'lay'
|
2
|
+
|
3
|
+
class Person
|
4
|
+
attr_accessor :name, :projects
|
5
|
+
def initialize a
|
6
|
+
@a = a
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class Project
|
11
|
+
attr_accessor :title, :age
|
12
|
+
end
|
13
|
+
|
14
|
+
require 'test/unit'
|
15
|
+
class TC_Lay < Test::Unit::TestCase
|
16
|
+
|
17
|
+
def test_one_object
|
18
|
+
assert_not_nil Project.lay(:title => "p1", :age => 5)
|
19
|
+
end
|
20
|
+
def test_without_attr
|
21
|
+
assert_not_nil Project.lay(:_foo => 5)
|
22
|
+
end
|
23
|
+
def test_with_constructor
|
24
|
+
assert_not_nil Person.lay(["Aye"], :name => "Bob")
|
25
|
+
end
|
26
|
+
def test_pass_nothing
|
27
|
+
assert_not_nil Project.lay()
|
28
|
+
end
|
29
|
+
def test_two_objects
|
30
|
+
assert_not_nil Person.lay(["Aye"], :name => "Bob", :projects =>
|
31
|
+
[Project.lay(:title => "p1", :age => 5), Project.lay(:title => "p2", :age => 2)])
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.2
|
3
|
+
specification_version: 1
|
4
|
+
name: lay
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: "0.1"
|
7
|
+
date: 2007-06-24 00:00:00 -05:00
|
8
|
+
summary: An object initialization helper with nested hiearchies in mind
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: cdcarter at gmail dot com
|
12
|
+
homepage: http://metacampsite.com
|
13
|
+
rubyforge_project: metacampsite
|
14
|
+
description: An object initialization helper with nested hiearchies in mind
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- Christian Carter
|
31
|
+
- Craig Muth
|
32
|
+
files:
|
33
|
+
- ./lib/lay.rb
|
34
|
+
- ./LICENSE
|
35
|
+
- ./Rakefile
|
36
|
+
- ./test/test_lay.rb
|
37
|
+
- ./Manifest
|
38
|
+
test_files: []
|
39
|
+
|
40
|
+
rdoc_options: []
|
41
|
+
|
42
|
+
extra_rdoc_files: []
|
43
|
+
|
44
|
+
executables: []
|
45
|
+
|
46
|
+
extensions: []
|
47
|
+
|
48
|
+
requirements: []
|
49
|
+
|
50
|
+
dependencies: []
|
51
|
+
|