dynabix 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,23 @@
1
+ .gemfiles
2
+ .gitattributes
3
+ .gitignore
4
+ .rspec
5
+ .yardopts
6
+ Gemfile
7
+ Gemfile.lock
8
+ Guardfile
9
+ HISTORY.markdown
10
+ LICENSE
11
+ README.markdown
12
+ Rakefile
13
+ VERSION
14
+ dynabix.gemspec
15
+ lib/dynabix.rb
16
+ lib/dynabix/metadata.rb
17
+ spec/aruba_helper.rb
18
+ spec/basic_gem/aruba_helper_spec.rb
19
+ spec/basic_gem/basic_gem_spec.rb
20
+ spec/basic_gem/gemspec_spec.rb
21
+ spec/dynabix/metadata_spec.rb
22
+ spec/schema.rb
23
+ spec/spec_helper.rb
@@ -0,0 +1 @@
1
+ *.rb diff=ruby
@@ -0,0 +1,7 @@
1
+ /pkg/
2
+ /.bundle/
3
+ /rdoc/
4
+ /.yardoc/
5
+ rerun.txt
6
+ tags
7
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --colour
2
+ #--format progress
3
+ --format documentation
@@ -0,0 +1,9 @@
1
+ --verbose
2
+ lib/**/*.rb
3
+ features/**/*.feature
4
+ features/step_definitions/**/*.rb
5
+ features/support/env.rb
6
+ -
7
+ LICENSE
8
+ HISTORY.markdown
9
+ VERSION
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in the .gemspec file
4
+ gemspec
5
+
6
+ # Linux only supplement to .gemspec
7
+ group :development do
8
+ gem "libnotify" if RUBY_PLATFORM.downcase.include?("linux")
9
+ end
@@ -0,0 +1,87 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ dynabix (0.3.0)
5
+ activerecord (~> 3.0)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ activemodel (3.2.3)
11
+ activesupport (= 3.2.3)
12
+ builder (~> 3.0.0)
13
+ activerecord (3.2.3)
14
+ activemodel (= 3.2.3)
15
+ activesupport (= 3.2.3)
16
+ arel (~> 3.0.2)
17
+ tzinfo (~> 0.3.29)
18
+ activesupport (3.2.3)
19
+ i18n (~> 0.6)
20
+ multi_json (~> 1.0)
21
+ arel (3.0.2)
22
+ aruba (0.4.5)
23
+ bcat (>= 0.6.1)
24
+ childprocess (>= 0.1.9)
25
+ cucumber (>= 0.10.7)
26
+ rdiscount (>= 1.6.8)
27
+ rspec (>= 2.6.0)
28
+ bcat (0.6.2)
29
+ rack (~> 1.0)
30
+ builder (3.0.0)
31
+ childprocess (0.3.1)
32
+ ffi (~> 1.0.6)
33
+ cucumber (1.1.9)
34
+ builder (>= 2.1.2)
35
+ diff-lcs (>= 1.1.2)
36
+ gherkin (~> 2.9.0)
37
+ json (>= 1.4.6)
38
+ term-ansicolor (>= 1.0.6)
39
+ diff-lcs (1.1.3)
40
+ ffi (1.0.11)
41
+ gherkin (2.9.0)
42
+ json (>= 1.4.6)
43
+ guard (1.0.1)
44
+ ffi (>= 0.5.0)
45
+ thor (~> 0.14.6)
46
+ guard-rspec (0.7.0)
47
+ guard (>= 0.10.0)
48
+ i18n (0.6.0)
49
+ json (1.6.6)
50
+ libnotify (0.7.2)
51
+ ffi (~> 1.0.0)
52
+ multi_json (1.3.4)
53
+ rack (1.4.1)
54
+ rake (0.9.2.2)
55
+ rdiscount (1.6.8)
56
+ redcarpet (2.1.0)
57
+ rspec (2.9.0)
58
+ rspec-core (~> 2.9.0)
59
+ rspec-expectations (~> 2.9.0)
60
+ rspec-mocks (~> 2.9.0)
61
+ rspec-core (2.9.0)
62
+ rspec-expectations (2.9.1)
63
+ diff-lcs (~> 1.1.3)
64
+ rspec-mocks (2.9.0)
65
+ sqlite3 (1.3.5)
66
+ sqlite3-ruby (1.3.3)
67
+ sqlite3 (>= 1.3.3)
68
+ term-ansicolor (1.0.7)
69
+ thor (0.14.6)
70
+ tzinfo (0.3.33)
71
+ yard (0.7.5)
72
+
73
+ PLATFORMS
74
+ ruby
75
+
76
+ DEPENDENCIES
77
+ aruba (= 0.4.5)
78
+ bundler (>= 1.0.14)
79
+ dynabix!
80
+ guard (~> 1.0)
81
+ guard-rspec (~> 0.6)
82
+ libnotify
83
+ rake (>= 0.8.7)
84
+ redcarpet (>= 1.17.2)
85
+ rspec (>= 2.6.0)
86
+ sqlite3-ruby (>= 0.8.7)
87
+ yard (>= 0.7.4)
@@ -0,0 +1,17 @@
1
+ group :specs do
2
+ guard 'rspec',
3
+ :all_after_pass => false,
4
+ :all_on_start => false,
5
+ :cli => '--color --format nested --fail-fast',
6
+ :version => 2 do
7
+
8
+ watch(%r{^spec/.+_spec\.rb$})
9
+ watch('spec/spec_helper.rb') { "spec" }
10
+
11
+ # ex: lib/app_name/views.rb -> spec/app_name/views_spec.rb
12
+ watch(%r{^lib/(.+)/(.+)\.rb$}) { |m| "spec/#{m[1]}/#{m[2]}_spec.rb" }
13
+
14
+ # ex: lib/app_name/views/view_helper.rb -> spec/app_name/views/view_helper_spec.rb
15
+ watch(%r{^lib/(.+)/(.+)/(.+)\.rb$}) { |m| "spec/#{m[1]}/#{m[2]}/#{m[3]}_spec.rb" }
16
+ end
17
+ end
@@ -0,0 +1,12 @@
1
+ Dynabix History
2
+ ===============
3
+
4
+ Most recent changes are at the top
5
+
6
+
7
+ Changes
8
+ -------
9
+
10
+ ### 0.3.0 - TBD ###
11
+
12
+ * Initial release
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 GearheadForHire, LLC
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,154 @@
1
+ Dynabix
2
+ ========
3
+
4
+ An ActiveRecord 3.x Ruby gem for attribute serialization.
5
+
6
+ "Dy-na-bix, tasty serialization attribute accessors for ActiveRecord"
7
+
8
+ Overview
9
+ --------
10
+
11
+ Dynabix dynamically creates read/write accessors on ActiveRecord models for
12
+ storing attributes in a serialized Hash.
13
+
14
+ Installation
15
+ ------------
16
+
17
+ Add to your Gemfile
18
+
19
+ gem "dynabix"
20
+
21
+ Install the gem
22
+
23
+ bundle install
24
+
25
+ Development
26
+ -----------
27
+
28
+ Get the source
29
+
30
+ cd workspace
31
+
32
+ git clone https://github.com/robertwahler/dynabix.git
33
+
34
+ cd dynabix
35
+
36
+ Install the dependencies
37
+
38
+ bundle install
39
+
40
+ Run the specs
41
+
42
+ bundle exec rake spec
43
+
44
+ Autotest with Guard
45
+
46
+ bundle exec guard
47
+
48
+ Usage Examples
49
+ --------------
50
+
51
+ ### Ruby 1.8
52
+
53
+ Add a text column "metadata" to your model migration
54
+
55
+
56
+ class AddMetadataToThings < ActiveRecord::Migration
57
+
58
+ def change
59
+ add_column :things, :metadata, :text
60
+ end
61
+
62
+ end
63
+
64
+ Add accessors to your model using the default column name ":metadata", specify
65
+ the attributes in a separate step.
66
+
67
+ class Thing < ActiveRecord::Base
68
+ has_metadata
69
+
70
+ # full accessors
71
+ metadata_accessor :breakfast_food, :wheat_products, :needs_milk
72
+
73
+ # read-only
74
+ metadata_reader :friends_with_spoons
75
+ end
76
+
77
+ Specifying attributes for full attributes accessors in one step
78
+
79
+ class Thing < ActiveRecord::Base
80
+ has_metadata :metadata, :breakfast_food, :wheat_products, :needs_milk
81
+ end
82
+
83
+ Using the new accessors
84
+
85
+ thing = Thing.new
86
+
87
+ thing.breakfast_food = 'a wheat like cereal"
88
+
89
+ # same thing, but not using the hash directly
90
+ thing.metadata[:breakfast_food] = 'a wheat like cereal"
91
+
92
+ ### Ruby 1.9+
93
+
94
+ Dynabix under Ruby 1.9+ enables specifying multiple metadata columns on a model.
95
+
96
+ Add text columns "cows" and "chickens" to your model migration
97
+
98
+ class AddMetadataToThings < ActiveRecord::Migration
99
+
100
+ def change
101
+ add_column :things, :cows, :text
102
+ add_column :things, :chickens, :text
103
+ end
104
+
105
+ end
106
+
107
+ Specifying multiple metadata serializers (Ruby 1.9 only)
108
+
109
+ class Thing < ActiveRecord::Base
110
+ has_metadata :cows
111
+ has_metadata :chickens, :tasty, :feather_count
112
+
113
+ # read-only
114
+ cow_reader :likes_milk, :hates_eggs
115
+
116
+ # write-only
117
+ cow_writer :no_wheat_products
118
+
119
+ # extra full accessors for chickens
120
+ chicken_accessor :color, :likes_eggs
121
+ end
122
+
123
+ Runtime dependencies
124
+ --------------------
125
+
126
+ * Activerecord 3.x
127
+
128
+
129
+ Development dependencies
130
+ ---------------------
131
+
132
+ * Bundler for dependency management <http://github.com/carlhuda/bundler>
133
+ * Rspec for unit testing <http://github.com/rspec/rspec>
134
+ * Yard for documentation generation <http://github.com/lsegal/yard>
135
+
136
+
137
+ Rake tasks
138
+ ----------
139
+
140
+ bundle exec rake -T
141
+
142
+ rake build # Build dynabix-0.0.2.gem into the pkg directory
143
+ rake doc:clean # Remove generated documenation
144
+ rake doc:generate # Generate YARD Documentation
145
+ rake doc:undocumented # List undocumented objects
146
+ rake gemfiles # Generate .gemfiles via 'git ls-files'
147
+ rake install # Build and install dynabix-0.0.2.gem into system gems
148
+ rake release # Create tag v0.0.2 and build and push dynabix-0.0.2.gem to Rubygems
149
+ rake spec # Run RSpec
150
+
151
+ Copyright
152
+ ---------
153
+
154
+ Copyright (c) 2012 GearheadForHire, LLC. See [LICENSE](LICENSE) for details.
@@ -0,0 +1,72 @@
1
+ # encoding: utf-8
2
+
3
+ # Bundler is managing $LOAD_PATH, any gem needed by this Rakefile must be
4
+ # listed as a development dependency in the gemspec
5
+ require 'bundler/setup'
6
+ require 'bundler/gem_tasks'
7
+
8
+ require 'rspec/core/rake_task'
9
+ desc "Run RSpec"
10
+ RSpec::Core::RakeTask.new do |spec|
11
+ spec.pattern = 'spec/**/*_spec.rb'
12
+ end
13
+
14
+ task :default => :spec
15
+
16
+ namespace :doc do
17
+
18
+ doc_version = File.open(File.join(File.dirname(__FILE__), 'VERSION'), "r") { |f| f.read }
19
+ project_root = File.expand_path(File.dirname(__FILE__))
20
+ doc_destination = File.join(project_root, 'rdoc')
21
+
22
+ require 'yard'
23
+
24
+ YARD::Rake::YardocTask.new(:generate) do |yt|
25
+ yt.options = ['--output-dir', doc_destination,
26
+ '--title', "Dynabix #{doc_version} Documentation",
27
+ '--main', "README.markdown"
28
+ ]
29
+ end
30
+
31
+ desc "Remove generated documenation"
32
+ task :clean do
33
+ rm_r doc_destination if File.exists?(doc_destination)
34
+ end
35
+
36
+ desc "List undocumented objects"
37
+ task :undocumented do
38
+ system('yard stats --list-undoc')
39
+ end
40
+
41
+ end
42
+
43
+ # put the gemfiles task in the bundler dependency chain
44
+ task :build => [:gemfiles]
45
+ task :install => [:gemfiles]
46
+ task :release => [:gemfiles]
47
+
48
+ desc "Generate .gemfiles via 'git ls-files'"
49
+ task :gemfiles do
50
+ files = `git ls-files`
51
+
52
+ filename = File.join(File.dirname(__FILE__), '.gemfiles')
53
+ cached_files = nil
54
+ if File.exists?(filename)
55
+ puts ".gemfiles exists, reading..."
56
+ cached_files = File.open(filename, "rb") {|f| f.read}
57
+ end
58
+
59
+ if cached_files && cached_files.match("\r\n")
60
+ puts ".gemfiles using DOS EOL"
61
+ files.gsub!(/\n/, "\r\n")
62
+ end
63
+
64
+ if cached_files != files
65
+ puts ".gemfiles updating"
66
+ File.open(filename, 'wb') {|f| f.write(files)}
67
+ else
68
+ puts ".gemfiles update not required"
69
+ end
70
+
71
+ raise "unable to process .gemfiles" unless files
72
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.3.0
@@ -0,0 +1,61 @@
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ #
4
+ Gem::Specification.new do |s|
5
+
6
+ # avoid shelling out to run git every time the gemspec is evaluated
7
+ #
8
+ # @see spec/gemspec_spec.rb
9
+ #
10
+ gemfiles_cache = File.join(File.dirname(__FILE__), '.gemfiles')
11
+ if File.exists?(gemfiles_cache)
12
+ gemfiles = File.open(gemfiles_cache, "r") {|f| f.read}
13
+ # normalize EOL
14
+ gemfiles.gsub!(/\r\n/, "\n")
15
+ else
16
+ # .gemfiles missing, run 'rake gemfiles' to create it
17
+ # falling back to 'git ls-files'"
18
+ gemfiles = `git ls-files`
19
+ end
20
+
21
+ s.name = "dynabix"
22
+ s.version = File.open(File.join(File.dirname(__FILE__), 'VERSION'), "r") { |f| f.read }
23
+ s.platform = Gem::Platform::RUBY
24
+ s.authors = ["Robert Wahler"]
25
+ s.email = ["robert@gearheadforhire.com"]
26
+ s.homepage = "http://rubygems.org/gems/dynabix"
27
+ s.summary = "An ActiveRecord 3.x Ruby gem for attribute serialization"
28
+ s.description = "Dynabix dynamically creates read/write accessors on ActiveRecord models for storing attributes in a serialized Hash"
29
+
30
+ s.required_rubygems_version = ">= 1.3.6"
31
+ s.rubyforge_project = "dynabix"
32
+
33
+ s.add_dependency "activerecord", "~> 3.0"
34
+
35
+ s.add_development_dependency "bundler", ">= 1.0.14"
36
+ s.add_development_dependency "rspec", ">= 2.6.0"
37
+ s.add_development_dependency "aruba", "= 0.4.5"
38
+ s.add_development_dependency "rake", ">= 0.8.7"
39
+ s.add_development_dependency "sqlite3-ruby", ">= 0.8.7"
40
+
41
+ # doc generation
42
+ s.add_development_dependency "yard", ">= 0.7.4"
43
+ s.add_development_dependency "redcarpet", ">= 1.17.2"
44
+
45
+ # guard, watches files and runs specs and features
46
+ #
47
+ # @see Gemfile for platform specific dependencies
48
+ s.add_development_dependency "guard", "~> 1.0"
49
+ s.add_development_dependency "guard-rspec", "~> 0.6"
50
+
51
+ s.files = gemfiles.split("\n")
52
+ s.executables = gemfiles.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
53
+ s.require_paths = ["lib"]
54
+
55
+ s.rdoc_options = [
56
+ '--title', 'Dynabix Documentation',
57
+ '--main', 'README.markdown',
58
+ '--line-numbers',
59
+ '--inline-source'
60
+ ]
61
+ end
@@ -0,0 +1,27 @@
1
+ # require all files here
2
+ require 'rbconfig'
3
+ require 'dynabix/metadata'
4
+
5
+ # Master namespace
6
+ module Dynabix
7
+
8
+ # Contents of the VERSION file
9
+ #
10
+ # Example format: 0.0.1
11
+ #
12
+ # @return [String] the contents of the version file in #.#.# format
13
+ def self.version
14
+ version_info_file = File.join(File.dirname(__FILE__), *%w[.. VERSION])
15
+ File.open(version_info_file, "r") do |f|
16
+ f.read.strip
17
+ end
18
+ end
19
+
20
+ # Platform constants
21
+ unless defined?(Dynabix::WINDOWS)
22
+ WINDOWS = RbConfig::CONFIG['host_os'] =~ /mswin|mingw/i
23
+ CYGWIN = RbConfig::CONFIG['host_os'] =~ /cygwin/i
24
+ end
25
+
26
+ end
27
+
@@ -0,0 +1,147 @@
1
+ require 'active_record'
2
+
3
+ # An ActiveRecord 3.x Ruby gem for attribute serialization.
4
+ module Dynabix
5
+
6
+ # Extending ActiveRecord with dynamic accessors for serialization
7
+ module Metadata
8
+
9
+ # Set up the model for serialization to a HashWithIndifferentAccess.
10
+ #
11
+ # @example Using the default column name ":metadata", specify the attributes in a separate step
12
+ #
13
+ # class Thing < ActiveRecord::Base
14
+ # has_metadata
15
+ #
16
+ # # full accessors
17
+ # metadata_accessor :breakfast_food, :wheat_products, :needs_milk
18
+ #
19
+ # # read-only
20
+ # metadata_reader :friends_with_spoons
21
+ # end
22
+ #
23
+ # @example Specifying attributes for full attributes accessors in one step
24
+ #
25
+ # class Thing < ActiveRecord::Base
26
+ # has_metadata :metadata, :breakfast_food, :wheat_products, :needs_milk
27
+ # end
28
+ #
29
+ # @example Specifying multiple metadata serializers (Ruby 1.9 only)
30
+ #
31
+ # class Thing < ActiveRecord::Base
32
+ # has_metadata :cows
33
+ # has_metadata :chickens, :tasty, :feather_count
34
+ #
35
+ # # read-only
36
+ # cow_reader :likes_milk, :hates_eggs
37
+ #
38
+ # # write-only
39
+ # cow_writer :no_wheat_products
40
+ #
41
+ # # extra full accessors for chickens
42
+ # chicken_accessor :color, :likes_eggs
43
+ # end
44
+ #
45
+ # @param [Symbol] serializer, the symbolized name (:metadata) of the database text column used for serialization
46
+ # @param [Array<Symbol>] optional list of attribute names to add to the model as full accessors
47
+ #
48
+ # @return [void]
49
+ def has_metadata(serializer=:metadata, *attributes)
50
+ serialize(serializer, HashWithIndifferentAccess)
51
+
52
+ if RUBY_VERSION < '1.9'
53
+ raise "has_metadata serializer must be named ':metadata', this restriction is lifted in Ruby 1.9+" unless serializer == :metadata
54
+ else
55
+ # we can safely define additional accessors, Ruby 1.8 will only
56
+ # be able to use the statically defined :metadata_accessor
57
+ if serializer != :metadata
58
+
59
+ # define the class accessor
60
+ define_singleton_method "#{serializer}_accessor" do |*attrs|
61
+ attrs.each do |attr|
62
+ create_reader(serializer, attr)
63
+ create_writer(serializer, attr)
64
+ end
65
+ end
66
+
67
+ # define the class read accessor
68
+ define_singleton_method "#{serializer}_reader" do |*attrs|
69
+ attrs.each do |attr|
70
+ create_reader(serializer, attr)
71
+ end
72
+ end
73
+
74
+ # define the class write accessor
75
+ define_singleton_method "#{serializer}_writer" do |*attrs|
76
+ attrs.each do |attr|
77
+ create_writer(serializer, attr)
78
+ end
79
+ end
80
+
81
+ end
82
+ end
83
+
84
+ # Define each of the attributes for this serializer
85
+ attributes.each do |attr|
86
+ create_reader(serializer, attr)
87
+ create_writer(serializer, attr)
88
+ end
89
+ end
90
+
91
+ # Default read/write accessor, user defined accessors are available under Ruby 1.9+
92
+ #
93
+ # @param [Array<Symbol>] attributes
94
+ #
95
+ # @return [void]
96
+ def metadata_accessor(*attrs)
97
+ attrs.each do |attr|
98
+ create_reader(:metadata, attr)
99
+ create_writer(:metadata, attr)
100
+ end
101
+ end
102
+
103
+ # Default read accessor (getter), user defined accessors are available under Ruby 1.9+
104
+ #
105
+ # @param [Array<Symbol>] attributes
106
+ #
107
+ # @return [void]
108
+ def metadata_reader(*attrs)
109
+ attrs.each do |attr|
110
+ create_reader(:metadata, attr)
111
+ end
112
+ end
113
+
114
+ # Default write accessor (setter), user defined accessors are available under Ruby 1.9+
115
+ #
116
+ # @param [Array<Symbol>] attributes
117
+ #
118
+ # @return [void]
119
+ def metadata_writer(*attrs)
120
+ attrs.each do |attr|
121
+ create_writer(:metadata, attr)
122
+ end
123
+ end
124
+
125
+ private
126
+
127
+ def create_accessor(serializer, attr)
128
+ create_reader(serializer, attr)
129
+ create_writer(serializer, attr)
130
+ end
131
+
132
+ def create_reader(serializer, attr)
133
+ define_method("#{attr}".to_sym) do
134
+ self[serializer][attr.to_sym]
135
+ end
136
+ end
137
+
138
+ def create_writer(serializer, attr)
139
+ define_method("#{attr}=".to_sym) do |value|
140
+ self[serializer][attr.to_sym] = value
141
+ end
142
+ end
143
+
144
+ end
145
+ end
146
+
147
+ ActiveRecord::Base.extend Dynabix::Metadata
@@ -0,0 +1,25 @@
1
+ module Aruba
2
+ module Api
3
+
4
+ # @return full path to files in the aruba tmp folder
5
+ def fullpath(filename)
6
+ path = File.expand_path(File.join(current_dir, filename))
7
+ if path.match(/^\/cygdrive/)
8
+ # match /cygdrive/c/path/to and return c:\\path\\to
9
+ path = `cygpath -w #{path}`.chomp
10
+ elsif path.match(/.\:/)
11
+ # match c:/path/to and return c:\\path\\to
12
+ path = path.gsub(/\//, '\\')
13
+ end
14
+ path
15
+ end
16
+
17
+ # @return the contents of "filename" in the aruba tmp folder
18
+ def get_file_contents(filename)
19
+ in_current_dir do
20
+ IO.read(filename)
21
+ end
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dynabix do
4
+
5
+ before(:each) do
6
+ @filename = 'input.txt'
7
+ write_file(@filename, "the quick brown fox")
8
+ end
9
+
10
+ describe 'Aruba::API.current_dir' do
11
+
12
+ it "should return the current dir as 'tmp/aruba'" do
13
+ current_dir.should match(/^tmp\/aruba$/)
14
+ end
15
+ end
16
+
17
+ describe "aruba_helper fullpath('input.txt')" do
18
+
19
+ it "should return a valid expanded path to 'input.txt'" do
20
+ path = fullpath('input.txt')
21
+ path.should match(/tmp..*aruba/)
22
+ File.exists?(path).should == true
23
+ end
24
+ end
25
+
26
+ describe "aruba_helper get_file_contents('input.txt')" do
27
+
28
+ it "should return the contents of 'input.txt' as a String" do
29
+ get_file_contents('input.txt').should == 'the quick brown fox'
30
+ end
31
+ end
32
+
33
+ end
@@ -0,0 +1,84 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dynabix do
4
+
5
+ describe 'version' do
6
+
7
+ it "should return a string formatted '#.#.#'" do
8
+ Dynabix::version.should match(/(^[\d]+\.[\d]+\.[\d]+$)/)
9
+ end
10
+
11
+ end
12
+
13
+ # VIM autocmd to remove trailing whitespace
14
+ # autocmd BufWritePre * :%s/\s\+$//e
15
+ #
16
+ describe "code" do
17
+
18
+ before(:each) do
19
+ @gemfiles_filename = File.expand_path(File.dirname(__FILE__) + '/../../.gemfiles')
20
+ raise ".gemfiles not found. Please run 'rake gemfiles'" unless File.exists?(@gemfiles_filename)
21
+ @gemfiles = File.open(@gemfiles_filename, "rb") {|f| f.read}
22
+ @eol = @gemfiles.match("\r\n") ? "\r\n" : "\n"
23
+ end
24
+
25
+ def binary?(filename)
26
+ open filename do |f|
27
+ f.each_byte { |x|
28
+ x.nonzero? or return true
29
+ }
30
+ end
31
+ false
32
+ end
33
+
34
+ def check_for_tab_characters(filename)
35
+ failing_lines = []
36
+ File.readlines(filename).each_with_index do |line,number|
37
+ failing_lines << number + 1 if line =~ /\t/
38
+ end
39
+
40
+ unless failing_lines.empty?
41
+ "#{filename} has tab characters on lines #{failing_lines.join(', ')}"
42
+ end
43
+ end
44
+
45
+ def check_for_extra_spaces(filename)
46
+ failing_lines = []
47
+ File.readlines(filename).each_with_index do |line,number|
48
+ next if line =~ /^\s+#.*\s+#{@eol}$/
49
+ failing_lines << number + 1 if line =~ /\s+#{@eol}$/
50
+ end
51
+
52
+ unless failing_lines.empty?
53
+ "#{filename} has spaces on the EOL on lines #{failing_lines.join(', ')}"
54
+ end
55
+ end
56
+
57
+ RSpec::Matchers.define :be_well_formed do
58
+ failure_message_for_should do |actual|
59
+ actual.join("\n")
60
+ end
61
+
62
+ match do |actual|
63
+ actual.empty?
64
+ end
65
+ end
66
+
67
+ it "has no malformed whitespace" do
68
+ error_messages = []
69
+ @gemfiles.split(@eol).each do |filename|
70
+ filename = File.expand_path(File.join(File.dirname(__FILE__), ["..", "..", filename]))
71
+ unless File.exists?(filename)
72
+ puts "WARNING: .gemfiles out-of-date, #{filename} not found. Edit .gemfiles or run 'rake gemfiles' after committing changes."
73
+ next
74
+ end
75
+ next if filename =~ /\.gitmodules/
76
+ next if binary?(filename)
77
+ error_messages << check_for_tab_characters(filename)
78
+ error_messages << check_for_extra_spaces(filename)
79
+ end
80
+ error_messages.compact.should be_well_formed
81
+ end
82
+
83
+ end
84
+ end
@@ -0,0 +1,68 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dynabix do
4
+
5
+ def load_gemspec
6
+ filename = File.expand_path('../../../dynabix.gemspec', __FILE__)
7
+ eval(File.read(filename), nil, filename)
8
+ end
9
+
10
+ describe 'gemspec' do
11
+
12
+ it "should return the gem VERSION" do
13
+ @gemspec = load_gemspec
14
+ Dynabix::version.should_not be_nil
15
+ @gemspec.version.to_s.should == Dynabix::version
16
+ end
17
+
18
+ describe 'files' do
19
+
20
+ it "should return 'files' array" do
21
+ @gemspec = load_gemspec
22
+ @gemspec.files.is_a?(Array).should == true
23
+ @gemspec.files.include?('VERSION').should == true
24
+ end
25
+ it "should return 'executables' array" do
26
+ @gemspec = load_gemspec
27
+ @gemspec.executables.is_a?(Array).should == true
28
+ end
29
+
30
+ describe 'without .gemfiles cache' do
31
+ before(:each) do
32
+ File.stub!('exists?').and_return false
33
+ @gemspec = load_gemspec
34
+ end
35
+
36
+ it "should return 'files' from using 'git ls-files" do
37
+ File.exists?(File.expand_path('../../../.gemfiles', __FILE__)).should == false
38
+ @gemspec.files.is_a?(Array).should == true
39
+ @gemspec.files.include?('VERSION').should == true
40
+ end
41
+ it "should return 'executables' from 'git ls-files" do
42
+ File.exists?(File.expand_path('../../../.gemfiles', __FILE__)).should == false
43
+ @gemspec.executables.is_a?(Array).should == true
44
+ end
45
+ end
46
+
47
+ describe 'without git binary' do
48
+
49
+ before(:each) do
50
+ stub!(:system).and_return false
51
+ @gemspec = load_gemspec
52
+ end
53
+
54
+ it "should return 'files' from cache" do
55
+ system('git --version').should == false
56
+ @gemspec.files.is_a?(Array).should == true
57
+ @gemspec.files.include?('VERSION').should == true
58
+ end
59
+ it "should return 'executables' from cache" do
60
+ system('git --version').should == false
61
+ @gemspec.executables.is_a?(Array).should == true
62
+ end
63
+
64
+ end
65
+ end
66
+
67
+ end
68
+ end
@@ -0,0 +1,137 @@
1
+ require 'spec_helper'
2
+
3
+ class Thing < ActiveRecord::Base
4
+ has_metadata
5
+
6
+ metadata_accessor :rv_doors, :rv_windows
7
+ end
8
+
9
+ describe Dynabix::Metadata do
10
+
11
+ describe "has_metadata" do
12
+
13
+ it "should be a class method" do
14
+ defined?(Thing.has_metadata).should be_true
15
+ defined?(Thing.create_accessor).should be_false
16
+ end
17
+
18
+ end
19
+
20
+ describe "creating a serializer" do
21
+
22
+ context "has_metadata with no params, Ruby 1.8+" do
23
+
24
+ it "should create a default instance serializer accessor called 'metadata'" do
25
+ defined?(Thing.metadata).should be_false
26
+ thing = Thing.new
27
+ thing.should be_valid
28
+ defined?(thing.metadata).should be_true
29
+ thing.metadata.should == {}
30
+ end
31
+
32
+ it "should create a default class level accessor called 'metadata_accessor'" do
33
+ defined?(Thing.metadata_accessor).should be_true
34
+ defined?(Thing.rv_windows).should be_false
35
+
36
+ thing = Thing.new
37
+ defined?(thing.rv_windows).should be_true
38
+ thing.metadata[:rv_windows].should be_nil
39
+ thing.metadata[:rv_windows] = 1
40
+ thing.metadata[:rv_windows].should == 1
41
+ thing.rv_windows = 2
42
+ thing.rv_windows.should == 2
43
+ end
44
+
45
+ end
46
+
47
+ context "has_metadata with attribute params, Ruby 1.8+" do
48
+
49
+ class Foo < ActiveRecord::Base
50
+ has_metadata :metadata, :bar1, :bar2
51
+
52
+ metadata_reader :frog
53
+ metadata_writer :duck
54
+ end
55
+
56
+ it "should create a default instance serializer accessor called 'metadata'" do
57
+ foo = Foo.new
58
+ foo.metadata.should == {}
59
+ end
60
+
61
+ it "should create a default class level accessor called 'metadata_accessor'" do
62
+ foo = Foo.new
63
+ defined?(foo.bar1).should be_true
64
+ defined?(foo.bar2).should be_true
65
+ foo.metadata[:bar1].should be_nil
66
+ foo.metadata[:bar1] = 1
67
+ foo.metadata[:bar1].should == 1
68
+ foo.bar1 = 2
69
+ foo.bar1.should == 2
70
+ end
71
+
72
+ it "should create a default class level write accessor called 'metadata_writer'" do
73
+ foo = Foo.new
74
+ foo.duck = 2
75
+ foo.metadata[:duck].should == 2
76
+ lambda { foo.duck }.should raise_exception(NoMethodError)
77
+ end
78
+
79
+ it "should create a default class level read accessor called 'metadata_reader'" do
80
+ foo = Foo.new
81
+ foo.metadata[:frog] = 4
82
+ foo.frog.should == 4
83
+ lambda { foo.frog = 5 }.should raise_exception(NoMethodError)
84
+ end
85
+ end
86
+
87
+ unless RUBY_VERSION < '1.9'
88
+
89
+ class Bar < ActiveRecord::Base
90
+ has_metadata :bardata
91
+
92
+ bardata_accessor :foo
93
+ bardata_reader :frog
94
+ bardata_writer :duck
95
+ end
96
+
97
+ context "has_metadata with user defined name of metadata database field 'bardata', Ruby 1.9+" do
98
+
99
+ it "should create a default instance serializer accessor called 'bardata'" do
100
+ defined?(Bar.bardata).should be_false
101
+ thing = Bar.new
102
+ thing.should be_valid
103
+ defined?(thing.bardata).should be_true
104
+ thing.bardata.should == {}
105
+ end
106
+
107
+ it "should create a default class level accessor called 'bardata_accessor'" do
108
+ defined?(Bar.bardata_accessor).should be_true
109
+ defined?(Bar.foo).should be_false
110
+
111
+ thing = Bar.new
112
+ defined?(thing.foo).should be_true
113
+ thing.bardata[:foo].should be_nil
114
+ thing.bardata[:foo] = 1
115
+ thing.bardata[:foo].should == 1
116
+ thing.foo = 2
117
+ thing.foo.should == 2
118
+ end
119
+
120
+ it "should create a default class level write accessor called 'bardata_writer'" do
121
+ bar = Bar.new
122
+ bar.duck = 2
123
+ bar.bardata[:duck].should == 2
124
+ lambda { bar.duck }.should raise_exception(NoMethodError)
125
+ end
126
+
127
+ it "should create a default class level read accessor called 'bardata_reader'" do
128
+ bar = Bar.new
129
+ bar.bardata[:frog] = 4
130
+ bar.frog.should == 4
131
+ lambda { bar.frog = 5 }.should raise_exception(NoMethodError)
132
+ end
133
+ end
134
+ end
135
+
136
+ end
137
+ end
@@ -0,0 +1,27 @@
1
+ ActiveRecord::Schema.define(:version => 0) do
2
+
3
+ create_table :things, :force => true do |t|
4
+ t.string :description
5
+ t.text :notes
6
+ t.text :metadata
7
+
8
+ t.timestamps
9
+ end
10
+
11
+ create_table :bars, :force => true do |t|
12
+ t.string :description
13
+ t.text :notes
14
+ t.text :bardata
15
+
16
+ t.timestamps
17
+ end
18
+
19
+ create_table :foos, :force => true do |t|
20
+ t.string :description
21
+ t.text :notes
22
+ t.text :metadata
23
+
24
+ t.timestamps
25
+ end
26
+
27
+ end
@@ -0,0 +1,16 @@
1
+ require 'dynabix'
2
+ require 'rspec/core'
3
+ require 'aruba/api'
4
+ require 'aruba_helper'
5
+ require 'active_record'
6
+
7
+ ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
8
+ ActiveRecord::Migration.verbose = false
9
+ load "schema.rb"
10
+
11
+ RSpec.configure do |config|
12
+ config.include Aruba::Api
13
+ config.filter_run :focus => true
14
+ config.run_all_when_everything_filtered = true
15
+ config.treat_symbols_as_metadata_keys_with_true_values = true
16
+ end
metadata ADDED
@@ -0,0 +1,239 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dynabix
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Robert Wahler
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-04 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: '3.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: '3.0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 1.0.14
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: 1.0.14
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 2.6.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: 2.6.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: aruba
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - '='
68
+ - !ruby/object:Gem::Version
69
+ version: 0.4.5
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - '='
76
+ - !ruby/object:Gem::Version
77
+ version: 0.4.5
78
+ - !ruby/object:Gem::Dependency
79
+ name: rake
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: 0.8.7
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: 0.8.7
94
+ - !ruby/object:Gem::Dependency
95
+ name: sqlite3-ruby
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: 0.8.7
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: 0.8.7
110
+ - !ruby/object:Gem::Dependency
111
+ name: yard
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: 0.7.4
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: 0.7.4
126
+ - !ruby/object:Gem::Dependency
127
+ name: redcarpet
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: 1.17.2
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: 1.17.2
142
+ - !ruby/object:Gem::Dependency
143
+ name: guard
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ~>
148
+ - !ruby/object:Gem::Version
149
+ version: '1.0'
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ~>
156
+ - !ruby/object:Gem::Version
157
+ version: '1.0'
158
+ - !ruby/object:Gem::Dependency
159
+ name: guard-rspec
160
+ requirement: !ruby/object:Gem::Requirement
161
+ none: false
162
+ requirements:
163
+ - - ~>
164
+ - !ruby/object:Gem::Version
165
+ version: '0.6'
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ~>
172
+ - !ruby/object:Gem::Version
173
+ version: '0.6'
174
+ description: Dynabix dynamically creates read/write accessors on ActiveRecord models
175
+ for storing attributes in a serialized Hash
176
+ email:
177
+ - robert@gearheadforhire.com
178
+ executables: []
179
+ extensions: []
180
+ extra_rdoc_files: []
181
+ files:
182
+ - .gemfiles
183
+ - .gitattributes
184
+ - .gitignore
185
+ - .rspec
186
+ - .yardopts
187
+ - Gemfile
188
+ - Gemfile.lock
189
+ - Guardfile
190
+ - HISTORY.markdown
191
+ - LICENSE
192
+ - README.markdown
193
+ - Rakefile
194
+ - VERSION
195
+ - dynabix.gemspec
196
+ - lib/dynabix.rb
197
+ - lib/dynabix/metadata.rb
198
+ - spec/aruba_helper.rb
199
+ - spec/basic_gem/aruba_helper_spec.rb
200
+ - spec/basic_gem/basic_gem_spec.rb
201
+ - spec/basic_gem/gemspec_spec.rb
202
+ - spec/dynabix/metadata_spec.rb
203
+ - spec/schema.rb
204
+ - spec/spec_helper.rb
205
+ homepage: http://rubygems.org/gems/dynabix
206
+ licenses: []
207
+ post_install_message:
208
+ rdoc_options:
209
+ - --title
210
+ - Dynabix Documentation
211
+ - --main
212
+ - README.markdown
213
+ - --line-numbers
214
+ - --inline-source
215
+ require_paths:
216
+ - lib
217
+ required_ruby_version: !ruby/object:Gem::Requirement
218
+ none: false
219
+ requirements:
220
+ - - ! '>='
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
223
+ segments:
224
+ - 0
225
+ hash: 575564662145783656
226
+ required_rubygems_version: !ruby/object:Gem::Requirement
227
+ none: false
228
+ requirements:
229
+ - - ! '>='
230
+ - !ruby/object:Gem::Version
231
+ version: 1.3.6
232
+ requirements: []
233
+ rubyforge_project: dynabix
234
+ rubygems_version: 1.8.21
235
+ signing_key:
236
+ specification_version: 3
237
+ summary: An ActiveRecord 3.x Ruby gem for attribute serialization
238
+ test_files: []
239
+ has_rdoc: