ar_properties 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.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 YOURNAME
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.
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = ArProperties
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'ArProperties'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+
24
+
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
28
+ require 'rake/testtask'
29
+
30
+ Rake::TestTask.new(:test) do |t|
31
+ t.libs << 'lib'
32
+ t.libs << 'test'
33
+ t.pattern = 'test/**/*_test.rb'
34
+ t.verbose = false
35
+ end
36
+
37
+
38
+ task :default => :test
@@ -0,0 +1,36 @@
1
+ require 'active_record'
2
+ require 'ar_properties/property'
3
+ require 'ar_properties/version'
4
+
5
+ module ActiveRecord
6
+ module Properties
7
+ extend ActiveSupport::Concern
8
+
9
+ def self.activate!
10
+ ActiveRecord::Base.send(:include, self)
11
+ end
12
+
13
+ class PropertyError < StandardError
14
+ end
15
+
16
+ module ClassMethods
17
+ def columns
18
+ @columns ||= properties.map(&:to_column)
19
+ end
20
+
21
+ def properties
22
+ @properties ||= []
23
+ end
24
+
25
+ def property(*args)
26
+ Property.new(connection, *args).tap {|x| properties << x }
27
+ end
28
+
29
+ def timestamps(suffix=:at)
30
+ raise PropertyError, "unknown timestamps suffix: #{suffix.inspect}" unless %w[at on].include?(suffix.to_s)
31
+ property :"created_#{suffix}", :time
32
+ property :"updated_#{suffix}", :time
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,39 @@
1
+ module ActiveRecord
2
+ module Properties
3
+ class Property
4
+ def initialize(base, name, type, options={})
5
+ @name, @type, @base = name, type, base
6
+
7
+ native = base.native_database_types
8
+ @limit = options.fetch(:limit) do
9
+ native[type][:limit] if native[type].is_a?(Hash)
10
+ end
11
+
12
+ @precision = options[:precision]
13
+ @scale = options[:scale]
14
+ @default = options[:default]
15
+ @null = options[:null]
16
+
17
+ unless base.native_database_types.keys.include?(type.try(:to_sym))
18
+ raise PropertyError, "unknown type: #{type.inspect}"
19
+ end
20
+ end
21
+
22
+ attr_reader :base, :name, :type, :precision, :scale, :default, :null, :limit
23
+
24
+ def to_column
25
+ ConnectionAdapters::Column.new(name.to_s, default.try(:to_s), sql_type, null).tap do |column|
26
+ column.primary = primary?
27
+ end
28
+ end
29
+
30
+ def sql_type
31
+ base.type_to_sql(type.to_sym, limit, precision, scale)
32
+ end
33
+
34
+ def primary?
35
+ type.to_sym == :primary_key
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,5 @@
1
+ module ActiveRecord
2
+ module Properties
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :ar_properties do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ar_properties
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Andy Delcambre
9
+ - Larry Diehl
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2012-05-02 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activerecord
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: 3.2.3
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ version: 3.2.3
31
+ - !ruby/object:Gem::Dependency
32
+ name: sqlite3
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ type: :development
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ description: ! "\n This gem turns off schema introspection in favor of declaring
48
+ properties in your models.\n Instead, you declare the properties in the model
49
+ itself and ActiveRecord will only\n read and write the columns that you specify.\n
50
+ \ "
51
+ email:
52
+ - engineering@engineyard.com
53
+ executables: []
54
+ extensions: []
55
+ extra_rdoc_files: []
56
+ files:
57
+ - lib/ar_properties/property.rb
58
+ - lib/ar_properties/version.rb
59
+ - lib/ar_properties.rb
60
+ - lib/tasks/ar_properties_tasks.rake
61
+ - MIT-LICENSE
62
+ - Rakefile
63
+ - README.rdoc
64
+ homepage: http://github.com/engineyard/ar_properties
65
+ licenses: []
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubyforge_project:
84
+ rubygems_version: 1.8.24
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: Explicit properties for ActiveRecord
88
+ test_files: []