entasis 0.5.0 → 1.0.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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YzRmZmE2ODA5MTRkMDMxODZiODFlNDljMzA2MDEyYmQxNWYwMTE1YQ==
4
+ Mzc0YmRmNjVlNzJlODJiNzQ5OTdjYTBiMGYwNTM4NWU3ZGEyZWY2MQ==
5
5
  data.tar.gz: !binary |-
6
- OGNkYTA0MDZkN2VmMzBkMDU1NzRkNzMwNzEzNGQzMWRmNTNiMmI4NA==
6
+ ZGFlODI4ZDllZDNkMGVmOTMwNGY5NDhkNDFkMTViY2YyMmI3NzllYg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- OTNlYWE4OTAyZmMwMmM1Y2ZhNzA4MmQ2MmNkMTM4ZGNjMDg4Y2Y2MDQ1NGQ4
10
- MTIyMDU4OWU1Y2U1MjdhZWY1ZjY2N2QyZTY3ZDdmOGZjNzk1NWI0MGZkZGFi
11
- MzM4OGY4NWEzMzQ1YzQzNGVjZjBhYjEyMzEzMGFjMGYwNmFmMDQ=
9
+ NzE1YWI5ZDQ1NTdkNjA3MzZjODkwYjNkYWU1YWM3NWZlMzdiNDk4Y2RhMGUw
10
+ Y2Q5YjEzMjJmZTQzNjc1ZTJmNGRjMTFhNWQ4NDlmMDJkNjZiNjc3YmY5MGY4
11
+ MTk1ZTE0MWEyMWE2ZTg0NDU5ZTVjYWMxNjVjMTBmNmIwNWU5NTg=
12
12
  data.tar.gz: !binary |-
13
- NjVhODIwMGY1ZjdjYTU4ODQxZDIzYTlhZTk2ZjkwZmU4OWQxMTA0ZjU2YmU4
14
- MzY0MzVjMDdjZTZiNzk4Y2RiM2UyNWVmZDdkMGNmYjY5NDEyZmFmZTk2ODc4
15
- YWJkNzdmNzlkYzU4OWU1NjE2MGFlODE5MWU1YWJlNTkzMDQ2YTM=
13
+ ZjYwMjdlOTBhNTMxMDJjNGU4NTE4ZDYwZDU1MjRlZGQ4NDE4NDBlZmMxZTRm
14
+ NzY1MWQ5YjdiNjA3ZGJjNGRhMDVhYWUwNzU1MTgxMTQ2MGEyNjQzOTljOTZk
15
+ MWFmZDVkNmI1NWYyYzljZTljM2ZkMDI2YjY0MmY0MGM3YWZiOTU=
data/HISTORY CHANGED
@@ -1,3 +1,11 @@
1
+ == 1.0.0
2
+ No longer raises error on unknown keys by default.
3
+ Introduced option of strict checkeing instead.
4
+ This contradict with previous versions of the gem.
5
+
6
+ == 0.5.0
7
+ Introduced relations between classes.
8
+
1
9
  == 0.4.0
2
10
  Introduced options for Entasis::Model.attributes and Entasis::TransposeKeys
3
11
  It's now possible to silently ignore unknown attributes by passing
data/README.md CHANGED
@@ -31,10 +31,6 @@ anon.valid? # => false
31
31
  anon.errors # => {:name=>["can't be blank"]}>
32
32
  ```
33
33
 
34
- Default behavior is to raise if any key in the hash given to `.new` or `#attributes=` is not defined,
35
- this can be circumvented by passing `ignore_undefined: true` as options when defining your attributes.
36
-
37
-
38
34
  Relations
39
35
  ---------
40
36
 
@@ -67,6 +63,13 @@ person.friends[0].best_friend == person # => true
67
63
  ```
68
64
 
69
65
 
66
+ Strict checking of attributes
67
+ -----------------------------
68
+
69
+ Default behavior is to ignore any key in the hash given to `.new` or `#attributes=` that's not in the list of attribute names.
70
+ By setting passing the option `strict: true` to the attribute definition it will raise an UnknownAttributeError for that class everytime an unkown key is in the given hash.
71
+
72
+
70
73
  Transposing keys
71
74
  ----------------
72
75
 
data/entasis.gemspec CHANGED
@@ -3,18 +3,19 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
  require "entasis/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
- s.name = "entasis"
7
- s.version = Entasis::VERSION
8
- s.platform = Gem::Platform::RUBY
9
- s.authors = ["Ingemar Edsborn"]
10
- s.email = ["ingemar@xox.se"]
11
-
12
- s.homepage = "http://github.com/ingemar/entasis"
13
- s.summary = %q{A few neat methods for a basic class}
14
- s.description = %q{Entasis provides a few useful methods for building a basic class. Handy for models without a database.}
15
-
16
- s.files = Dir.glob("lib/**/*") + %w(Gemfile entasis.gemspec HISTORY README.md LICENSE)
17
- s.test_files = Dir.glob('spec/*')
6
+ s.platform = Gem::Platform::RUBY
7
+ s.name = 'entasis'
8
+ s.summary = %q{A few neat methods for a basic class}
9
+ s.description = %q{Entasis provides a few useful methods for building a basic class. Handy for models without a database.}
10
+ s.version = Entasis::VERSION
11
+ s.authors = ["Ingemar Edsborn"]
12
+ s.email = 'ingemar@xox.se'
13
+ s.homepage = "http://github.com/ingemar/entasis"
14
+ s.license = 'MIT'
15
+ s.required_ruby_version = '>= 1.9.3'
16
+ s.has_rdoc = true
17
+ s.files = Dir.glob("lib/**/*") + %w(Gemfile entasis.gemspec README.md HISTORY LICENSE)
18
+ s.test_files = Dir.glob('spec/*')
18
19
 
19
20
  s.add_runtime_dependency 'activemodel', '~> 3.1'
20
21
  s.add_development_dependency 'rspec', '~> 2.0'
data/lib/entasis/model.rb CHANGED
@@ -19,7 +19,7 @@ module Entasis
19
19
  #
20
20
  # Last argument can be an options hash:
21
21
  #
22
- # ignore_undefined: true - Silently ignore any undefined attributes
22
+ # strict: true - Raise UnknownAttributeError when given an unknown attribute.
23
23
  #
24
24
  def attributes(*attrs)
25
25
  self.attributes_config = attrs.last.is_a?(Hash) ? attrs.pop : {}
@@ -49,7 +49,7 @@ module Entasis
49
49
  if attribute_names.include?(name.to_s) || self.respond_to?("#{name}=")
50
50
  self.send("#{name}=", value)
51
51
  else
52
- if attributes_config[:ignore_undefined] != true
52
+ if attributes_config[:strict] == true
53
53
  raise self.class::UnknownAttributeError, "unknown attribute: #{name}"
54
54
  end
55
55
  end
@@ -9,8 +9,11 @@ module Entasis
9
9
  ##
10
10
  #
11
11
  # Takes a hash of attribute names and values and set each attribute.
12
+ # Before trying to set the given attribute it transpose the name of that
13
+ # attribute from camelcased to underscored.
12
14
  #
13
- # If passwed an unkown attribute it ill raise +class::UnknownAttributeError+
15
+ # If strict attribute name checking is enabled it will raise
16
+ # an +UnknownAttributeError+ for that class.
14
17
  #
15
18
  def attributes_with_transpose=(hash)
16
19
  hash.each do |name, value|
@@ -18,7 +21,7 @@ module Entasis
18
21
  if attribute_names.include?(transposed_name) || self.respond_to?("#{transposed_name}=")
19
22
  self.send("#{transposed_name}=", value)
20
23
  else
21
- if attributes_config[:ignore_undefined] != true
24
+ if attributes_config[:strict] == true
22
25
  raise self.class::UnknownAttributeError, "unknown attribute: #{transposed_name} (transposed from #{name})"
23
26
  end
24
27
  end
@@ -1,3 +1,3 @@
1
1
  module Entasis
2
- VERSION = "0.5.0"
2
+ VERSION = "1.0.0"
3
3
  end
data/spec/entasis_spec.rb CHANGED
@@ -34,17 +34,21 @@ describe Entasis::Model do
34
34
  end
35
35
  end
36
36
 
37
- it 'raises an error if attribute is unknown' do
38
- expect {
39
- Person.new(undefined: 'value')
40
- }.to raise_error Person::UnknownAttributeError, 'unknown attribute: undefined'
41
- end
37
+ context 'when given unknown attributes' do
38
+ subject { Person.new(undefined: 'value') }
39
+
40
+ it 'ignore unknown attributes' do
41
+ expect(subject.attributes.keys).not_to include('undifined')
42
+ end
42
43
 
43
- context 'when .attributes option :allow_unknown is set to true' do
44
- subject { RelaxedPerson.new(undefined: 'value') }
44
+ context 'when .attributes option :strict is set to true' do
45
+ subject { StrictPerson.new(undefined: 'value') }
45
46
 
46
- it 'ignores that attribute' do
47
- expect(subject.attributes.keys).to_not include('undifined')
47
+ it 'raises an error if attribute is unknown' do
48
+ expect {
49
+ StrictPerson.new(undefined: 'value')
50
+ }.to raise_error StrictPerson::UnknownAttributeError, 'unknown attribute: undefined'
51
+ end
48
52
  end
49
53
  end
50
54
  end
@@ -17,10 +17,20 @@ describe Entasis::TransposeKeys do
17
17
  end
18
18
  end
19
19
 
20
- it 'raises an error if attribute is unknown' do
21
- expect {
22
- Car.new(unDefined: 'value')
23
- }.to raise_error Car::UnknownAttributeError, 'unknown attribute: un_defined (transposed from unDefined)'
20
+ context 'when given unknown attributes' do
21
+ subject { Car.new(undefined: 'value') }
22
+
23
+ it 'ignore unknown attributes' do
24
+ expect(subject.attributes.keys).not_to include('undifined')
25
+ end
26
+
27
+ context 'when .attributes option :strict is set to true' do
28
+ it 'raises an error if attribute is unknown' do
29
+ expect {
30
+ Car::Destination.new(unDefined: 'value')
31
+ }.to raise_error Car::Destination::UnknownAttributeError, 'unknown attribute: un_defined (transposed from unDefined)'
32
+ end
33
+ end
24
34
  end
25
35
  end
26
36
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: entasis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ingemar Edsborn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-01 00:00:00.000000000 Z
11
+ date: 2013-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -40,8 +40,7 @@ dependencies:
40
40
  version: '2.0'
41
41
  description: Entasis provides a few useful methods for building a basic class. Handy
42
42
  for models without a database.
43
- email:
44
- - ingemar@xox.se
43
+ email: ingemar@xox.se
45
44
  executables: []
46
45
  extensions: []
47
46
  extra_rdoc_files: []
@@ -54,15 +53,16 @@ files:
54
53
  - lib/entasis.rb
55
54
  - Gemfile
56
55
  - entasis.gemspec
57
- - HISTORY
58
56
  - README.md
57
+ - HISTORY
59
58
  - LICENSE
60
59
  - spec/entasis_spec.rb
61
60
  - spec/relations_spec.rb
62
61
  - spec/spec_helper.rb
63
62
  - spec/transpose_keys_spec.rb
64
63
  homepage: http://github.com/ingemar/entasis
65
- licenses: []
64
+ licenses:
65
+ - MIT
66
66
  metadata: {}
67
67
  post_install_message:
68
68
  rdoc_options: []
@@ -72,7 +72,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ! '>='
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: 1.9.3
76
76
  required_rubygems_version: !ruby/object:Gem::Requirement
77
77
  requirements:
78
78
  - - ! '>='