entasis 0.2.0 → 0.2.2
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/HISTORY +7 -0
- data/LICENSE +1 -1
- data/README.md +5 -3
- data/entasis.gemspec +14 -10
- data/lib/entasis/base.rb +36 -0
- data/lib/entasis/version.rb +1 -1
- data/lib/entasis.rb +3 -32
- data/spec/entasis_spec.rb +14 -0
- data/spec/person.rb +2 -0
- data/spec/spec_helper.rb +4 -4
- metadata +58 -45
data/HISTORY
CHANGED
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -16,6 +16,9 @@ Example:
|
|
16
16
|
hilda = Person.new(:name => 'Hilda', :age => '23', :city => 'Berlin')
|
17
17
|
hilda.attribute_names # => ["name", "age", "city"]
|
18
18
|
hilda.attributes # => {"name"=>"Hilda", "age"=>23, "city"=>"Berlin"}
|
19
|
+
anon = Person.new
|
20
|
+
anon.valid? # => false
|
21
|
+
anon.errors # => {:name=>["can't be blank"]}>
|
19
22
|
|
20
23
|
|
21
24
|
Note on Patches/Pull Requests
|
@@ -31,11 +34,10 @@ Note on Patches/Pull Requests
|
|
31
34
|
Author
|
32
35
|
------
|
33
36
|
|
34
|
-
Ingemar Edsborn (ingemar@
|
37
|
+
Ingemar Edsborn (ingemar@xox.se)
|
35
38
|
|
36
39
|
|
37
40
|
Copyright
|
38
41
|
---------
|
39
42
|
|
40
|
-
Copyright (c) 2010
|
41
|
-
|
43
|
+
Copyright (c) 2010 Ingemar Edsborn. See LICENSE for details
|
data/entasis.gemspec
CHANGED
@@ -3,15 +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
|
7
|
-
s.version
|
8
|
-
s.platform
|
9
|
-
s.authors
|
10
|
-
s.email
|
11
|
-
s.homepage = "http://github.com/ingemar/entasis"
|
12
|
-
s.summary = %q{A few neat methods for a basic class}
|
13
|
-
s.description = %q{Entasis provides a few very useful instance methods for Struct based classes. Handy for models without a database.}
|
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"]
|
14
11
|
|
15
|
-
s.
|
16
|
-
s.
|
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/*')
|
18
|
+
|
19
|
+
s.add_runtime_dependency('activemodel', '~> 3.0')
|
20
|
+
s.add_development_dependency 'rspec', '~> 2.0'
|
17
21
|
end
|
data/lib/entasis/base.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
module Entasis
|
2
|
+
class Base
|
3
|
+
include ActiveModel::Validations
|
4
|
+
|
5
|
+
class << self
|
6
|
+
# Takes a list of symbolized attribute names and defines them
|
7
|
+
def attributes(*attrs)
|
8
|
+
@@attribute_names = attrs.map(&:to_s)
|
9
|
+
attr_accessor(*attrs)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# Takes a hash and assigns keys and values to it's attributes members
|
14
|
+
def initialize(*args)
|
15
|
+
if args.first.is_a?(Hash) then set_attributes_from_hash(args.first) else super(*args) end
|
16
|
+
end
|
17
|
+
|
18
|
+
def attribute_names
|
19
|
+
@@attribute_names
|
20
|
+
end
|
21
|
+
|
22
|
+
# Returns an attributes hash
|
23
|
+
def attributes
|
24
|
+
attrs = {}
|
25
|
+
attribute_names.each { |name| attrs[name] = send(name) }
|
26
|
+
attrs
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
# Takes each key and value from the hash and assigns it to it's attribute.
|
31
|
+
def set_attributes_from_hash(hash)
|
32
|
+
hash.each_pair { |key, value| self.send("#{key}=", value) }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
data/lib/entasis/version.rb
CHANGED
data/lib/entasis.rb
CHANGED
@@ -1,34 +1,5 @@
|
|
1
|
-
|
2
|
-
class Base
|
3
|
-
class << self
|
4
|
-
# Takes a list of symbolized attribute names and defines them
|
5
|
-
def attributes(*attrs)
|
6
|
-
@@attribute_names = attrs.map(&:to_s)
|
7
|
-
attr_accessor(*attrs)
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
# Takes a hash and assigns keys and values to it's attributes members
|
12
|
-
def initialize(*args)
|
13
|
-
if args.first.is_a?(Hash) then set_attributes_from_hash(args.first) else super(*args) end
|
14
|
-
end
|
15
|
-
|
16
|
-
def attribute_names
|
17
|
-
@@attribute_names
|
18
|
-
end
|
1
|
+
require 'active_model'
|
19
2
|
|
20
|
-
|
21
|
-
|
22
|
-
attrs = {}
|
23
|
-
attribute_names.each { |name| attrs[name] = send(name) }
|
24
|
-
attrs
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
# Takes each key and value from the hash and assigns it to it's attribute.
|
29
|
-
def set_attributes_from_hash(hash)
|
30
|
-
hash.each_pair { |key, value| self.send("#{key}=", value) }
|
31
|
-
end
|
32
|
-
end
|
3
|
+
module Entasis
|
4
|
+
autoload :Base, 'entasis/base'
|
33
5
|
end
|
34
|
-
|
data/spec/entasis_spec.rb
CHANGED
@@ -23,4 +23,18 @@ describe "Entasis::Base" do
|
|
23
23
|
hilda.attributes.should == {"name"=>"Hilda", "age"=>23, "city"=>"Berlin"}
|
24
24
|
end
|
25
25
|
end
|
26
|
+
|
27
|
+
context "validations" do
|
28
|
+
describe "#valid?" do
|
29
|
+
it "validates" do
|
30
|
+
hilda.should be_valid
|
31
|
+
end
|
32
|
+
|
33
|
+
it "will have errors" do
|
34
|
+
anon = Person.new(:name => "")
|
35
|
+
anon.should_not be_valid
|
36
|
+
anon.errors.to_hash.should == { :name => ["can't be blank"] }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
26
40
|
end
|
data/spec/person.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require "rubygems"
|
2
|
+
require "bundler/setup"
|
3
|
+
|
3
4
|
require 'entasis'
|
4
|
-
require 'rspec'
|
5
5
|
|
6
|
-
|
6
|
+
RSpec.configure do |config|
|
7
7
|
end
|
metadata
CHANGED
@@ -1,34 +1,57 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: entasis
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 2
|
9
|
-
- 0
|
10
|
-
version: 0.2.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.2
|
5
|
+
prerelease:
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Ingemar Edsborn
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
-
|
12
|
+
date: 2012-08-24 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activemodel
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3.0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '2.0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '2.0'
|
46
|
+
description: Entasis provides a few useful methods for building a basic class. Handy
|
47
|
+
for models without a database.
|
48
|
+
email:
|
49
|
+
- ingemar@xox.se
|
25
50
|
executables: []
|
26
|
-
|
27
51
|
extensions: []
|
28
|
-
|
29
52
|
extra_rdoc_files: []
|
30
|
-
|
31
|
-
|
53
|
+
files:
|
54
|
+
- lib/entasis/base.rb
|
32
55
|
- lib/entasis/version.rb
|
33
56
|
- lib/entasis.rb
|
34
57
|
- Gemfile
|
@@ -39,41 +62,31 @@ files:
|
|
39
62
|
- spec/entasis_spec.rb
|
40
63
|
- spec/person.rb
|
41
64
|
- spec/spec_helper.rb
|
42
|
-
has_rdoc: true
|
43
65
|
homepage: http://github.com/ingemar/entasis
|
44
66
|
licenses: []
|
45
|
-
|
46
67
|
post_install_message:
|
47
68
|
rdoc_options: []
|
48
|
-
|
49
|
-
require_paths:
|
69
|
+
require_paths:
|
50
70
|
- lib
|
51
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
72
|
none: false
|
53
|
-
requirements:
|
54
|
-
- -
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
|
57
|
-
|
58
|
-
- 0
|
59
|
-
version: "0"
|
60
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
78
|
none: false
|
62
|
-
requirements:
|
63
|
-
- -
|
64
|
-
- !ruby/object:Gem::Version
|
65
|
-
|
66
|
-
segments:
|
67
|
-
- 0
|
68
|
-
version: "0"
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
requirements: []
|
70
|
-
|
71
84
|
rubyforge_project:
|
72
|
-
rubygems_version: 1.
|
85
|
+
rubygems_version: 1.8.23
|
73
86
|
signing_key:
|
74
87
|
specification_version: 3
|
75
88
|
summary: A few neat methods for a basic class
|
76
|
-
test_files:
|
89
|
+
test_files:
|
77
90
|
- spec/entasis_spec.rb
|
78
91
|
- spec/person.rb
|
79
92
|
- spec/spec_helper.rb
|