sequel_json_attributes 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/sequel_json_attributes.rb +30 -0
  2. metadata +47 -0
@@ -0,0 +1,30 @@
1
+ module Sequel
2
+ module Plugins
3
+ module JsonAttributes
4
+ module ClassMethods
5
+ def store attribute, options
6
+ options[:accessors].each do |accessor|
7
+ #define reader
8
+ send :define_method, accessor do
9
+ json = send attribute
10
+ if json
11
+ JSON.parse(json)[accessor.to_s]
12
+ else
13
+ nil
14
+ end
15
+ end
16
+
17
+ #define writer
18
+ send :define_method, "#{accessor.to_s}=".to_sym do |value|
19
+ json = send(attribute) || {}.to_json
20
+ parsed_json = JSON.parse json
21
+ parsed_json[accessor.to_s] = value
22
+ send "#{attribute.to_s}=".to_sym, parsed_json.to_json
23
+ value
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sequel_json_attributes
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Misha Conway
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-04 00:00:00.000000000Z
13
+ dependencies: []
14
+ description:
15
+ email: MishaAConway@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/sequel_json_attributes.rb
21
+ homepage:
22
+ licenses: []
23
+ post_install_message:
24
+ rdoc_options: []
25
+ require_paths:
26
+ - lib
27
+ required_ruby_version: !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project: nowarning
41
+ rubygems_version: 1.8.15
42
+ signing_key:
43
+ specification_version: 3
44
+ summary: ! "Implements ActiveRecord::Store for Sequel models.Example:class User <
45
+ Sequel::Model\tplugin :json_attributesstore :json_data, :accessors => [:x_user_id,
46
+ :o_user_id]end"
47
+ test_files: []