value_object_ar 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/methods.rb +33 -0
  2. data/lib/value_object_ar.rb +5 -0
  3. metadata +95 -0
data/lib/methods.rb ADDED
@@ -0,0 +1,33 @@
1
+ module ValueObjectAR
2
+ module Methods
3
+ extend ActiveSupport::Concern
4
+
5
+ module ClassMethods
6
+
7
+ def value_object(attribute, klass)
8
+ class_eval do
9
+ define_value_object_ar_reader(attribute, klass)
10
+ define_value_object_ar_writer(attribute, klass)
11
+ end
12
+ end
13
+
14
+ private
15
+
16
+ def define_value_object_ar_reader(attribute, klass)
17
+ define_method(attribute.to_s) do
18
+ klass.new(attributes[attribute.to_s])
19
+ end
20
+ end
21
+
22
+ def define_value_object_ar_writer(attribute, klass)
23
+ define_method("#{attribute}=") do |value|
24
+ if value.is_a?(klass)
25
+ value = value.send(attribute)
26
+ end
27
+ attributes[attribute.to_s] = value
28
+ end
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,5 @@
1
+ require 'active_support'
2
+ require 'active_record'
3
+ require 'methods'
4
+
5
+ ActiveRecord::Base.send(:include, ValueObjectAR::Methods)
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: value_object_ar
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Kasper Bjørn Nielsen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-31 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activerecord
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
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: activerecord-nulldb-adapter
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
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'
62
+ description:
63
+ email: kasperbn@gmail.com
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - lib/methods.rb
69
+ - lib/value_object_ar.rb
70
+ homepage: http://github.com/kasperbn/value_object_ar
71
+ licenses: []
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 1.8.25
92
+ signing_key:
93
+ specification_version: 3
94
+ summary: Value objects for your active models
95
+ test_files: []