hstorable 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a56275999230cf78d65804c8e404e4ddf4e4ef47
4
+ data.tar.gz: 12040b430a90ead22a84ee8953876a743bc310b6
5
+ SHA512:
6
+ metadata.gz: 42aa471017da9eab2d6ee97e1a0c0917e2e1084c9dddeeb7e6ab52b8cca1f6e70504f56abd43f24a80376a896290afa283785cd3933b48878a71ab3578b40b78
7
+ data.tar.gz: 867818f823c55fd8fd968af10a988df9fcdfdcbec66aec41470dc11e1a72ca390fe6f3ee2bba3b7c59e85a9a440ef24175a6544213676b69cf5e295b511a942e
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hstorable.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Sergey Tsvetkov
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,80 @@
1
+ # Hstorable
2
+
3
+ This gem simplifies working wih fields stored using Hstore
4
+
5
+ ## How to use
6
+
7
+ It is pertty easy to use HStorable with STI in RoR:
8
+
9
+ ```ruby
10
+
11
+ class Api::BaseWrapper < ActiveRecord::Base
12
+ extend Hstorable
13
+ end
14
+
15
+ class Api::OneApiWrapper < Api::BaseWrapper
16
+ hstore_simple :properties, name: 'consumer_key'
17
+ hstore_simple :properties, name: 'consumer_secret'
18
+ hstore_simple :properties, name: 'api_version', default: '26.0'
19
+ hstore_simple :properties, name: 'code', readonly: true
20
+ hstore_simple :properties, name: 'access_token', readonly: true
21
+ hstore_simple :properties, name: 'refresh_token', readonly: true
22
+ hstore_simple :properties, name: 'instance_url', readonly: true
23
+ hstore_simple :properties, name: 'state', readonly: true, default: 'created'
24
+ end
25
+
26
+ class Api::AnotherApiWrapper < Api::BaseWrapper
27
+ hstore_simple :properties, name: 'user_name'
28
+ hstore_simple :properties, name: 'secret'
29
+ end
30
+ ```
31
+
32
+ Different types of models with different set of fields will be stored in one table.
33
+
34
+ ## Installation
35
+
36
+ Add this line to your application's Gemfile:
37
+
38
+ gem 'hstorable'
39
+
40
+ And then execute:
41
+
42
+ $ bundle
43
+
44
+ Or install it yourself as:
45
+
46
+ $ gem install hstorable
47
+
48
+
49
+ ## Contributing
50
+
51
+ 1. Fork it ( http://github.com/kimrgrey/hstorable/fork )
52
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
53
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
54
+ 4. Push to the branch (`git push origin my-new-feature`)
55
+ 5. Create new Pull Request
56
+
57
+ ## License
58
+
59
+ Copyright (c) 2014 Sergey Tsvetkov
60
+
61
+ MIT License
62
+
63
+ Permission is hereby granted, free of charge, to any person obtaining
64
+ a copy of this software and associated documentation files (the
65
+ "Software"), to deal in the Software without restriction, including
66
+ without limitation the rights to use, copy, modify, merge, publish,
67
+ distribute, sublicense, and/or sell copies of the Software, and to
68
+ permit persons to whom the Software is furnished to do so, subject to
69
+ the following conditions:
70
+
71
+ The above copyright notice and this permission notice shall be
72
+ included in all copies or substantial portions of the Software.
73
+
74
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
75
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
76
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
77
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
78
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
79
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
80
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/hstorable.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'hstorable/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "hstorable"
8
+ spec.version = Hstorable::VERSION
9
+ spec.authors = ["Sergey Tsvetkov"]
10
+ spec.email = ["sergey.a.tsvetkov@gmail.com"]
11
+ spec.summary = %q{This gem simplifies working wih fields stored using Hstore}
12
+ spec.description = %q{This gem simplifies working wih fields stored using Hstore}
13
+ spec.homepage = "http://hstorable.kimrgrey.org/"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,3 @@
1
+ module Hstorable
2
+ VERSION = "0.0.1"
3
+ end
data/lib/hstorable.rb ADDED
@@ -0,0 +1,52 @@
1
+ require "hstorable/version"
2
+
3
+ module Hstorable
4
+ def hstore_register_field(name, options)
5
+ @hstore_fields ||= []
6
+ @hstore_fields << { name: name }.merge(options)
7
+ end
8
+
9
+ def hstore_field_names
10
+ @hstore_fields.map { |field| field[:name] }
11
+ end
12
+
13
+ def hstore_readonly_field?(name)
14
+ options = hstore_options_for_field(name)
15
+ options && options[:readonly]
16
+ end
17
+
18
+ def hstore_options_for_field(name)
19
+ @hstore_fields.find { |field| field[:name] == name }
20
+ end
21
+
22
+ def hstore_simple(field, options)
23
+ name = options[:name]
24
+ default = options[:default]
25
+
26
+ define_method "#{name}" do
27
+ hstore = self.send(field)
28
+ value = hstore[name]
29
+ value ? value : default
30
+ end
31
+
32
+ define_method "#{name}=" do |value|
33
+ hstore = self.send(field)
34
+ self.send("#{field}_will_change!") if hstore[name] != value
35
+ hstore[name] = value
36
+ hstore[name]
37
+ end
38
+
39
+ hstore_register_field(name, options)
40
+ end
41
+
42
+ def hstore_model(options)
43
+ # TODO Implement handling of model dependencies here
44
+ end
45
+
46
+ def hstore(type, field, options)
47
+ case type
48
+ when :simple then hstore_simple(field, options)
49
+ when :model then hstore_model(field, options)
50
+ end
51
+ end
52
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hstorable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sergey Tsvetkov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: This gem simplifies working wih fields stored using Hstore
42
+ email:
43
+ - sergey.a.tsvetkov@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - hstorable.gemspec
54
+ - lib/hstorable.rb
55
+ - lib/hstorable/version.rb
56
+ homepage: http://hstorable.kimrgrey.org/
57
+ licenses:
58
+ - MIT
59
+ metadata: {}
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 2.2.0
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: This gem simplifies working wih fields stored using Hstore
80
+ test_files: []