minimodel 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,37 @@
1
+ Minimodel: A little library for defining little models
2
+ ======================================================
3
+
4
+
5
+ Motivation
6
+ ----------
7
+
8
+ Many apps use small "read only" datasets that can easily be held in memory,
9
+ for example: currency data, country data, colour data, advertising banners,
10
+ options for select boxes, payment plans etc. Sometimes it's useful to model
11
+ this data without using a database, and that's what minimodel is for.
12
+
13
+
14
+ Example
15
+ -------
16
+
17
+ Here's how you could implement a currency model using minimodel:
18
+
19
+ ```ruby
20
+ require 'minimodel'
21
+
22
+ class Currency < MiniModel
23
+ indexed_by :code
24
+
25
+ insert code: 'EUR', name: 'Euro'
26
+ insert code: 'GBP', name: 'Pound sterling'
27
+ insert code: 'USD', name: 'United States dollar'
28
+ end
29
+ ```
30
+
31
+ The Currency class will respond to `#count` (returning the total number of
32
+ currencies), `#all` (returning an array of currency objects), and `#find`
33
+ (to lookup a specific currency by its code). Similar to ActiveRecord.
34
+ There's also a `load_from` class method which will load data from a YAML
35
+ file; useful for when you'd rather store the raw data outside of the class.
36
+
37
+ Take a look at `spec/*_spec.rb` for more examples. Have fun!
data/Rakefile CHANGED
@@ -1,5 +1,7 @@
1
1
  require 'rake/testtask'
2
2
 
3
+ task :default => :test
4
+
3
5
  Rake::TestTask.new do |t|
4
6
  t.test_files = FileList['spec/*_spec.rb']
5
7
  end
@@ -59,6 +59,10 @@ class MiniModel
59
59
  @auto_increment = options[:auto_increment] ? 1 : nil
60
60
  end
61
61
 
62
+ def keys
63
+ all.map(&primary_key)
64
+ end
65
+
62
66
  def insert(attributes)
63
67
  unless @auto_increment.nil?
64
68
  attributes[primary_key] = @auto_increment
@@ -1,13 +1,13 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'minimodel'
3
- s.version = '0.3.0'
3
+ s.version = '0.4.0'
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.authors = ['Tim Craft']
6
6
  s.email = ['mail@timcraft.com']
7
7
  s.homepage = 'http://github.com/timcraft/minimodel'
8
8
  s.description = 'A little library for defining little models'
9
9
  s.summary = 'See description'
10
- s.files = Dir.glob('{lib,spec}/**/*') + %w(README.txt Rakefile minimodel.gemspec)
10
+ s.files = Dir.glob('{lib,spec}/**/*') + %w(README.md Rakefile minimodel.gemspec)
11
11
  s.add_development_dependency('activesupport', ['>= 3.0.3'])
12
12
  s.add_development_dependency('activerecord', ['>= 3.0.3'])
13
13
  s.require_path = 'lib'
@@ -65,6 +65,12 @@ describe 'Currency' do
65
65
  end
66
66
  end
67
67
 
68
+ describe 'keys class method' do
69
+ it 'should return an array containing all the primary keys' do
70
+ Currency.keys.must_equal(%w(EUR GBP USD INR JPY))
71
+ end
72
+ end
73
+
68
74
  describe 'primary_key class method' do
69
75
  it 'should return the primary key specified using #indexed_by' do
70
76
  Currency.primary_key.must_equal(:code)
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.3.0
4
+ version: 0.4.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: 2012-01-31 00:00:00.000000000Z
12
+ date: 2012-04-09 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &10440420 !ruby/object:Gem::Requirement
16
+ requirement: &508110 !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: *10440420
24
+ version_requirements: *508110
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: activerecord
27
- requirement: &10440150 !ruby/object:Gem::Requirement
27
+ requirement: &487740 !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: *10440150
35
+ version_requirements: *487740
36
36
  description: A little library for defining little models
37
37
  email:
38
38
  - mail@timcraft.com
@@ -46,7 +46,7 @@ files:
46
46
  - spec/currency_data.yml
47
47
  - spec/currency_spec.rb
48
48
  - spec/dutch_education_spec.rb
49
- - README.txt
49
+ - README.md
50
50
  - Rakefile
51
51
  - minimodel.gemspec
52
52
  homepage: http://github.com/timcraft/minimodel
data/README.txt DELETED
@@ -1,27 +0,0 @@
1
- A little library for defining little models.
2
-
3
- Many apps use small "read only" datasets that can easily be held in memory,
4
- for example: currency data, country data, colour data, advertising banners,
5
- options for select boxes, payment plans etc. Sometimes it's useful to model
6
- this data without using your database, and that's what minimodel is for.
7
-
8
- Quick example:
9
-
10
- require 'minimodel'
11
-
12
- class Currency < MiniModel
13
- indexed_by :code
14
-
15
- insert code: 'EUR', name: 'Euro'
16
- insert code: 'GBP', name: 'Pound sterling'
17
- insert code: 'USD', name: 'United States dollar'
18
- end
19
-
20
-
21
- The Currency class will respond to #count (returning the total number of
22
- currencies), #all (returning an array of currency objects), and #find
23
- (to lookup a specific currency by its code). Just like ActiveRecord.
24
-
25
- Take a look at spec/*_spec.rb for more examples.
26
-
27
- Have fun.