reindeer 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 69a46e362ec033d7e2681ea545e96c9d6d3f9a60
4
+ data.tar.gz: cdf916813387c7cbdba22161b627260ef3d7c0c6
5
+ SHA512:
6
+ metadata.gz: 944cb90ba2b6d8bb74b089a2c79dfd942463b2a1515da32eea5ec8ecf12010a074204113d836855eb42d0128caaae639bf9bc4c82980e94d9a4615ee72cda384
7
+ data.tar.gz: 258f371f131f9efddbb49c92688566dba79af9718f6d0341812dc3c76f0d83e7cbb3c9f255b5912f9a4bb99e6d4c8dd299412bddaeb1871181fa9ddc4a906758
@@ -1,3 +1,7 @@
1
+ ## 0.0.2
2
+
3
+ * Support attributes in inherited classes.
4
+
1
5
  ## 0.0.1
2
6
 
3
7
  * Initial release.
data/Gemfile CHANGED
@@ -1,7 +1,5 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- ruby '1.9.3'
4
-
5
3
  group :test do
6
4
  gem 'rake', '~> 10'
7
5
  gem 'rspec', '~> 2'
data/README.md CHANGED
@@ -9,18 +9,20 @@ borrowed from [Moose](http://p3rl.org/Moose).
9
9
 
10
10
  # Usage
11
11
 
12
- require 'reindeer'
13
- class Point < Reindeer
14
- has :x, is: :rw, is_a: Integer
15
- has :y, is: :rw, is_a: Integer
16
- end
17
- class Point3D < Point
18
- has :z, is: :rw, is_a: Integer
19
- end
12
+ ```ruby
13
+ require 'reindeer'
14
+ class Point < Reindeer
15
+ has :x, is: :rw, is_a: Integer
16
+ has :y, is: :rw, is_a: Integer
17
+ end
18
+ class Point3D < Point
19
+ has :z, is: :rw, is_a: Integer
20
+ end
21
+ ```
20
22
 
21
23
  # Features
22
24
 
23
- These features are supported to a greater or less extent:
25
+ These features are supported to a lesser or greater extent:
24
26
 
25
27
  ## Construction
26
28
 
@@ -111,21 +113,23 @@ To compose a role in a Reindeer class two expressions are required,
111
113
  latter brings in the role attributes and asserts the existence of any
112
114
  required methods e.g
113
115
 
114
- module Breakable
115
- include Reindeer::Role
116
- has :is_broken, default: -> { false }
117
- requires :fix!
118
- end
119
-
120
- class Egg < Reindeer
121
- with Breakable
122
-
123
- def fix!
124
- throw :no_dice if is_broken
125
- end
126
-
127
- meta.compose!
128
- end
116
+ ```ruby
117
+ module Breakable
118
+ include Reindeer::Role
119
+ has :is_broken, default: -> { false }
120
+ requires :fix!
121
+ end
122
+
123
+ class Egg < Reindeer
124
+ with Breakable
125
+
126
+ def fix!
127
+ throw :no_dice if is_broken
128
+ end
129
+
130
+ meta.compose!
131
+ end
132
+ ```
129
133
 
130
134
  The `.does?` method can be used to inspect which roles have been
131
135
  consumed e.g `Egg.does?(Breakable) == true`.
@@ -140,29 +144,33 @@ Given that Ruby has a well established class system one need only
140
144
  assert an attribute is of a given (existing) class a Reindeer will go
141
145
  to the trouble of asserting that when the attribute value is set e.g
142
146
 
143
- class AccountSqlTable < Reindeer
144
- has :id, is_a: Fixnum
145
- has :owner, is_a: String
146
- has :amount, is_a: Float
147
- # ...
148
- end
147
+ ```ruby
148
+ class AccountSqlTable < Reindeer
149
+ has :id, is_a: Fixnum
150
+ has :owner, is_a: String
151
+ has :amount, is_a: Float
152
+ # ...
153
+ end
154
+ ```
149
155
 
150
156
  However if you need a specific type of class (e.g strings of a certain
151
157
  length) then a custom type constraint is needed. These can be defined
152
158
  simply by composing the `Reindeer::Role::TypeConstraint` and
153
159
  implementing a `verify` method e.g
154
160
 
155
- class Varchar255 < Reindeer
156
- with Reindeer::Role::TypeConstraint
157
- def verify(v)
158
- v.length <= 255
159
- end
160
- meta.compose!
161
- end
162
-
163
- class AccountSqlTable # continued from above
164
- has :summary, type_of: Varchar255
165
- end
161
+ ```ruby
162
+ class Varchar255 < Reindeer
163
+ with Reindeer::Role::TypeConstraint
164
+ def verify(v)
165
+ v.length <= 255
166
+ end
167
+ meta.compose!
168
+ end
169
+
170
+ class AccountSqlTable # continued from above
171
+ has :summary, type_of: Varchar255
172
+ end
173
+ ```
166
174
 
167
175
  *NB* The distinction between class and type constraints seems apt at this
168
176
  point but is by no means set in stone. Hopefully the passage of time
@@ -88,12 +88,12 @@ class Reindeer
88
88
  end
89
89
 
90
90
  def has_attribute?(name)
91
- get_attributes.any? {|a| a.name == name }
91
+ get_all_attributes.any? {|a| a.name == name }
92
92
  end
93
93
 
94
94
  def get_attribute(sym)
95
95
  sym = sym.sub(/^@/, '').to_sym if sym.is_a?(String)
96
- get_attributes.select{|a| a.name == sym}.first
96
+ get_all_attributes.select{|a| a.name == sym}.first
97
97
  end
98
98
  end
99
99
  end
@@ -1,3 +1,3 @@
1
1
  module Reindeer
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
@@ -219,4 +219,17 @@ describe 'Reindeer attributes' do
219
219
  end
220
220
  }.to raise_error(Reindeer::Meta::Attribute::AttributeError)
221
221
  end
222
+
223
+ it 'should find attributes up the inheritance chain' do
224
+ class NineteenthOne < Reindeer
225
+ has :foo, is: :rw
226
+ class Specialised < NineteenthOne
227
+ has :bar
228
+ end
229
+ end
230
+
231
+ obj = NineteenthOne::Specialised.new(bar: 'abc')
232
+ obj.foo = 123
233
+ expect(obj.foo).to eq(123)
234
+ end
222
235
  end
File without changes
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reindeer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
5
- prerelease:
4
+ version: 0.0.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Dan Brook
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-03-31 00:00:00.000000000 Z
11
+ date: 2015-04-14 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rake
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rspec
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
@@ -49,7 +44,6 @@ executables: []
49
44
  extensions: []
50
45
  extra_rdoc_files: []
51
46
  files:
52
- - .rspec
53
47
  - CHANGELOG.md
54
48
  - Gemfile
55
49
  - Gemfile.lock
@@ -68,29 +62,29 @@ files:
68
62
  - spec/reindeer/roles_spec.rb
69
63
  - spec/reindeer/types_spec.rb
70
64
  - spec/reindeer_spec.rb
65
+ - spec/spec_helper.rb
71
66
  homepage: http://github.com/broquaint/reindeer
72
67
  licenses: []
68
+ metadata: {}
73
69
  post_install_message:
74
70
  rdoc_options: []
75
71
  require_paths:
76
72
  - lib
77
73
  required_ruby_version: !ruby/object:Gem::Requirement
78
- none: false
79
74
  requirements:
80
- - - ! '>='
75
+ - - '>='
81
76
  - !ruby/object:Gem::Version
82
77
  version: '1.9'
83
78
  required_rubygems_version: !ruby/object:Gem::Requirement
84
- none: false
85
79
  requirements:
86
- - - ! '>='
80
+ - - '>='
87
81
  - !ruby/object:Gem::Version
88
82
  version: '0'
89
83
  requirements: []
90
84
  rubyforge_project:
91
- rubygems_version: 1.8.24
85
+ rubygems_version: 2.0.14
92
86
  signing_key:
93
- specification_version: 3
87
+ specification_version: 4
94
88
  summary: Moose sugar in Ruby
95
89
  test_files:
96
90
  - spec/reindeer/attributes_spec.rb
@@ -98,3 +92,4 @@ test_files:
98
92
  - spec/reindeer/roles_spec.rb
99
93
  - spec/reindeer/types_spec.rb
100
94
  - spec/reindeer_spec.rb
95
+ - spec/spec_helper.rb