not_activerecord 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d78d042bfed45a2c68655478bf12b39d1c60fd0a
4
+ data.tar.gz: cd058d174d444213e7630c2de49581f087d4f17c
5
+ SHA512:
6
+ metadata.gz: c15e27641e5fae9e52bf8822730162ec7e591e971938bf87a06815f8f726be5ae011bac896437cfce248c3f4ac38a22d9dcf677a01d97ec787b69b18dddc67b0
7
+ data.tar.gz: f16b2222e58ef8f979f592f2128c4bb14307d669a79a4b1cf9309ef2c71638c085a1731efe2df4fd0fee8464b65ed39b8ded1a700c659851456bb1b239eeb86b
@@ -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 not_activerecord.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Robert Pankowecki
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.
@@ -0,0 +1,42 @@
1
+ # NotActiveRecord
2
+
3
+ Clearly express the boundaries of your AR objects for other programmers.
4
+
5
+ Just because your object has `user_id` does not mean it needs to
6
+ know anything about `user` at all.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's `Gemfile`:
11
+
12
+ gem 'not_activerecord'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install not_activerecord
21
+
22
+ ## Usage
23
+
24
+ class LessonProgressLevel < ActiveRecord::Base
25
+ extend NotActiveRecord
26
+
27
+ does_not_belong_to :student
28
+ does_not_belong_to :lesson
29
+ does_not_belong_to :training
30
+ end
31
+
32
+
33
+ class MyClass < ActiveRecord::Base
34
+ extend NotActiveRecord
35
+
36
+ does_not_belong_to :user
37
+ does_not_have_many :users
38
+ does_not_have_one :user
39
+ does_not_have_and_belong_to_many :users
40
+ end
41
+
42
+ MyClass.new.user # gives you nice and warming exception :)
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,52 @@
1
+ require "not_activerecord/version"
2
+
3
+ module NotActiveRecord
4
+ Error = Class.new(StandardError)
5
+
6
+ %w(
7
+ does_not_belong_to
8
+ does_not_have_many
9
+ does_not_have_one
10
+ does_not_have_and_belong_to_many
11
+
12
+ does_not_have_or_belong_to_many
13
+
14
+ does_not_has_many
15
+ does_not_has_one
16
+ does_not_has_and_belongs_to_many
17
+ ).each do |does_not|
18
+ define_method(does_not) do |*args|
19
+ args.each do |method_name|
20
+ define_method(method_name) do
21
+ raise Error.new("You tried to called method ##{method_name} but one of
22
+ the developers decided that you should not cross this boundary of your
23
+ application/database. This object behavior is supposed to work without calling
24
+ requested associated object. You should also be able to instantiate and test it
25
+ properly without calling ##{method_name}. If you don't agree, go ahead and discuss
26
+ this issue with your coworker. Maybe you are trying to implement something that is
27
+ a responsibility of higher level layer that has access to :#{method_name} and this
28
+ (#{inspect}) object at the same time.
29
+
30
+ TLDR: Someone went through a lot to tell you that your probably should not be doing
31
+ what you are doing. Respect it :)
32
+
33
+ Example:
34
+
35
+ class Order < ActiveRecord::Base
36
+ has_many :order_lines
37
+ end
38
+
39
+ class OrderLine < ActiveRecord::Base
40
+ does_not_belong_to :order
41
+ end
42
+
43
+ Order is an Aggregate (http://martinfowler.com/bliki/DDD_Aggregate.html)
44
+ and OrderLine should never call #order or know which order it belongs to
45
+ (even though it has order_id for database reasons). If your usecase
46
+ requires the knowledge of :order_line and :order at the same time, write a
47
+ method for it in Order class instead of writing it in OrderLine.")
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,3 @@
1
+ module NotActiveRecord
2
+ VERSION = "1.0.0"
3
+ end
@@ -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 'not_activerecord/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "not_activerecord"
8
+ spec.version = NotActiveRecord::VERSION
9
+ spec.authors = ["Robert Pankowecki"]
10
+ spec.email = ["robert.pankowecki@gmail.com"]
11
+ spec.description = %q{Gem which helps you in not providing associations}
12
+ spec.summary = %q{does_not}
13
+ spec.homepage = ""
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.3"
22
+ spec.add_development_dependency "rake"
23
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: not_activerecord
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Robert Pankowecki
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-26 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
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: Gem which helps you in not providing associations
42
+ email:
43
+ - robert.pankowecki@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
+ - lib/not_activerecord.rb
54
+ - lib/not_activerecord/version.rb
55
+ - not_activerecord.gemspec
56
+ homepage: ''
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.0.14
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: does_not
80
+ test_files: []