stuff_arc 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # stuff_arc - supports Rails portable data dump and restore
2
2
 
3
- ## Version 0.0.2
3
+ ## Version 0.0.4
4
4
 
5
5
  stuff_arc adds class level archiving and unarchiving of an ActiveRecord object
6
6
  a Rails app.
data/lib/stuff_arc.rb CHANGED
@@ -12,13 +12,11 @@
12
12
  # Both methods are designed to be run from a Rails Console - not programatically.
13
13
 
14
14
  require 'rails'
15
+ require 'active_model'
15
16
  # require 'pry'
16
- # require 'active_support'
17
- # require 'active_support/inflector'
18
- # require 'active_support/json'
19
17
 
20
18
  module StuffArc
21
- VERSION = "0.0.3"
19
+ VERSION = "0.0.4"
22
20
 
23
21
  def self.included(mod)
24
22
  mod_lowercase = mod.to_s.underscore.pluralize
@@ -43,8 +41,8 @@ module StuffArc
43
41
  f = File.open(fname, 'w')
44
42
  list = self.all
45
43
  list.each do |#{mod_lowercase}|
46
- json_str = ActiveSupport::JSON.encode #{mod_lowercase}, :include_root_in_json => false, :except => :id
47
- f.write json_str + "\n"
44
+ # as_json returns a hash, which we have to change to a JSON string
45
+ f.write #{mod_lowercase}.as_json.to_json + "\n"
48
46
  end
49
47
  f.close
50
48
  list.length
@@ -71,7 +69,7 @@ module StuffArc
71
69
  f = File.new fname
72
70
 
73
71
  f.lines do |line|
74
- #{mod_lowercase} = self.new Hash[ActiveSupport::JSON.decode(line).map { |k,v| [k.to_sym, v] }]
72
+ #{mod_lowercase} = #{mod}.new.from_json(line.chomp)
75
73
  begin
76
74
  #{mod_lowercase}.save!
77
75
  rescue Exception => e
@@ -1,10 +1,12 @@
1
1
  $LOAD_PATH << File.expand_path("../../lib", __FILE__)
2
2
  require 'test/unit'
3
+ require 'active_model'
3
4
  require 'stuff_arc'
4
5
  # require 'active_model'
5
6
 
6
7
  class StuffArcHelper
7
8
  include StuffArc
9
+ include ActiveModel::Serializers::JSON
8
10
 
9
11
  class <<self
10
12
  attr_accessor :db
@@ -26,6 +28,16 @@ class StuffArcHelper
26
28
  def ==(other)
27
29
  self.foo == other.foo && self.bar == other.bar
28
30
  end
31
+
32
+ def attributes
33
+ {'foo' => @foo, 'bar' => @bar}
34
+ end
35
+
36
+ def attributes=(hash)
37
+ hash.each do |k,v|
38
+ self.instance_variable_set "@#{k}", v
39
+ end
40
+ end
29
41
 
30
42
  def self.all
31
43
  [self.new({foo: 'foo', bar: 'bar'}), self.new({foo: 'foo2', bar: 'bar2'})]
@@ -41,12 +53,12 @@ class StuffArcTest < Test::Unit::TestCase
41
53
  # puts "StuffArcHelper.public_methods: #{StuffArcHelper.public_methods.grep /arc/}"
42
54
  # end
43
55
 
44
- def teardown
45
- fname = StuffArcHelper.to_s.underscore.pluralize + '.json'
46
- [fname, fname + '~'].each do |fn|
47
- File.unlink(fn) if File.exists? fn
48
- end
49
- end
56
+ # def teardown
57
+ # fname = StuffArcHelper.to_s.underscore.pluralize + '.json'
58
+ # [fname, fname + '~'].each do |fn|
59
+ # File.unlink(fn) if File.exists? fn
60
+ # end
61
+ # end
50
62
 
51
63
  def test_methods_exist
52
64
  assert StuffArcHelper.respond_to?(:archive), "StuffArcHelper has class method :archive"
@@ -74,6 +86,7 @@ class StuffArcTest < Test::Unit::TestCase
74
86
  StuffArcHelper.archive :lib_dir => path
75
87
  assert File.exists?(File.join(path, 'stuff_arc_helpers.json')), "archive should be in #{path}"
76
88
  File.unlink File.join(path, 'stuff_arc_helpers.json') if File.exists? File.join(path, 'stuff_arc_helpers.json')
89
+ File.unlink File.join(path, 'stuff_arc_helpers.json~') if File.exists? File.join(path, 'stuff_arc_helpers.json~')
77
90
  Dir.rmdir path if File.exists? path
78
91
  end
79
92
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stuff_arc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
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-07 00:00:00.000000000Z
12
+ date: 2011-09-08 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &2166654720 !ruby/object:Gem::Requirement
16
+ requirement: &2166421240 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2166654720
24
+ version_requirements: *2166421240
25
25
  description: stuff_arc - adds class level archiving/unarchiving to ActiveRecord::Base
26
26
  children
27
27
  email: mike@clove.com