minimodel 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/minimodel.rb CHANGED
@@ -17,6 +17,14 @@ class MiniModel
17
17
  @attributes
18
18
  end
19
19
 
20
+ def to_json
21
+ @attributes.to_json
22
+ end
23
+
24
+ def read_attribute(name)
25
+ @attributes[name]
26
+ end
27
+
20
28
  def method_missing(symbol, *args, &block)
21
29
  if @attributes.has_key?(symbol) && args.empty? && block.nil?
22
30
  return @attributes[symbol]
@@ -25,6 +33,10 @@ class MiniModel
25
33
  end
26
34
  end
27
35
 
36
+ def respond_to_missing?(symbol, include_private = false)
37
+ @attributes.has_key?(symbol)
38
+ end
39
+
28
40
  class DuplicateKeyError < StandardError
29
41
  end
30
42
 
data/minimodel.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'minimodel'
3
- s.version = '0.1.0'
3
+ s.version = '0.2.0'
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.authors = ['Tim Craft']
6
6
  s.email = ['mail@timcraft.com']
@@ -1,5 +1,6 @@
1
1
  require 'minitest/autorun'
2
2
  require 'minimodel'
3
+ require 'json'
3
4
 
4
5
  class Currency < MiniModel
5
6
  indexed_by :code
@@ -15,6 +16,11 @@ describe 'A currency object' do
15
16
  @euro = Currency.new(code: 'EUR', name: 'Euro')
16
17
  end
17
18
 
19
+ it 'should respond_to?(:code) and respond_to?(:name)' do
20
+ @euro.respond_to?(:code).must_equal true
21
+ @euro.respond_to?(:name).must_equal true
22
+ end
23
+
18
24
  it 'should have attribute reader methods' do
19
25
  @euro.code.must_equal 'EUR'
20
26
  @euro.name.must_equal 'Euro'
@@ -41,6 +47,19 @@ describe 'A currency object' do
41
47
  @euro.to_hash.must_equal code: 'EUR', name: 'Euro'
42
48
  end
43
49
  end
50
+
51
+ describe '#to_json' do
52
+ it 'should return a string containing a JSON object' do
53
+ @euro.to_json.must_equal '{"code":"EUR","name":"Euro"}'
54
+ end
55
+ end
56
+
57
+ describe '#read_attribute' do
58
+ it 'should return the value corresponding to the given attribute name' do
59
+ @euro.read_attribute(:code).must_equal 'EUR'
60
+ @euro.read_attribute(:name).must_equal 'Euro'
61
+ end
62
+ end
44
63
  end
45
64
 
46
65
  describe Currency do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minimodel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-21 00:00:00.000000000Z
12
+ date: 2011-10-11 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &3990170 !ruby/object:Gem::Requirement
16
+ requirement: &9966180 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.0.3
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *3990170
24
+ version_requirements: *9966180
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: activerecord
27
- requirement: &3989920 !ruby/object:Gem::Requirement
27
+ requirement: &9965800 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: 3.0.3
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *3989920
35
+ version_requirements: *9965800
36
36
  description: A little library for defining little models
37
37
  email:
38
38
  - mail@timcraft.com