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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e913502c1480108ff5c4507e962f0b1942cad854
4
- data.tar.gz: c0a7002bce433cd57b7dc5991d33bd4ad196bc64
3
+ metadata.gz: f752e5c5701d52dabb1d1b96f9237bc44afac7d0
4
+ data.tar.gz: 960ffe276844fed404fe548686bae1fcfd084816
5
5
  SHA512:
6
- metadata.gz: 18c66d5fc0cf2c61c66b5b19369d8c920cfc76814a04e970c40270f01f64a0da18fe837a87dedd1f5b241196f609d051285ce99b59b9b3d657f60d4463b89be6
7
- data.tar.gz: ed13cc3654fc013b894406abbe1af802c82cb20519b559f841224231ff322a6b7c1ea4bee2bd1de57a3801bbdb22823a117d5a435fcfa71e55c68d0731a8fd28
6
+ metadata.gz: ff063ee9dd1919d3b62c084e5dca97fcd6fe607679386ef91d91fa599fbff291599a5dfd54b21103e178cee5c54e0832a03204a5ddad153978e66e15f3803a0b
7
+ data.tar.gz: 668640df8cb10d3e65a646cd3b959b31e282c2eb48e622e2bb097b0773d8c5668b97499fa5eddce1a59bec86aa1820078ea4694c846ac6b1462a43791622e21a
data/lib/pour/gem.rb CHANGED
@@ -41,7 +41,7 @@ module Pour
41
41
  end
42
42
 
43
43
  module VERSION #:nodoc:
44
- MAJOR, MINOR, PATCH, PRE = [0, 0, 2, 0]
44
+ MAJOR, MINOR, PATCH, PRE = [0, 0, 3, 0]
45
45
  STRING = [MAJOR, MINOR, PATCH, PRE].compact.join('.')
46
46
  end
47
47
 
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.class.included_modules.include?(Pour::Pourable)
6
- raise Pour::Unpourable.new(pourable)
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
- poured = self.class_variable_get(:@@__poured__) || []
28
- mould.class_variable_set(:@@__poured__, poured)
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
@@ -5,6 +5,7 @@ module Pour
5
5
  require 'pour/gem'
6
6
 
7
7
  require 'pour/property'
8
+ require 'pour/propertied'
8
9
  require 'pour/pourable'
9
10
  require 'pour/mould'
10
11
  end
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.2.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