cerealizer 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile.lock CHANGED
@@ -6,7 +6,24 @@ PATH
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
+ coderay (1.0.8)
9
10
  diff-lcs (1.1.3)
11
+ guard (1.5.4)
12
+ listen (>= 0.4.2)
13
+ lumberjack (>= 1.0.2)
14
+ pry (>= 0.9.10)
15
+ thor (>= 0.14.6)
16
+ guard-rspec (2.4.0)
17
+ guard (>= 1.1)
18
+ rspec (~> 2.11)
19
+ listen (0.6.0)
20
+ lumberjack (1.0.2)
21
+ method_source (0.8.1)
22
+ pry (0.9.11.4)
23
+ coderay (~> 1.0.5)
24
+ method_source (~> 0.8)
25
+ slop (~> 3.4)
26
+ rb-fsevent (0.9.3)
10
27
  rspec (2.12.0)
11
28
  rspec-core (~> 2.12.0)
12
29
  rspec-expectations (~> 2.12.0)
@@ -15,10 +32,14 @@ GEM
15
32
  rspec-expectations (2.12.1)
16
33
  diff-lcs (~> 1.1.3)
17
34
  rspec-mocks (2.12.2)
35
+ slop (3.4.3)
36
+ thor (0.17.0)
18
37
 
19
38
  PLATFORMS
20
39
  ruby
21
40
 
22
41
  DEPENDENCIES
23
42
  cerealizer!
43
+ guard-rspec
44
+ rb-fsevent (~> 0.9.1)
24
45
  rspec (>= 2.9.0)
data/Guardfile ADDED
@@ -0,0 +1,8 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec' do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+ end
data/cerealizer.gemspec CHANGED
@@ -18,4 +18,6 @@ Gem::Specification.new do |gem|
18
18
  gem.require_paths = ["lib"]
19
19
 
20
20
  gem.add_development_dependency 'rspec', '>= 2.9.0'
21
+ gem.add_development_dependency 'guard-rspec'
22
+ gem.add_development_dependency 'rb-fsevent', '~> 0.9.1'
21
23
  end
@@ -1,3 +1,3 @@
1
1
  module Cerealizer
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/cerealizer.rb CHANGED
@@ -19,17 +19,9 @@ module Cerealizer
19
19
  self
20
20
  end
21
21
 
22
- def self.key(key)
23
- keys.push Key.new(key)
24
- end
25
-
26
- def self.keys
27
- @keys ||= []
28
- end
29
-
30
22
  # Call methods on the object that's being presented and create a flat
31
23
  # hash for these mofos.
32
- def serializable_hash
24
+ def read_keys
33
25
  self.class.keys.inject Hash.new do |hash, key|
34
26
  hash[key.name] = proxy_reader(key.name) if readable?(key.name)
35
27
  hash
@@ -37,11 +29,21 @@ module Cerealizer
37
29
  end
38
30
 
39
31
  # Update the attrs on zie model.
40
- def update_attributes(attrs={})
41
- attrs.each { |key, value| proxy_writer(key, value) if writeable?(key.name) }
32
+ def write_keys(attrs)
33
+ attrs.each { |key, value| proxy_writer(key, value) if writeable?(key) }
42
34
  self
43
35
  end
44
36
 
37
+ # Registers a key with the class.
38
+ def self.key(key)
39
+ keys.push Key.new(key)
40
+ end
41
+
42
+ # Keys that are registered with the class.
43
+ def self.keys
44
+ @keys ||= []
45
+ end
46
+
45
47
  private
46
48
  # TODO - Should the default be writable?
47
49
  def writeable?(key)
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ describe Cerealizer do
4
+
5
+ # Anonomous classes we use to test cerealizer
6
+ let(:cereal_klass) { Struct.new(:name, :sugar_content, :private_notes, :owner_id) }
7
+ let(:user_klass) { Struct.new(:name, :role, :id) }
8
+ let(:serializer_klass) do
9
+ # Weird eh? Its an anonymous class. Don't want to litter the Global namespace with
10
+ # constants that don't make sense.
11
+ Class.new Cerealizer::Base do
12
+ key :name
13
+ key :private_notes
14
+ key :sugar_content
15
+ end
16
+ end
17
+
18
+ # We're gonna use these instances for the test cases.
19
+ let(:brad){ user_klass.new('Brad Gessler', :admin, 1) }
20
+ let(:joe){ user_klass.new('Joe Shmoe', :anon, 2) }
21
+ let(:cheerios){ cereal_klass.new('Cheerios', '1 gram', 'Tastes like cardboard', brad.id) }
22
+ let(:cheerios_serializer){ serializer_klass.new(cheerios, brad) }
23
+
24
+ describe "#read_keys" do
25
+ it "should serialize keys" do
26
+ cheerios_serializer.read_keys.keys.should include(:name, :private_notes, :sugar_content)
27
+ end
28
+
29
+ it "should serializer values" do
30
+ cheerios_serializer.read_keys.values.should include('Cheerios', '1 gram', 'Tastes like cardboard')
31
+ end
32
+ end
33
+
34
+ describe "#write_keys" do
35
+ it "should update object attributes" do
36
+ cheerios_serializer.write_keys(:name => 'Captain Crunch').object.name.should == 'Captain Crunch'
37
+ end
38
+ end
39
+
40
+ describe ".href" do
41
+ let(:serializer_klass) do
42
+ Class.new Cerealizer::Base do
43
+ href "/users/:owner_id"
44
+ end
45
+ end
46
+ end
47
+
48
+ end
@@ -0,0 +1,19 @@
1
+ require 'cerealizer'
2
+
3
+ # This file was generated by the `rspec --init` command. Conventionally, all
4
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
5
+ # Require this file using `require "spec_helper"` to ensure that it is only
6
+ # loaded once.
7
+ #
8
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
9
+ RSpec.configure do |config|
10
+ config.treat_symbols_as_metadata_keys_with_true_values = true
11
+ config.run_all_when_everything_filtered = true
12
+ config.filter_run :focus
13
+
14
+ # Run specs in random order to surface order dependencies. If you find an
15
+ # order dependency and want to debug it, you can fix the order by providing
16
+ # the seed, which is printed after each run.
17
+ # --seed 1234
18
+ config.order = 'random'
19
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cerealizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-08 00:00:00.000000000 Z
12
+ date: 2013-02-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -27,6 +27,38 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: 2.9.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: guard-rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rb-fsevent
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 0.9.1
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.9.1
30
62
  description: Serialize and deserialize classes and JSON.
31
63
  email:
32
64
  - brad@polleverywhere.com
@@ -35,14 +67,18 @@ extensions: []
35
67
  extra_rdoc_files: []
36
68
  files:
37
69
  - .gitignore
70
+ - .rspec
38
71
  - Gemfile
39
72
  - Gemfile.lock
73
+ - Guardfile
40
74
  - LICENSE.txt
41
75
  - README.md
42
76
  - Rakefile
43
77
  - cerealizer.gemspec
44
78
  - lib/cerealizer.rb
45
79
  - lib/cerealizer/version.rb
80
+ - spec/lib/cerealizer_spec.rb
81
+ - spec/spec_helper.rb
46
82
  homepage: http://github.com/polleverywhere/cerealizer
47
83
  licenses: []
48
84
  post_install_message:
@@ -68,5 +104,7 @@ signing_key:
68
104
  specification_version: 3
69
105
  summary: Dive into the nitty gritty details of serializing and deserializing between
70
106
  objects and a hash.
71
- test_files: []
107
+ test_files:
108
+ - spec/lib/cerealizer_spec.rb
109
+ - spec/spec_helper.rb
72
110
  has_rdoc: