MasterRecord 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog ADDED
@@ -0,0 +1,3 @@
1
+ 0.3.1
2
+ * add attributes method (ex Item.find_one_by_price(40).attributes => {:id => "2",:identity => "Item@2",:name => "チョコレート",:price => 40})
3
+ * add []access (ex Item.find_one_by_price(50)[:id] => "3")
data/MasterRecord.gemspec CHANGED
@@ -5,20 +5,22 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "MasterRecord"
8
- s.version = "0.3.0"
8
+ s.version = "0.3.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Takeshi Morita"]
12
- s.date = "2011-12-17"
12
+ s.date = "2011-12-20"
13
13
  s.description = "Object Mapper for csv or tsv or yaml etc.. you can use find,find_one_by|field|,find_by_|field|"
14
14
  s.email = "laten@nifty.com"
15
15
  s.extra_rdoc_files = [
16
+ "ChangeLog",
16
17
  "LICENSE.txt",
17
18
  "README.rdoc"
18
19
  ]
19
20
  s.files = [
20
21
  ".document",
21
22
  ".rspec",
23
+ "ChangeLog",
22
24
  "Gemfile",
23
25
  "LICENSE.txt",
24
26
  "MasterRecord.gemspec",
data/README.rdoc CHANGED
@@ -21,6 +21,7 @@
21
21
  :name => MasterRecord.string,
22
22
  :population => MasterRecord.integer,
23
23
  :salutation => lambda{|r| "'#{r}!!'" }
24
+ :now => lambda{|r|"lambda{ Time.now.localtime('" + r + "')}"},
24
25
  }
25
26
  include MasterRecord
26
27
  end
@@ -45,6 +46,8 @@
45
46
  Item.load_data(MasterRecord::TSV.load_file(File.expand_path("./data/item.tsv", File.dirname(__FILE__))))
46
47
  Item.find().count => 3
47
48
  Item.find_by_price(50)[0].name => "ガム"
49
+ Item.find_one_by_price(50)[:id] => "3"
50
+ Item.find_one_by_price(40).attributes => {:id => "2",:identity => "Item@2",:name => "チョコレート",:price => 40}
48
51
 
49
52
  #1:
50
53
  # name: "Japan"
@@ -60,6 +63,8 @@
60
63
  Country.find().count => 2
61
64
  Country.find_one_by_population(500000000).name => "China"
62
65
  Country.find().map(&:salutation) => ["こんにちは!!","您好!!"]}
66
+ Country.find("1").now.call.to_s => "2011-12-18 01:01:00 +0900"
67
+ Country.find("2").now.call.to_s => "2011-12-18 00:01:00 +0800"
63
68
 
64
69
 
65
70
  == Contributing to MasterRecord
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
data/data/country.yml CHANGED
@@ -2,7 +2,9 @@
2
2
  name: "Japan"
3
3
  salutation: "こんにちは"
4
4
  population: 120000000
5
+ now: "+09:00"
5
6
  2:
6
7
  name: "China"
7
8
  salutation: "您好"
8
9
  population: 500000000
10
+ now: "+08:00"
data/lib/MasterRecord.rb CHANGED
@@ -53,6 +53,14 @@ module MasterRecord
53
53
  @info = rec[@id]
54
54
  end
55
55
 
56
+ def attributes
57
+ @info.merge({:id => @id,:identity => @identity})
58
+ end
59
+
60
+ def [](field)
61
+ attributes[field.to_sym]
62
+ end
63
+
56
64
  attr_reader :identity, :id
57
65
 
58
66
  def c.all
@@ -19,13 +19,15 @@ class Country
19
19
  CountryFields = {
20
20
  :name => MasterRecord.string,
21
21
  :population => MasterRecord.integer,
22
- :salutation => lambda{|r| "'#{r}!!'" }
22
+ :salutation => lambda{|r| "'#{r}!!'" },
23
+ :now => lambda{|r|"lambda{ Time.now.localtime('" + r + "')}"},
23
24
  }
24
25
  include MasterRecord
25
26
  end
26
27
  describe "Masterrecord" do
27
28
  describe "csv" do
28
29
  before do
30
+ #id,name,age
29
31
  #1,ひろし,10
30
32
  #2,たけし,20
31
33
  #3,まこと,30
@@ -47,7 +49,9 @@ describe "Masterrecord" do
47
49
  Item.load_data(MasterRecord::TSV.load_file(File.expand_path("../data/item.tsv", File.dirname(__FILE__))))
48
50
  end
49
51
  it{ Item.find().count.should == 3}
50
- it{ Item.find_by_price(50)[0].name.should == "ガム"}
52
+ it{ Item.find_by_price(50)[0]["name"].should == "ガム"}
53
+ it{ Item.find_one_by_price(50)[:id].should == "3"}
54
+ it{ Item.find_one_by_price(40).attributes.should == {:id => "2",:identity => "Item@2",:name => "チョコレート",:price => 40}}
51
55
  end
52
56
  describe "yml" do
53
57
  before do
@@ -55,15 +59,20 @@ describe "Masterrecord" do
55
59
  # name: "Japan"
56
60
  # population: 120000000
57
61
  # salutation: "こんにちは"
62
+ # now: "+09:00"
58
63
  #2:
59
64
  # name: "China"
60
65
  # population: 500000000
61
66
  # salutation: "您好"
67
+ # now: "+08:00"
62
68
  Country.load_data(
63
69
  MasterRecord::YAML.load_file(Country.fields,File.expand_path("../data/country.yml", File.dirname(__FILE__))))
70
+ @now = Time.new(2011,12,18,1,1,0)
71
+ Time.stub!(:now).and_return(@now)
64
72
  end
65
73
  it{ Country.find().count.should == 2}
66
- it{ Country.find_one_by_population(500000000).name.should == "China"}
67
74
  it{ Country.find().map(&:salutation).should == ["こんにちは!!","您好!!"]}
75
+ it{ Country.find("1").now.call.to_s.should == "2011-12-18 01:01:00 +0900"}
76
+ it{ Country.find("2").now.call.to_s.should == "2011-12-18 00:01:00 +0800"}
68
77
  end
69
78
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: MasterRecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
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-12-17 00:00:00.000000000 Z
12
+ date: 2011-12-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &20301620 !ruby/object:Gem::Requirement
16
+ requirement: &11611540 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 2.3.0
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *20301620
24
+ version_requirements: *11611540
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bundler
27
- requirement: &20300880 !ruby/object:Gem::Requirement
27
+ requirement: &11610740 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.0.0
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *20300880
35
+ version_requirements: *11610740
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: jeweler
38
- requirement: &20300320 !ruby/object:Gem::Requirement
38
+ requirement: &11609720 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.6.4
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *20300320
46
+ version_requirements: *11609720
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rcov
49
- requirement: &20299320 !ruby/object:Gem::Requirement
49
+ requirement: &11608860 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,17 +54,19 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *20299320
57
+ version_requirements: *11608860
58
58
  description: Object Mapper for csv or tsv or yaml etc.. you can use find,find_one_by|field|,find_by_|field|
59
59
  email: laten@nifty.com
60
60
  executables: []
61
61
  extensions: []
62
62
  extra_rdoc_files:
63
+ - ChangeLog
63
64
  - LICENSE.txt
64
65
  - README.rdoc
65
66
  files:
66
67
  - .document
67
68
  - .rspec
69
+ - ChangeLog
68
70
  - Gemfile
69
71
  - LICENSE.txt
70
72
  - MasterRecord.gemspec
@@ -96,7 +98,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
96
98
  version: '0'
97
99
  segments:
98
100
  - 0
99
- hash: -1265236637701093746
101
+ hash: -2812055945714536566
100
102
  required_rubygems_version: !ruby/object:Gem::Requirement
101
103
  none: false
102
104
  requirements: