ambry 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/Changelog.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Ambry Changelog
2
2
 
3
+ ## [0.1.2](https://github.com/norman/ambry/tree/0.1.1) - 2001-08-29 ([diff](https://github.com/norman/ambry/compare/0.1.1...0.1.2))
4
+
5
+ ### [Norman Clarke](https://github.com/norman)
6
+
7
+ * Add read-only option to adapters
8
+
9
+ ### [Luis Lavena](https://github.com/luislavena)
10
+
11
+ * Load Marshal data as binary
12
+
13
+
3
14
  ## [0.1.1](https://github.com/norman/ambry/tree/0.1.1) - 2011-08-24 ([diff](https://github.com/norman/ambry/compare/0.1.0...0.1.1))
4
15
 
5
16
  ### [Esad Hajdarevic](https://github.com/esad)
data/lib/ambry/adapter.rb CHANGED
@@ -9,10 +9,12 @@ module Ambry
9
9
 
10
10
  attr_reader :name
11
11
  attr_reader :db
12
+ attr_accessor :read_only
12
13
 
13
14
  # @option options [String] :name The adapter name. Defaults to {#Ambry.default_adapter_name}.
14
15
  def initialize(options = {})
15
- @name = options[:name] || Ambry.default_adapter_name
16
+ @name = options[:name] || Ambry.default_adapter_name
17
+ @read_only = false
16
18
  load_database
17
19
  Ambry.register_adapter(self)
18
20
  end
@@ -44,9 +46,16 @@ module Ambry
44
46
  true
45
47
  end
46
48
 
49
+ # Is the adapter read only? If so, attempts to write data will raise an
50
+ # AmbryError.
51
+ def read_only?
52
+ @read_only
53
+ end
54
+
47
55
  # Inheriting adapters can overload this method to persist the data to some
48
56
  # kind of storage.
49
57
  def save_database
58
+ raise AmbryError if read_only?
50
59
  true
51
60
  end
52
61
  end
@@ -8,6 +8,7 @@ module Ambry
8
8
 
9
9
  def initialize(options)
10
10
  @file_path = options[:file]
11
+ @read_only = !! options[:read_only]
11
12
  @lock = Mutex.new
12
13
  super
13
14
  end
@@ -25,12 +26,14 @@ module Ambry
25
26
  end
26
27
 
27
28
  def import_data
28
- Marshal.load(::File.read(file_path))
29
+ data = ::File.open(file_path, "rb") { |f| f.read }
30
+ Marshal.load(data)
29
31
  end
30
32
 
31
33
  def save_database
34
+ super
32
35
  @lock.synchronize do
33
- ::File.open(file_path, "w") {|f| f.write(export_data)}
36
+ ::File.open(file_path, "wb") {|f| f.write(export_data)}
34
37
  end
35
38
  end
36
39
  end
data/lib/ambry/version.rb CHANGED
@@ -2,7 +2,7 @@ module Ambry
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 1
5
+ TINY = 2
6
6
  BUILD = nil
7
7
  STRING = [MAJOR, MINOR, TINY, BUILD].compact.join('.')
8
8
  end
@@ -35,6 +35,14 @@ classes.each do |klass|
35
35
  assert @adapter.save_database
36
36
  assert File.exists? @path
37
37
  end
38
+
39
+ it "should raise an AmbryError if it's read-only" do
40
+ @adapter.read_only = true
41
+ assert_raises Ambry::AmbryError do
42
+ @adapter.save_database
43
+ end
44
+ end
45
+
38
46
  end
39
47
 
40
48
  describe "#load_database" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ambry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-24 00:00:00.000000000 Z
12
+ date: 2011-08-29 00:00:00.000000000 -03:00
13
+ default_executable:
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: ffaker
16
- requirement: &70346028569780 !ruby/object:Gem::Requirement
17
+ requirement: &70300868631420 !ruby/object:Gem::Requirement
17
18
  none: false
18
19
  requirements:
19
20
  - - ! '>='
@@ -21,10 +22,10 @@ dependencies:
21
22
  version: '0'
22
23
  type: :development
23
24
  prerelease: false
24
- version_requirements: *70346028569780
25
+ version_requirements: *70300868631420
25
26
  - !ruby/object:Gem::Dependency
26
27
  name: minitest
27
- requirement: &70346028569280 !ruby/object:Gem::Requirement
28
+ requirement: &70300868630540 !ruby/object:Gem::Requirement
28
29
  none: false
29
30
  requirements:
30
31
  - - ~>
@@ -32,10 +33,10 @@ dependencies:
32
33
  version: 2.2.2
33
34
  type: :development
34
35
  prerelease: false
35
- version_requirements: *70346028569280
36
+ version_requirements: *70300868630540
36
37
  - !ruby/object:Gem::Dependency
37
38
  name: mocha
38
- requirement: &70346028568860 !ruby/object:Gem::Requirement
39
+ requirement: &70300868629560 !ruby/object:Gem::Requirement
39
40
  none: false
40
41
  requirements:
41
42
  - - ! '>='
@@ -43,10 +44,10 @@ dependencies:
43
44
  version: '0'
44
45
  type: :development
45
46
  prerelease: false
46
- version_requirements: *70346028568860
47
+ version_requirements: *70300868629560
47
48
  - !ruby/object:Gem::Dependency
48
49
  name: activesupport
49
- requirement: &70346028568320 !ruby/object:Gem::Requirement
50
+ requirement: &70300868625940 !ruby/object:Gem::Requirement
50
51
  none: false
51
52
  requirements:
52
53
  - - ~>
@@ -54,10 +55,10 @@ dependencies:
54
55
  version: '3.0'
55
56
  type: :development
56
57
  prerelease: false
57
- version_requirements: *70346028568320
58
+ version_requirements: *70300868625940
58
59
  - !ruby/object:Gem::Dependency
59
60
  name: activemodel
60
- requirement: &70346028567820 !ruby/object:Gem::Requirement
61
+ requirement: &70300868625020 !ruby/object:Gem::Requirement
61
62
  none: false
62
63
  requirements:
63
64
  - - ~>
@@ -65,10 +66,10 @@ dependencies:
65
66
  version: '3.0'
66
67
  type: :development
67
68
  prerelease: false
68
- version_requirements: *70346028567820
69
+ version_requirements: *70300868625020
69
70
  - !ruby/object:Gem::Dependency
70
71
  name: rake
71
- requirement: &70346028567440 !ruby/object:Gem::Requirement
72
+ requirement: &70300868621760 !ruby/object:Gem::Requirement
72
73
  none: false
73
74
  requirements:
74
75
  - - ! '>='
@@ -76,7 +77,7 @@ dependencies:
76
77
  version: '0'
77
78
  type: :development
78
79
  prerelease: false
79
- version_requirements: *70346028567440
80
+ version_requirements: *70300868621760
80
81
  description: ! " Ambry is not an ORM, man! It's a database and ORM replacement
81
82
  for (mostly)\n static models and small datasets. It provides ActiveModel compatibility,
82
83
  and\n flexible searching and storage.\n"
@@ -117,6 +118,7 @@ files:
117
118
  - spec/mapper_spec.rb
118
119
  - spec/model_spec.rb
119
120
  - spec/spec_helper.rb
121
+ has_rdoc: true
120
122
  homepage: http://github.com/norman/ambry
121
123
  licenses: []
122
124
  post_install_message:
@@ -137,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
137
139
  version: '0'
138
140
  requirements: []
139
141
  rubyforge_project: ! '[none]'
140
- rubygems_version: 1.8.6
142
+ rubygems_version: 1.6.2
141
143
  signing_key:
142
144
  specification_version: 3
143
145
  summary: An ActiveModel-compatible ORM-like library for storing model instances in