entasis 0.3.0.rc1.1 → 0.3.0
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.
- data/Gemfile +1 -3
- data/README.md +1 -0
- data/lib/entasis/model.rb +23 -6
- data/lib/entasis/version.rb +1 -1
- data/spec/entasis_spec.rb +2 -3
- data/spec/spec_helper.rb +1 -0
- metadata +6 -8
- data/spec/person.rb +0 -11
data/Gemfile
CHANGED
data/README.md
CHANGED
data/lib/entasis/model.rb
CHANGED
@@ -9,7 +9,10 @@ module Entasis
|
|
9
9
|
end
|
10
10
|
|
11
11
|
module ClassMethods
|
12
|
-
|
12
|
+
##
|
13
|
+
#
|
14
|
+
# Takes a list of attribute names
|
15
|
+
#
|
13
16
|
def attributes(*attrs)
|
14
17
|
class_variable_set :@@attribute_names, attrs.map(&:to_s)
|
15
18
|
|
@@ -17,30 +20,44 @@ module Entasis
|
|
17
20
|
end
|
18
21
|
end
|
19
22
|
|
23
|
+
##
|
24
|
+
#
|
20
25
|
# Takes a hash and assigns keys and values to it's attributes members
|
26
|
+
#
|
21
27
|
def initialize(hash)
|
22
28
|
self.attributes = hash
|
23
29
|
end
|
24
30
|
|
31
|
+
##
|
32
|
+
#
|
33
|
+
# Returns a list of attribute names
|
34
|
+
#
|
25
35
|
def attribute_names
|
26
36
|
self.class.class_variable_get :@@attribute_names
|
27
37
|
end
|
28
38
|
|
39
|
+
##
|
40
|
+
#
|
41
|
+
# Takes a hash of attribute names and values and set each attribute.
|
42
|
+
#
|
43
|
+
# If passwed an unkown attribute it ill raise +class::UnknownAttributeError+
|
44
|
+
#
|
29
45
|
def attributes=(hash)
|
30
46
|
hash.each do |name, value|
|
31
47
|
if attribute_names.include?(name.to_s) || self.respond_to?("#{name}=")
|
32
48
|
self.send("#{name}=", value)
|
33
49
|
else
|
34
|
-
raise self.class::UnknownAttributeError, "unkown attribute
|
50
|
+
raise self.class::UnknownAttributeError, "unkown attribute: #{name}"
|
35
51
|
end
|
36
52
|
end
|
37
53
|
end
|
38
54
|
|
39
|
-
|
55
|
+
##
|
56
|
+
#
|
57
|
+
# Returns all attributes serialied as hash
|
58
|
+
#
|
40
59
|
def attributes
|
41
|
-
|
42
|
-
attribute_names.each { |name| attrs[name] = send(name) }
|
43
|
-
attrs
|
60
|
+
attribute_names.inject({}) { |h, name| h[name] = send(name); h }
|
44
61
|
end
|
45
62
|
end
|
46
63
|
end
|
data/lib/entasis/version.rb
CHANGED
data/spec/entasis_spec.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
require
|
2
|
-
require File.expand_path(File.dirname(__FILE__) + '/person')
|
1
|
+
require 'spec_helper'
|
3
2
|
|
4
3
|
describe "Entasis::Model" do
|
5
4
|
let(:hilda) { hilda = Person.new(:name => 'Hilda', :age => '23', :city => 'Berlin') }
|
@@ -14,7 +13,7 @@ describe "Entasis::Model" do
|
|
14
13
|
it "raises an error if attribute is unknown" do
|
15
14
|
expect {
|
16
15
|
Person.new(undefined: 'value')
|
17
|
-
}.to raise_error Person::UnknownAttributeError, 'unkown attribute
|
16
|
+
}.to raise_error Person::UnknownAttributeError, 'unkown attribute: undefined'
|
18
17
|
end
|
19
18
|
end
|
20
19
|
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: entasis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.0
|
5
|
-
prerelease:
|
4
|
+
version: 0.3.0
|
5
|
+
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Ingemar Edsborn
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|
@@ -61,7 +61,6 @@ files:
|
|
61
61
|
- README.md
|
62
62
|
- LICENSE
|
63
63
|
- spec/entasis_spec.rb
|
64
|
-
- spec/person.rb
|
65
64
|
- spec/spec_helper.rb
|
66
65
|
homepage: http://github.com/ingemar/entasis
|
67
66
|
licenses: []
|
@@ -78,16 +77,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
78
77
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
78
|
none: false
|
80
79
|
requirements:
|
81
|
-
- - ! '
|
80
|
+
- - ! '>='
|
82
81
|
- !ruby/object:Gem::Version
|
83
|
-
version:
|
82
|
+
version: '0'
|
84
83
|
requirements: []
|
85
84
|
rubyforge_project:
|
86
|
-
rubygems_version: 1.8.
|
85
|
+
rubygems_version: 1.8.24
|
87
86
|
signing_key:
|
88
87
|
specification_version: 3
|
89
88
|
summary: A few neat methods for a basic class
|
90
89
|
test_files:
|
91
90
|
- spec/entasis_spec.rb
|
92
|
-
- spec/person.rb
|
93
91
|
- spec/spec_helper.rb
|