babby 0.1.0 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f01decd7ac10aa4cfeadfd021a58082b97f781b0
4
- data.tar.gz: 2e0a6f850504d9183d7f09939ff269b84fbbc212
3
+ metadata.gz: 91f515d089fc0ac6850ff65b794a7e375b8a7360
4
+ data.tar.gz: d54d01d2f2f0472995b393da26a38ff5b1e10a38
5
5
  SHA512:
6
- metadata.gz: 167ebd61c30bf7149ae445945809262946dfbe479ca08488e5b159f3d7b76fd28497a665637f2eb71c3bc0c956135a07e335b53ef8a63573fb22a324a4e3f163
7
- data.tar.gz: 0b30c45c44b11a69451d31f44c464cfe08a45123345de3e82ed68dff55108665c7174a5ec885442d8f4bc06baa549fd0001161bd8aec50a2885ca42eb4207e39
6
+ metadata.gz: 2ec923d1d2459f5f03bc63c9f0969dd0ac0a0439eb06126d62a4fe44e41636346350eb2caddee8c22cac7c3d2c8161e56e27627e6f7de33e545a9804e2b833fe
7
+ data.tar.gz: f344bf381eeec7b2ee23ec4eaef68f74a1b4162cbe9f10a6a06602fcc9b7ae9f539701f90ee09b37ea8732e8e0d956681d4fa9e9b0f48ba74ff19b6986ad94bc
data/README.md CHANGED
@@ -24,16 +24,62 @@ i.thingy # => "widget"
24
24
  i.doodad # => ["lol", "rofl"]
25
25
  ```
26
26
 
27
+ You can contextualize domain objects as follows:
28
+
29
+ ```
30
+ class Base
31
+ include Babby::MetaDSL
32
+
33
+ dsl_method :contextualize, type: :proc
34
+
35
+ attr_accessor :entity
36
+
37
+ def initialize(instance)
38
+ @entity = instance
39
+ end
40
+
41
+ def generate
42
+ puts "path: #{contextualize[:path]} content: #{contextualize[:content]}"
43
+ end
44
+ end
45
+
46
+ class PooGenerator < Base
47
+ contextualize Proc.new { |instance| { path: instance.path, content: instance.content } }
48
+ end
49
+
50
+ class Thing
51
+ attr_accessor :path, :content
52
+
53
+ def initialize(path, content)
54
+ @path = path
55
+ @content = content
56
+ end
57
+ end
58
+
59
+ e = Thing.new('lol what', "poopsticks")
60
+ i = PooGenerator.new(e)
61
+
62
+ puts i.generate
63
+ ```
64
+
27
65
  ### But inheritance is yucky
28
- Yes, but not for is-a relationships.
66
+ Yes, but not for is-a relationships. Besides, dogmatism is yucky too. :3
67
+
29
68
 
30
69
  ## Development
31
70
 
32
71
  ### TODOs
33
- * add specs
72
+ * add specs!!!
73
+ * Allow parameterization of derived class entity - see babby.rb:21
34
74
  * add inflection/pluralization for arrays, with manual getter specification as a backup.
75
+ * Add ability to validate type of argument to dsl method
76
+ * Add ability to validate presence of hash keys on hash arguments
35
77
 
36
78
  ## License
37
79
 
38
80
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
39
81
 
82
+ ## Changelog
83
+
84
+ 0.2.0 - Fixed glaring bug in 0.1.0 (static map missing from module)
85
+ - Add proc
Binary file
@@ -1,4 +1,8 @@
1
- require "babby/version"
1
+ #require "babby/version"
2
+
3
+ STATE_TYPE_MAP = {
4
+ array: Array
5
+ }
2
6
 
3
7
  module Babby
4
8
  module MetaDSL
@@ -14,6 +18,10 @@ module Babby
14
18
 
15
19
  module ClassMethods
16
20
 
21
+ def apply_to entity_method_name
22
+ # Set the name of the method to retrieve the entity bound to the instance, as a symbol
23
+ end
24
+
17
25
  def dsl_method name, type: nil
18
26
  state_type = type ? STATE_TYPE_MAP[type] : nil
19
27
 
@@ -28,20 +36,29 @@ module Babby
28
36
  else
29
37
  define_singleton_method name do |value| # define 'setter' for derived class - i.e. DSL 'setup' method a la attr_accessor
30
38
  if not self.instance_variable_get "@#{name}"
31
- self.instance_variable_set "@#{name}", type ? state_type.new : nil
39
+ self.instance_variable_set "@#{name}", state_type ? state_type.new : nil
32
40
  end
33
41
 
34
42
  self.instance_variable_set "@#{name}", value # Set the underlying class instance variable to the desired value
35
43
  end
36
44
  end
45
+
37
46
  define_singleton_method "get_#{name}".to_sym do
38
47
  self.instance_variable_get "@#{name}"
39
48
  end
40
49
 
41
- define_method name do
42
- self.class.send "get_#{name}".to_sym
50
+ if type == :proc
51
+ define_method name do
52
+ proc = self.class.send "get_#{name}".to_sym
53
+ proc.call(entity)
54
+ end
55
+ else
56
+ define_method name do
57
+ self.class.send "get_#{name}".to_sym
58
+ end
43
59
  end
44
60
  end
45
61
  end
46
62
  end
47
- end
63
+ end
64
+
@@ -1,3 +1,3 @@
1
1
  module Babby
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: babby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chaz Straney
@@ -52,6 +52,7 @@ files:
52
52
  - LICENSE.txt
53
53
  - README.md
54
54
  - Rakefile
55
+ - babby-0.1.0.gem
55
56
  - babby.gemspec
56
57
  - bin/console
57
58
  - bin/setup