lazy_record 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -3
- data/lib/lazy_record/associations.rb +2 -2
- data/lib/lazy_record/attributes.rb +4 -3
- data/lib/lazy_record/collections.rb +2 -3
- data/lib/lazy_record/version.rb +1 -1
- metadata +1 -60
- data/.gitignore +0 -12
- data/.rspec +0 -2
- data/.rubocop.yml +0 -8
- data/Gemfile +0 -6
- data/Rakefile +0 -8
- data/bin/console +0 -15
- data/bin/setup +0 -8
- data/config/environment.rb +0 -12
- data/lazy_record.gemspec +0 -41
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b7d8a49d7b115279037a9fecb09b1250c9629cc9
|
4
|
+
data.tar.gz: 840ac59fc2e9c603aafb2e054adf257a4bbbdc07
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b8825a2232f7934611ee3bee0b2b09c579cc18674234e951e8fcf91e79c65810e3589f0daa1928f7d30c249cc6a48252f66c10c5801d816baa5621f6b839ece
|
7
|
+
data.tar.gz: 515522ec1f52bf4041b7f6421547dd756ffde7820e9845a685c557e2e25a79311cb61705e0529e171996fa0c7991b35fadf40a01346d14d9aed0dc6eea1399ca
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# LazyRecord
|
2
2
|
[![Code Climate](https://codeclimate.com/github/msimonborg/lazy_record/badges/gpa.svg)](https://codeclimate.com/github/msimonborg/lazy_record)
|
3
|
+
[![Build Status](https://travis-ci.org/msimonborg/lazy_record.svg?branch=master)](https://travis-ci.org/msimonborg/lazy_record)
|
4
|
+
[![Coverage Status](https://coveralls.io/repos/github/msimonborg/lazy_record/badge.svg?branch=master)](https://coveralls.io/github/msimonborg/lazy_record?branch=master)
|
3
5
|
|
4
6
|
LazyRecord writes a bunch of boilerplate code for your POROs, similarly to what you'd expect ActiveRecord to do for your database-backed objects. This project is an attempt to understand and explore dynamic programming techniques in Ruby, and demystify some of the Rails magic. Maybe someone will find it useful.
|
5
7
|
|
@@ -51,7 +53,7 @@ Use `attr_accessor` like you would use normally, and you'll get hash syntax in y
|
|
51
53
|
class Thing < LazyRecord::Base
|
52
54
|
attr_accessor :stuff, :junk
|
53
55
|
attr_reader :hmm
|
54
|
-
|
56
|
+
|
55
57
|
def something
|
56
58
|
@something ||= 'something'
|
57
59
|
end
|
@@ -69,10 +71,10 @@ If you want to define private or protected `attr_accessor`s or `attr_reader`s, t
|
|
69
71
|
class Thing < LazyRecord::Base
|
70
72
|
attr_accessor :stuff, :junk
|
71
73
|
private :junk, :junk= # passing the setter and getter method names as arguments to Module.private/Module.protected will work
|
72
|
-
|
74
|
+
|
73
75
|
private_attr_accessor :hmm # this also works
|
74
76
|
protected_attr_accessor :huh # this works too
|
75
|
-
|
77
|
+
|
76
78
|
private
|
77
79
|
attr_accessor :what # declaring the methods after calling the private method will not work, and the methods will be public and visible.
|
78
80
|
# this is a bug due to the custom implementation of .attr_*, and if anyone can find a fix please submit it!
|
@@ -41,8 +41,8 @@ module LazyRecord
|
|
41
41
|
|
42
42
|
def define_association_setter(assoc)
|
43
43
|
model = find_scoped_association_class(assoc)
|
44
|
-
define_method("#{assoc}=") do |
|
45
|
-
return instance_variable_set("@#{assoc}",
|
44
|
+
define_method("#{assoc}=") do |val|
|
45
|
+
return instance_variable_set("@#{assoc}", val) if val.is_a? model.call
|
46
46
|
raise ArgumentError, "Argument must be a #{model.call}"
|
47
47
|
end
|
48
48
|
end
|
@@ -8,9 +8,10 @@ module LazyRecord
|
|
8
8
|
# #initialize just call super.
|
9
9
|
module Attributes
|
10
10
|
def lr_attr_accessor(*names) # Will be removed in version 1.0.0
|
11
|
-
puts 'Using `.lr_attr_accessor` is deprecated. Use the standard
|
12
|
-
' methods instead. You will get the same results, plus
|
13
|
-
' recognized by rdoc. `.lr_attr_accessor` will
|
11
|
+
puts 'Using `.lr_attr_accessor` is deprecated. Use the standard '\
|
12
|
+
'`.attr_*` methods instead. You will get the same results, plus '\
|
13
|
+
'the methods will be recognized by rdoc. `.lr_attr_accessor` will'\
|
14
|
+
' be removed in version 1.0.0'
|
14
15
|
attr_accessor(*names)
|
15
16
|
end
|
16
17
|
|
@@ -23,9 +23,8 @@ module LazyRecord
|
|
23
23
|
def define_collection_setter(collection)
|
24
24
|
model = find_scoped_collection_class(collection)
|
25
25
|
define_method("#{collection}=") do |coll|
|
26
|
-
coll = Relation.new(model: model, array: coll)
|
27
|
-
|
28
|
-
raise ArgumentError, "Argument must be a collection of #{collection}"
|
26
|
+
coll = Relation.new(model: model, array: coll)
|
27
|
+
instance_variable_set("@#{collection}", coll)
|
29
28
|
end
|
30
29
|
end
|
31
30
|
|
data/lib/lazy_record/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lazy_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- M. Simon Borg
|
@@ -44,40 +44,6 @@ dependencies:
|
|
44
44
|
- - ">="
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: 1.0.3
|
47
|
-
- !ruby/object:Gem::Dependency
|
48
|
-
name: pry
|
49
|
-
requirement: !ruby/object:Gem::Requirement
|
50
|
-
requirements:
|
51
|
-
- - "~>"
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: 0.10.0
|
54
|
-
type: :development
|
55
|
-
prerelease: false
|
56
|
-
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
requirements:
|
58
|
-
- - "~>"
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
version: 0.10.0
|
61
|
-
- !ruby/object:Gem::Dependency
|
62
|
-
name: rspec
|
63
|
-
requirement: !ruby/object:Gem::Requirement
|
64
|
-
requirements:
|
65
|
-
- - "~>"
|
66
|
-
- !ruby/object:Gem::Version
|
67
|
-
version: '3.5'
|
68
|
-
- - ">="
|
69
|
-
- !ruby/object:Gem::Version
|
70
|
-
version: 3.5.0
|
71
|
-
type: :development
|
72
|
-
prerelease: false
|
73
|
-
version_requirements: !ruby/object:Gem::Requirement
|
74
|
-
requirements:
|
75
|
-
- - "~>"
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
version: '3.5'
|
78
|
-
- - ">="
|
79
|
-
- !ruby/object:Gem::Version
|
80
|
-
version: 3.5.0
|
81
47
|
- !ruby/object:Gem::Dependency
|
82
48
|
name: bundler
|
83
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -92,20 +58,6 @@ dependencies:
|
|
92
58
|
- - "~>"
|
93
59
|
- !ruby/object:Gem::Version
|
94
60
|
version: '1.14'
|
95
|
-
- !ruby/object:Gem::Dependency
|
96
|
-
name: rake
|
97
|
-
requirement: !ruby/object:Gem::Requirement
|
98
|
-
requirements:
|
99
|
-
- - "~>"
|
100
|
-
- !ruby/object:Gem::Version
|
101
|
-
version: '10.0'
|
102
|
-
type: :development
|
103
|
-
prerelease: false
|
104
|
-
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
requirements:
|
106
|
-
- - "~>"
|
107
|
-
- !ruby/object:Gem::Version
|
108
|
-
version: '10.0'
|
109
61
|
description: Add some convenience macros for your POROs that cut down on boilerplate
|
110
62
|
code. Method definition macros, more powerful attr_accessors, and easy associations
|
111
63
|
between in-memory objects. Mocks the ActiveRecord API to make it feel comfortable
|
@@ -117,19 +69,8 @@ executables: []
|
|
117
69
|
extensions: []
|
118
70
|
extra_rdoc_files: []
|
119
71
|
files:
|
120
|
-
- ".gitignore"
|
121
|
-
- ".rspec"
|
122
|
-
- ".rubocop.yml"
|
123
|
-
- ".ruby-gemset"
|
124
|
-
- ".ruby-version"
|
125
|
-
- Gemfile
|
126
72
|
- LICENSE.txt
|
127
73
|
- README.md
|
128
|
-
- Rakefile
|
129
|
-
- bin/console
|
130
|
-
- bin/setup
|
131
|
-
- config/environment.rb
|
132
|
-
- lazy_record.gemspec
|
133
74
|
- lib/lazy_record.rb
|
134
75
|
- lib/lazy_record/associations.rb
|
135
76
|
- lib/lazy_record/attributes.rb
|
data/.gitignore
DELETED
data/.rspec
DELETED
data/.rubocop.yml
DELETED
data/Gemfile
DELETED
data/Rakefile
DELETED
data/bin/console
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
require 'bundler/setup'
|
5
|
-
require_relative '../config/environment'
|
6
|
-
|
7
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
-
# with your gem easier. You can also use a different console, if you like.
|
9
|
-
|
10
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
-
require 'pry'
|
12
|
-
Pry.start
|
13
|
-
|
14
|
-
# require 'irb'
|
15
|
-
# IRB.start(__FILE__)
|
data/bin/setup
DELETED
data/config/environment.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
example = File.expand_path('../../example', __FILE__)
|
4
|
-
$LOAD_PATH.unshift(example) unless $LOAD_PATH.include?(example)
|
5
|
-
lib = File.expand_path('../lib', __FILE__)
|
6
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
7
|
-
|
8
|
-
require 'lazy_record'
|
9
|
-
autoload :Cat, 'cat'
|
10
|
-
autoload :Dog, 'dog'
|
11
|
-
autoload :Friend, 'friend'
|
12
|
-
autoload :Person, 'person'
|
data/lazy_record.gemspec
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
lib = File.expand_path('../lib', __FILE__)
|
5
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
6
|
-
require 'lazy_record/version'
|
7
|
-
|
8
|
-
Gem::Specification.new do |spec|
|
9
|
-
spec.name = 'lazy_record'
|
10
|
-
spec.version = LazyRecord::VERSION
|
11
|
-
spec.authors = ['M. Simon Borg']
|
12
|
-
spec.email = ['msimonborg@gmail.com']
|
13
|
-
|
14
|
-
spec.summary = 'Some ActiveRecord magic for your table-less POROs. WIP.'
|
15
|
-
spec.description = 'Add some convenience macros for your POROs that cut down on boilerplate code. Method definition macros, more powerful attr_accessors, and easy associations between in-memory objects. Mocks the ActiveRecord API to make it feel comfortable and intuitive for Rails developers. The main intent of this project is to explore dynamic programming in Ruby. Maybe someone will find it useful. WIP.'
|
16
|
-
spec.homepage = 'https://www.github.com/msimonborg/lazy_record'
|
17
|
-
spec.license = 'MIT'
|
18
|
-
spec.required_ruby_version = '>= 2.3.0'
|
19
|
-
|
20
|
-
if spec.respond_to?(:metadata)
|
21
|
-
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
22
|
-
else
|
23
|
-
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
24
|
-
'public gem pushes.'
|
25
|
-
end
|
26
|
-
|
27
|
-
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
28
|
-
f.match(%r{^(test|spec|features|example)/})
|
29
|
-
end
|
30
|
-
spec.bindir = 'exe'
|
31
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
32
|
-
spec.require_paths = ['lib']
|
33
|
-
|
34
|
-
spec.add_dependency 'activesupport', '~> 5.0'
|
35
|
-
spec.add_dependency 'scoped_attr_accessor', '~> 1.0', '>= 1.0.3'
|
36
|
-
|
37
|
-
spec.add_development_dependency 'pry', '~> 0.10.0'
|
38
|
-
spec.add_development_dependency 'rspec', '~> 3.5', '>= 3.5.0'
|
39
|
-
spec.add_development_dependency 'bundler', '~> 1.14'
|
40
|
-
spec.add_development_dependency 'rake', '~> 10.0'
|
41
|
-
end
|