moosex 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +27 -0
- data/LICENSE +20 -0
- data/README.md +50 -0
- data/lib/moosex.rb +107 -0
- data/lib/moosex/version.rb +3 -0
- data/moosex.gemspec +24 -0
- data/spec/moosex_spec.rb +65 -0
- metadata +99 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 11498c2543b354be73e14d5f4a7acf0b743cc8ca
|
4
|
+
data.tar.gz: 14d5a801de841fb2edc262b1341ab203db2ee5e2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 06879aad4c8e8bc01947fae38781909c5a8042b7e36880290dbed4c9ff4972d7e7f74538690f13da062b987f235fa898334fd62dee9e4332229c3260c82d0534
|
7
|
+
data.tar.gz: 7afaf26b30e7af09da4f43acbd6d2b1ba2887db37771cbd6325fadb44c6823f2e0c197ee53fc08720e36cdb731a48d9059beeb60dae74ac1c19be40cb3a04fc6
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
moosex (0.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.2.5)
|
10
|
+
rake (10.1.1)
|
11
|
+
rspec (2.14.1)
|
12
|
+
rspec-core (~> 2.14.0)
|
13
|
+
rspec-expectations (~> 2.14.0)
|
14
|
+
rspec-mocks (~> 2.14.0)
|
15
|
+
rspec-core (2.14.7)
|
16
|
+
rspec-expectations (2.14.4)
|
17
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
18
|
+
rspec-mocks (2.14.4)
|
19
|
+
|
20
|
+
PLATFORMS
|
21
|
+
ruby
|
22
|
+
|
23
|
+
DEPENDENCIES
|
24
|
+
bundler (~> 1.5)
|
25
|
+
moosex!
|
26
|
+
rake
|
27
|
+
rspec
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Tiago Peczenyj
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# Moosex
|
2
|
+
|
3
|
+
A postmodern object system for Ruby
|
4
|
+
|
5
|
+
class Point
|
6
|
+
include MooseX
|
7
|
+
|
8
|
+
has :x , {
|
9
|
+
:is => :rw,
|
10
|
+
:isa => Integer,
|
11
|
+
:default => 0,
|
12
|
+
}
|
13
|
+
|
14
|
+
has :y , {
|
15
|
+
:is => :rw,
|
16
|
+
:isa => Integer,
|
17
|
+
:default => lambda { 0 },
|
18
|
+
}
|
19
|
+
|
20
|
+
def clear
|
21
|
+
self.x= 0
|
22
|
+
self.y= 0
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
## Installation
|
27
|
+
|
28
|
+
Add this line to your application's Gemfile:
|
29
|
+
|
30
|
+
gem 'moosex'
|
31
|
+
|
32
|
+
And then execute:
|
33
|
+
|
34
|
+
$ bundle
|
35
|
+
|
36
|
+
Or install it yourself as:
|
37
|
+
|
38
|
+
$ gem install moosex
|
39
|
+
|
40
|
+
## Usage
|
41
|
+
|
42
|
+
MooseX is an extension of Ruby object system. The main goal of MooseX is to make Ruby Object Oriented programming easier, more consistent, and less tedious. With MooseX you can think more about what you want to do and less about the mechanics of OOP. It is a port of Moose/Moo from Perl to Ruby world.
|
43
|
+
|
44
|
+
## Contributing
|
45
|
+
|
46
|
+
1. Fork it ( http://github.com/peczenyj/MooseX/fork )
|
47
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
48
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
49
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
50
|
+
5. Create new Pull Request
|
data/lib/moosex.rb
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
# Module MooseX
|
2
|
+
# A postmodern object system for Ruby
|
3
|
+
#
|
4
|
+
# MooseX is an extension of Ruby object system. The main goal of MooseX is to make Ruby Object Oriented programming easier, more consistent, and less tedious. With MooseX you can think more about what you want to do and less about the mechanics of OOP. It is a port of Moose/Moo from Perl to Ruby world.
|
5
|
+
|
6
|
+
require "moosex/version"
|
7
|
+
|
8
|
+
module MooseX
|
9
|
+
|
10
|
+
def self.included(o)
|
11
|
+
|
12
|
+
o.extend(MooseX::Core)
|
13
|
+
|
14
|
+
o.class_exec {
|
15
|
+
@@meta = MooseX::Meta.new()
|
16
|
+
}
|
17
|
+
o.define_singleton_method :__meta do
|
18
|
+
class_variable_get "@@meta".to_sym
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize(args={})
|
22
|
+
|
23
|
+
self.class.__meta().init(self, args)
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
module Core
|
30
|
+
|
31
|
+
def has(attr_name, attr_options)
|
32
|
+
attr = MooseX::Attribute.new(attr_name, attr_options)
|
33
|
+
g = attr.generate_getter
|
34
|
+
|
35
|
+
define_method attr_name, &g
|
36
|
+
|
37
|
+
s = attr.generate_setter
|
38
|
+
|
39
|
+
define_method "#{attr_name}=", &s
|
40
|
+
|
41
|
+
__meta.add(attr)
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
class Attribute
|
47
|
+
|
48
|
+
def initialize(a, o)
|
49
|
+
@attr_symbol = a
|
50
|
+
@options = o
|
51
|
+
end
|
52
|
+
|
53
|
+
def init(object, args)
|
54
|
+
setter = @attr_symbol.to_s.concat("=").to_sym
|
55
|
+
value = nil
|
56
|
+
|
57
|
+
if args.has_key? @attr_symbol
|
58
|
+
value = args[ @attr_symbol ]
|
59
|
+
elsif @options[:required]
|
60
|
+
raise "ops, attr #{@attr_symbol} is required"
|
61
|
+
else
|
62
|
+
value = (@options[:default].is_a? Proc) ? @options[:default].call : @options[:default]
|
63
|
+
end
|
64
|
+
|
65
|
+
object.send( setter, value )
|
66
|
+
end
|
67
|
+
|
68
|
+
def generate_getter
|
69
|
+
inst_variable_name = "@#{@attr_symbol}".to_sym
|
70
|
+
Proc.new { instance_variable_get inst_variable_name }
|
71
|
+
end
|
72
|
+
|
73
|
+
def generate_setter
|
74
|
+
inst_variable_name = "@#{@attr_symbol}".to_sym
|
75
|
+
type_check = generate_type_check
|
76
|
+
Proc.new do |value|
|
77
|
+
type_check.call(value)
|
78
|
+
instance_variable_set inst_variable_name, value
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def generate_type_check
|
83
|
+
if @options.has_key? :isa
|
84
|
+
klass = @options[:isa]
|
85
|
+
return lambda do |new_value|
|
86
|
+
raise "isa check for \"#{@attr_symbol}\" failed: lol is not #{klass}!" unless new_value.is_a? klass
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
lambda { |new_value| }
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
class Meta
|
95
|
+
def initialize
|
96
|
+
@attrs = []
|
97
|
+
end
|
98
|
+
|
99
|
+
def add(attr)
|
100
|
+
@attrs << attr
|
101
|
+
end
|
102
|
+
|
103
|
+
def init(object, args)
|
104
|
+
@attrs.each{ |attr| attr.init(object, args) }
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
data/moosex.gemspec
ADDED
@@ -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 'moosex/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "moosex"
|
8
|
+
spec.version = Moosex::VERSION
|
9
|
+
spec.authors = ["Tiago Peczenyj"]
|
10
|
+
spec.email = ["tiago.peczenyj@gmail.com"]
|
11
|
+
spec.summary = %q{A postmodern object system for Ruby}
|
12
|
+
spec.description = %q{MooseX is an extension of Ruby object system. The main goal of MooseX is to make Ruby Object Oriented programming easier, more consistent, and less tedious. With MooseX you can think more about what you want to do and less about the mechanics of OOP. It is a port of Moose/Moo from Perl to Ruby world.}
|
13
|
+
spec.homepage = "http://github.com/peczenyj/MooseX"
|
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.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
end
|
data/spec/moosex_spec.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
#require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
require 'moosex'
|
3
|
+
|
4
|
+
class Point
|
5
|
+
include MooseX
|
6
|
+
|
7
|
+
has :x , {
|
8
|
+
:is => :rw,
|
9
|
+
:isa => Integer,
|
10
|
+
:default => 0,
|
11
|
+
}
|
12
|
+
|
13
|
+
has :y , {
|
14
|
+
:is => :rw,
|
15
|
+
:isa => Integer,
|
16
|
+
:default => lambda { 0 },
|
17
|
+
}
|
18
|
+
|
19
|
+
def clear
|
20
|
+
self.x= 0
|
21
|
+
self.y= 0
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "Point" do
|
26
|
+
describe "should has an intelligent constructor" do
|
27
|
+
it "without arguments, should initialize with default values" do
|
28
|
+
p = Point.new
|
29
|
+
p.x.should be_zero
|
30
|
+
p.y.should be_zero
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should initialize only y" do
|
34
|
+
p = Point.new( :x => 5 )
|
35
|
+
p.x.should == 5
|
36
|
+
p.y.should be_zero
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should initialize x and y" do
|
40
|
+
p = Point.new( :x => 5, :y => 4)
|
41
|
+
p.x.should == 5
|
42
|
+
p.y.should == 4
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "should create a getter and a setter" do
|
47
|
+
it "for x" do
|
48
|
+
p = Point.new
|
49
|
+
p.x= 5
|
50
|
+
p.x.should == 5
|
51
|
+
end
|
52
|
+
|
53
|
+
it "for x, with type check" do
|
54
|
+
p = Point.new
|
55
|
+
expect { p.x = "lol" }.to raise_error('isa check for "x" failed: lol is not Integer!')
|
56
|
+
end
|
57
|
+
|
58
|
+
it "clear should clean attributes" do
|
59
|
+
p = Point.new( :x => 5, :y => 4)
|
60
|
+
p.clear
|
61
|
+
p.x.should be_zero
|
62
|
+
p.y.should be_zero
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: moosex
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tiago Peczenyj
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-31 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.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
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
|
+
- !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: MooseX is an extension of Ruby object system. The main goal of MooseX
|
56
|
+
is to make Ruby Object Oriented programming easier, more consistent, and less tedious.
|
57
|
+
With MooseX you can think more about what you want to do and less about the mechanics
|
58
|
+
of OOP. It is a port of Moose/Moo from Perl to Ruby world.
|
59
|
+
email:
|
60
|
+
- tiago.peczenyj@gmail.com
|
61
|
+
executables: []
|
62
|
+
extensions: []
|
63
|
+
extra_rdoc_files: []
|
64
|
+
files:
|
65
|
+
- .gitignore
|
66
|
+
- Gemfile
|
67
|
+
- Gemfile.lock
|
68
|
+
- LICENSE
|
69
|
+
- README.md
|
70
|
+
- lib/moosex.rb
|
71
|
+
- lib/moosex/version.rb
|
72
|
+
- moosex.gemspec
|
73
|
+
- spec/moosex_spec.rb
|
74
|
+
homepage: http://github.com/peczenyj/MooseX
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
metadata: {}
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ! '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ! '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 2.2.1
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: A postmodern object system for Ruby
|
98
|
+
test_files:
|
99
|
+
- spec/moosex_spec.rb
|