pour 0.0.2.0 → 0.0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pour/gem.rb +1 -1
- data/lib/pour/mould.rb +17 -6
- data/lib/pour/pourable.rb +2 -43
- data/lib/pour/propertied.rb +57 -0
- data/lib/pour.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f752e5c5701d52dabb1d1b96f9237bc44afac7d0
|
4
|
+
data.tar.gz: 960ffe276844fed404fe548686bae1fcfd084816
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff063ee9dd1919d3b62c084e5dca97fcd6fe607679386ef91d91fa599fbff291599a5dfd54b21103e178cee5c54e0832a03204a5ddad153978e66e15f3803a0b
|
7
|
+
data.tar.gz: 668640df8cb10d3e65a646cd3b959b31e282c2eb48e622e2bb097b0773d8c5668b97499fa5eddce1a59bec86aa1820078ea4694c846ac6b1462a43791622e21a
|
data/lib/pour/gem.rb
CHANGED
data/lib/pour/mould.rb
CHANGED
@@ -2,14 +2,16 @@ module Pour
|
|
2
2
|
class Mould
|
3
3
|
module ClassMethods
|
4
4
|
def pour(pourable)
|
5
|
-
unless pourable.
|
6
|
-
|
5
|
+
unless pourable.included_modules.include?(Pour::Pourable)
|
6
|
+
# TODO(mtwilliams): Use a custom exceptin type, Pour::Unpourable.
|
7
|
+
raise ":("
|
7
8
|
end
|
8
9
|
|
9
10
|
poured = self.class_variable_get(:@@__poured__)
|
10
11
|
|
11
12
|
unless poured.include? pourable
|
12
|
-
self.class_variable_set(:@@__poured__, poured + pourable)
|
13
|
+
self.class_variable_set(:@@__poured__, poured + [pourable])
|
14
|
+
|
13
15
|
# This capture all the properties as well as any user-defined methods.
|
14
16
|
self.include(pourable)
|
15
17
|
end
|
@@ -20,12 +22,21 @@ module Pour
|
|
20
22
|
end
|
21
23
|
|
22
24
|
def self.inherited(mould)
|
25
|
+
mould.send :include, Pour::Propertied
|
26
|
+
|
23
27
|
mould.send :extend, ClassMethods
|
24
28
|
mould.send :include, InstanceMethods
|
25
|
-
|
26
29
|
# We can assume nothing has been "poured" into |mold|.
|
27
|
-
|
28
|
-
|
30
|
+
mould.class_variable_set(:@@__poured__, [])
|
31
|
+
|
32
|
+
mould.define_singleton_method :inherited do |descendent|
|
33
|
+
mould.send :include, Pour::Propertied
|
34
|
+
descendent.class_variable_set(:@@__properties__, mould.class_variable_get(:@@__properties__))
|
35
|
+
|
36
|
+
descendent.send :extend, ClassMethods
|
37
|
+
descendent.send :include, InstanceMethods
|
38
|
+
descendent.class_variable_set(:@@__poured__, mould.class_variable_get(:@@__poured__))
|
39
|
+
end
|
29
40
|
end
|
30
41
|
end
|
31
42
|
end
|
data/lib/pour/pourable.rb
CHANGED
@@ -1,57 +1,16 @@
|
|
1
1
|
module Pour
|
2
2
|
module Pourable
|
3
3
|
module ClassMethods
|
4
|
-
def property(name, typespec)
|
5
|
-
if self.__properties__.map(&:name).include?(name)
|
6
|
-
raise "Already have a property called '#{name}'!"
|
7
|
-
end
|
8
|
-
|
9
|
-
property = Pour::Property.new(name: name, typespec: typespec)
|
10
|
-
self.__properties__ = self.__properties__ + [property]
|
11
|
-
|
12
|
-
decorated = "@#{name}".to_sym
|
13
|
-
reader = name.to_sym
|
14
|
-
writer = "#{name}=".to_sym
|
15
|
-
|
16
|
-
self.class_eval do
|
17
|
-
define_method reader do
|
18
|
-
self.insance_variable_get(decorated)
|
19
|
-
end
|
20
|
-
|
21
|
-
define_method writer do |new_value|
|
22
|
-
if property.typespec.valid?(new_value)
|
23
|
-
self.insance_variable_set(decorated, new_value)
|
24
|
-
else
|
25
|
-
# TODO(mtwilliams): recursively map to determine where and why the
|
26
|
-
# |new_value| doesn't match the typespec.
|
27
|
-
raise ":("
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def __properties__
|
34
|
-
if self.class.superclass.included_modules.include? Pour::Pourable
|
35
|
-
properties = self.class.superclass.class_variable_get(:@@__properties__)
|
36
|
-
self.class_variable_set(:@@__properties__, properties)
|
37
|
-
end
|
38
|
-
|
39
|
-
self.class_variable_get(:@@__properties__)
|
40
|
-
end
|
41
|
-
|
42
|
-
def __properties__=(properties)
|
43
|
-
self.class_variable_set(:@@__properties__, properties)
|
44
|
-
end
|
45
4
|
end
|
46
5
|
|
47
6
|
module InstanceMethods
|
48
7
|
end
|
49
8
|
|
50
9
|
def self.included(pourable)
|
10
|
+
pourable.send :include, Pour::Propertied
|
11
|
+
|
51
12
|
pourable.send :extend, ClassMethods
|
52
13
|
pourable.send :include, InstanceMethods
|
53
|
-
|
54
|
-
pourable.class_variable_set :@@__properties__, []
|
55
14
|
end
|
56
15
|
end
|
57
16
|
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Pour
|
2
|
+
module Propertied
|
3
|
+
module ClassMethods
|
4
|
+
def property(name, typespec)
|
5
|
+
if self.__properties__.map(&:name).include?(name)
|
6
|
+
raise "Already have a property called '#{name}'!"
|
7
|
+
end
|
8
|
+
|
9
|
+
property = Pour::Property.new(name: name, typespec: typespec)
|
10
|
+
self.__properties__ = self.__properties__ + [property]
|
11
|
+
|
12
|
+
decorated = "@#{name}".to_sym
|
13
|
+
reader = name.to_sym
|
14
|
+
writer = "#{name}=".to_sym
|
15
|
+
|
16
|
+
self.class_eval do
|
17
|
+
define_method reader do
|
18
|
+
self.insance_variable_get(decorated)
|
19
|
+
end
|
20
|
+
|
21
|
+
define_method writer do |new_value|
|
22
|
+
if property.typespec.valid?(new_value)
|
23
|
+
self.insance_variable_set(decorated, new_value)
|
24
|
+
else
|
25
|
+
# TODO(mtwilliams): recursively map to determine where and why the
|
26
|
+
# |new_value| doesn't match the typespec.
|
27
|
+
raise ":("
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def __properties__
|
34
|
+
if self.class.superclass.included_modules.include? Pour::Pourable
|
35
|
+
properties = self.class.superclass.class_variable_get(:@@__properties__)
|
36
|
+
self.class_variable_set(:@@__properties__, properties)
|
37
|
+
end
|
38
|
+
|
39
|
+
self.class_variable_get(:@@__properties__)
|
40
|
+
end
|
41
|
+
|
42
|
+
def __properties__=(properties)
|
43
|
+
self.class_variable_set(:@@__properties__, properties)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
module InstanceMethods
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.included(pourable)
|
51
|
+
pourable.send :extend, ClassMethods
|
52
|
+
pourable.send :include, InstanceMethods
|
53
|
+
|
54
|
+
pourable.class_variable_set :@@__properties__, []
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/lib/pour.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pour
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Williams
|
@@ -83,6 +83,7 @@ files:
|
|
83
83
|
- lib/pour/gem.rb
|
84
84
|
- lib/pour/mould.rb
|
85
85
|
- lib/pour/pourable.rb
|
86
|
+
- lib/pour/propertied.rb
|
86
87
|
- lib/pour/property.rb
|
87
88
|
- pour.gemspec
|
88
89
|
homepage: http://mtwilliams.github.io/pour
|