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 CHANGED
@@ -1,4 +1,2 @@
1
- source "http://rubygems.org"
2
-
3
- # Specify your gem's dependencies in entasis.gemspec
1
+ source :rubygems
4
2
  gemspec
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  entasis
2
2
  -------
3
+ [![Build Status](https://secure.travis-ci.org/ingemar/entasis.png)](http://travis-ci.org/ingemar/entasis)
3
4
 
4
5
  Entasis provides a few neat methods for building a basic class. Handy for models without a database.
5
6
 
data/lib/entasis/model.rb CHANGED
@@ -9,7 +9,10 @@ module Entasis
9
9
  end
10
10
 
11
11
  module ClassMethods
12
- # Takes a list of symbolized attribute names and defines them
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 \"#{name}\""
50
+ raise self.class::UnknownAttributeError, "unkown attribute: #{name}"
35
51
  end
36
52
  end
37
53
  end
38
54
 
39
- # Returns an attributes hash
55
+ ##
56
+ #
57
+ # Returns all attributes serialied as hash
58
+ #
40
59
  def attributes
41
- attrs = {}
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
@@ -1,3 +1,3 @@
1
1
  module Entasis
2
- VERSION = "0.3.0.rc1.1"
2
+ VERSION = "0.3.0"
3
3
  end
data/spec/entasis_spec.rb CHANGED
@@ -1,5 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
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 "undefined"'
16
+ }.to raise_error Person::UnknownAttributeError, 'unkown attribute: undefined'
18
17
  end
19
18
  end
20
19
 
data/spec/spec_helper.rb CHANGED
@@ -2,6 +2,7 @@ require "rubygems"
2
2
  require "bundler/setup"
3
3
 
4
4
  require 'entasis'
5
+ require File.expand_path(File.dirname(__FILE__) + '/support/person')
5
6
 
6
7
  RSpec.configure do |config|
7
8
  end
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.rc1.1
5
- prerelease: 6
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-25 00:00:00.000000000 Z
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: 1.3.1
82
+ version: '0'
84
83
  requirements: []
85
84
  rubyforge_project:
86
- rubygems_version: 1.8.23
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
data/spec/person.rb DELETED
@@ -1,11 +0,0 @@
1
- class Person
2
- include Entasis::Model
3
-
4
- attributes :name, :age, :city
5
-
6
- validates_presence_of :name
7
-
8
- def age=(years)
9
- @age = years.to_i
10
- end
11
- end