storext-override 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c83c83640824e13b8e307bb8afb861182e26a128
4
+ data.tar.gz: 85b084bd733ca57e118fe4922549f6aa71a228dd
5
+ SHA512:
6
+ metadata.gz: 2e5dbff6348d395536cafb1d0c752bfc5f3d1715a29c446c2f168e300821207e2e450a31c12251594e9d993e83ec2032a0eb77822dbe15da370a704937464101
7
+ data.tar.gz: 0abd9931c9ca371f5ef76376a67092183aef6c59c2e5f222262dfa31739f982ad34e549a752a600e8f27a37135d0ba384acf44245ed2bf3a66c8d7f6ecda2ee8
data/MIT-LICENSE ADDED
@@ -0,0 +1,9 @@
1
+ Copyright (c) 2015 G5
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Storext Override
2
+
3
+ This has a specific use case: you want to have another model, most likely a `Setting` model, that may override the parent model.
4
+
5
+ ## Usage
6
+
7
+ ```ruby
8
+ class Computer < ActiveRecord::Base
9
+ # If `data` is a PostgreSQL htsore or json store, you don't need to define `store` below.
10
+ store :data, coder: JSON
11
+ include Storext.model
12
+
13
+ store_attributes :data do
14
+ manufacturer String, default: "IBM"
15
+ end
16
+ end
17
+
18
+ class Phone < ActiveRecord::Base
19
+ # If `data` is a PostgreSQL htsore or json store, you don't need to define `store` below.
20
+ store :data, coder: JSON
21
+
22
+ belongs_to :computer
23
+ include Storext::Override
24
+
25
+ storext_override(:computer, :data)
26
+ end
27
+ ```
28
+
29
+ This looks at Computer's `data` column and copies all accessors into its own, withe override ability.
30
+
31
+ See `spec/storext/override_spec.rb` for examples.
32
+
33
+ ## License
34
+
35
+ Copyright (c) 2015 G5
36
+
37
+ MIT License
38
+
39
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
40
+
41
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
42
+
43
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'StorextOverride'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+ Bundler::GemHelper.install_tasks
21
+
@@ -0,0 +1 @@
1
+ require 'storext/override'
@@ -0,0 +1,56 @@
1
+ require 'storext'
2
+
3
+ module Storext
4
+ module Override
5
+
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ include Storext.model
10
+ end
11
+
12
+ module ClassMethods
13
+ def storext_override(association_name, column_name)
14
+ association =
15
+ storext_overrider_find_association(association_name)
16
+ association_class = association.class_name.constantize
17
+
18
+ storext_definitions = association_class.storext_definitions
19
+ storext_definitions.each do |attr, attr_definition|
20
+ if attr_definition[:column] == column_name
21
+ storext_overrider_define_reader(
22
+ association_name,
23
+ column_name,
24
+ attr,
25
+ attr_definition
26
+ )
27
+ end
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def storext_overrider_find_association(name)
34
+ self.reflect_on_all_associations.find do |a|
35
+ a.name == name
36
+ end
37
+ end
38
+
39
+ def storext_overrider_define_reader(association_name, column_name, attr, attr_definition)
40
+ self.store_attribute(
41
+ column_name,
42
+ attr,
43
+ attr_definition[:type],
44
+ attr_definition[:opts].reject { |k,v| k == :default },
45
+ )
46
+
47
+ define_method attr do |*args|
48
+ super(*args) || send(association_name).send(attr)
49
+ end
50
+ end
51
+ end
52
+
53
+ end
54
+ end
55
+
56
+ # rest of our requires here...
@@ -0,0 +1,5 @@
1
+ module Storext
2
+ module Override
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :storext_override do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: storext-override
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - G5
8
+ - Ramon Tayag
9
+ - JP Moral
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2015-03-24 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rails
17
+ requirement: !ruby/object:Gem::Requirement
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
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: '0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: storext
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '1.0'
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '1.0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: sqlite3
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ - !ruby/object:Gem::Dependency
58
+ name: rspec-rails
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ type: :development
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ description: Mimic and be able to override another Storext model
72
+ email:
73
+ - la.team@g5search.com
74
+ - ramon.tayag@gmail.com
75
+ executables: []
76
+ extensions: []
77
+ extra_rdoc_files: []
78
+ files:
79
+ - MIT-LICENSE
80
+ - README.md
81
+ - Rakefile
82
+ - lib/storext-override.rb
83
+ - lib/storext/override.rb
84
+ - lib/storext/override/version.rb
85
+ - lib/tasks/storext_override_tasks.rake
86
+ homepage: https://github.com/g5/storext-override
87
+ licenses:
88
+ - MIT
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.4.3
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: Mimic and be able to override another Storext model
110
+ test_files: []