identitee 0.4.0 → 0.5.0
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.
- checksums.yaml +6 -14
- data/.coveralls.yml +1 -0
- data/Gemfile +1 -0
- data/README.md +5 -4
- data/ROADMAP.md +4 -2
- data/lib/identitee/default_path_builder.rb +44 -0
- data/lib/identitee/identifiables.rb +4 -0
- data/lib/identitee/identify.rb +5 -1
- data/lib/identitee/version.rb +1 -1
- data/lib/identitee.rb +4 -1
- data/spec/acceptance/alias_find_acceptance_spec.rb +25 -0
- data/spec/acceptance/default_directory_acceptance_spec.rb +27 -0
- data/spec/acceptance/default_directory_set_tests/default_directory_test.rb +3 -0
- data/spec/acceptance/force_all_loading_acceptance_spec.rb +5 -16
- data/spec/acceptance/lazy_loading_acceptance_spec.rb +2 -2
- data/spec/acceptance/loading_all_tests/test1.rb +2 -0
- data/spec/acceptance/loading_all_tests/test2.rb +2 -0
- data/spec/integration/loader_integration_spec.rb +1 -1
- data/spec/lib/identitee/identifiables_spec.rb +8 -1
- data/spec/lib/identitee/identify_spec.rb +12 -2
- data/spec/lib/identitee/loader_spec.rb +2 -6
- data/spec/spec_helper.rb +5 -6
- metadata +17 -5
checksums.yaml
CHANGED
|
@@ -1,15 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
metadata.gz: !binary |-
|
|
9
|
-
M2M1MTEwNDk0MzkxNjE2M2I0MWJiZWQ2MzExMjczOTM1OGUxNmU4NTUxMDU4
|
|
10
|
-
NzNkMWQ5MmIyZGM1NzZkODc5YWFhZTVkZTQyYTAyMWJiN2U5MjgwNWMzNzc4
|
|
11
|
-
YmUxYmIyNGJhZDY2ODM0ZTcwOGYxNDFlNzg2MGFmZDJkNmEyMzU=
|
|
12
|
-
data.tar.gz: !binary |-
|
|
13
|
-
NDg2Y2JiZGFmOWMxMGNiMDQwNGM0NDA5ZWM3Mjc2M2IwYzIzMzFjYjliMjI0
|
|
14
|
-
OWY3Mjk4MDkzYjMwMjM4MDI5YWJhNDMxZWNlMTZmOTIyNTZmNmVmNWVmMTA5
|
|
15
|
-
NTRmM2M0ZjY2M2RiMjkyZmIyMzk4YjFjOWFmMDA5ZDVhODM1Zjc=
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 6cb24ae4857e7d85789960a9ddaa4878c595378c
|
|
4
|
+
data.tar.gz: e9d1d745ee288a215cad41b253314a53baceda29
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 17dc8a313f29d6af6c08e17a56bc5ac724d969251cdde10a16f4de9af96bdb5be6f27f3c36d0bd3ebe6f628a2aec59232fdbabff6d3540794e4b902460ced467
|
|
7
|
+
data.tar.gz: f1cb6f464b16f390eccdc8337913c75d027e967e12d9aa3fe9779a2b89bec4a11508dff765a48c8375e61bcb3f12050dff36cb9595a136380ae8341eb3a9b994
|
data/.coveralls.yml
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
service-name: travis-ci
|
data/Gemfile
CHANGED
data/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
# Identitee [](http://badge.fury.io/rb/identitee) [](https://travis-ci.org/natedavisolds/identify) [](https://codeclimate.com/github/natedavisolds/identify) [](https://coveralls.io/r/natedavisolds/identify?branch=master)
|
|
2
2
|
|
|
3
|
-
Provides methods for
|
|
3
|
+
Provides methods for building and retrieving instances of a class. Identify is intended to replace persisting data that is tightly tied to domain logic.
|
|
4
4
|
|
|
5
5
|
Many times you might see a database structure that will always remain static until the codebase changes. This is a headache to seed the proper data for the objects to work. Instead use identify to write these classes in code.
|
|
6
6
|
|
|
@@ -8,7 +8,7 @@ Likewise, many classes may be constructed that do the same thing... just a littl
|
|
|
8
8
|
|
|
9
9
|
### Finding
|
|
10
10
|
|
|
11
|
-
Find an identifiable through the `find_identifiable` class method. (See the Basic Example)
|
|
11
|
+
Find an identifiable through the `find_identifiable` (aliased also to find) class method. (See the Basic Example)
|
|
12
12
|
|
|
13
13
|
class Activity
|
|
14
14
|
include Identitee
|
|
@@ -25,10 +25,11 @@ Find an identifiable through the `find_identifiable` class method. (See the Basi
|
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
Activity.find_identifiable(:new_activity).title # => "Created something new"
|
|
28
|
+
Activity.find(:new_activity).title # => "Created something new"
|
|
28
29
|
|
|
29
30
|
### Loading identifiables
|
|
30
31
|
|
|
31
|
-
Identitee will try to autoload the identifiables if it doesn't already know about them. By default it will use the pluralize class_name of the identifiable from the folder that the source file is in. The load path can explicitly be set with the `
|
|
32
|
+
Identitee will try to autoload the identifiables if it doesn't already know about them. By default it will use the pluralize class_name of the identifiable from the folder that the source file is in. The load path can explicitly be set with the `set_identitee_root` method call.
|
|
32
33
|
|
|
33
34
|
class LazyLoadingTest
|
|
34
35
|
include Identitee
|
data/ROADMAP.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
# ROADMAP
|
|
2
2
|
|
|
3
|
+
## Needed For 1.0 Release
|
|
3
4
|
- Document a working example
|
|
4
5
|
- Allow for other/additional loaders to be used
|
|
5
|
-
-
|
|
6
|
+
- Reduce the number of class methods that identify creates
|
|
7
|
+
- Documentation in code
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
module Identitee
|
|
2
|
+
class DefaultPathBuilder
|
|
3
|
+
def self.to_path call_stack, including_class
|
|
4
|
+
new(call_stack, including_class).to_path
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def initialize call_stack, including_class
|
|
8
|
+
@call_stack = call_stack
|
|
9
|
+
@including_class = including_class
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def to_path
|
|
13
|
+
[directory_of_caller, pluralized_class_name].join('/')
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
private
|
|
17
|
+
|
|
18
|
+
attr_accessor :call_stack, :including_class
|
|
19
|
+
|
|
20
|
+
def directory_of_caller
|
|
21
|
+
File.dirname most_recent_caller_path_without_line_number
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def most_recent_caller_path_without_line_number
|
|
25
|
+
most_recent_caller_path.split(':').first
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def most_recent_caller_path
|
|
29
|
+
call_stack.first.to_s
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def pluralized_class_name
|
|
33
|
+
including_class_name.gsub(/([A-Z]+)([A-Z])/,'\1_\2').
|
|
34
|
+
gsub(/([a-z])([A-Z])/,'\1_\2').
|
|
35
|
+
gsub('/' ,'__').
|
|
36
|
+
gsub('::','__').
|
|
37
|
+
downcase + "s"
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def including_class_name
|
|
41
|
+
including_class.name.to_s
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
data/lib/identitee/identify.rb
CHANGED
|
@@ -18,6 +18,10 @@ module Identitee
|
|
|
18
18
|
end
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
+
def find_identifiable_key instance
|
|
22
|
+
identifiables.find_key instance
|
|
23
|
+
end
|
|
24
|
+
|
|
21
25
|
def all_identifiables
|
|
22
26
|
load_all_identifiables
|
|
23
27
|
identifiables.all
|
|
@@ -27,7 +31,7 @@ module Identitee
|
|
|
27
31
|
::Identitee::Loader.new(identify_root_directory: identify_root_directory).load_all
|
|
28
32
|
end
|
|
29
33
|
|
|
30
|
-
def
|
|
34
|
+
def set_identitee_root path_to_template_root
|
|
31
35
|
@identify_root_directory = path_to_template_root
|
|
32
36
|
end
|
|
33
37
|
|
data/lib/identitee/version.rb
CHANGED
data/lib/identitee.rb
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
require "identitee/version"
|
|
2
2
|
require "identitee/identify"
|
|
3
|
+
require "identitee/default_path_builder"
|
|
3
4
|
require "identitee/identify/find_alias"
|
|
4
5
|
|
|
5
6
|
module Identitee
|
|
6
7
|
def self.included base
|
|
7
8
|
base.extend ::Identitee::Identify
|
|
8
|
-
base.extend ::Identitee::Identify::FindAlias unless method_defined? :find
|
|
9
|
+
base.extend ::Identitee::Identify::FindAlias unless base.method_defined? :find
|
|
10
|
+
|
|
11
|
+
base.set_identitee_root Identitee::DefaultPathBuilder.to_path caller, base
|
|
9
12
|
end
|
|
10
13
|
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe "Can find identifiables using the short hand find" do
|
|
4
|
+
class AliasFindingTestCase
|
|
5
|
+
include Identitee
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
it "uses the find alias" do
|
|
9
|
+
test_case = AliasFindingTestCase.identify :test
|
|
10
|
+
AliasFindingTestCase.find(:test).should eq test_case
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
class OtherFindTestCase
|
|
14
|
+
def self.find echo
|
|
15
|
+
"other find #{echo}"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
include Identitee
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "uses the existing find method" do
|
|
22
|
+
test_case = OtherFindTestCase.identify :test
|
|
23
|
+
OtherFindTestCase.find(:test).should == "other find test"
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe "Default the directory to the caller classes directory and the pluralized version of the class name" do
|
|
4
|
+
class DefaultDirectorySetTest
|
|
5
|
+
include Identitee
|
|
6
|
+
|
|
7
|
+
attr_accessor :successful
|
|
8
|
+
|
|
9
|
+
def initialize
|
|
10
|
+
@successful = false
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def successful?
|
|
14
|
+
@successful
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "has a identify_root_directory" do
|
|
19
|
+
DefaultDirectorySetTest.identify_root_directory.should =~ /default_directory_set_tests/
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "lazy loads identifyables" do
|
|
23
|
+
test = DefaultDirectorySetTest.find_identifiable :default_directory_test
|
|
24
|
+
test.should_not be_nil
|
|
25
|
+
test.should be_successful
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -1,24 +1,13 @@
|
|
|
1
|
-
require '
|
|
1
|
+
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe "Force all Loading" do
|
|
4
|
-
|
|
5
|
-
class LazyLoadingTest
|
|
4
|
+
class LoadingAllTest
|
|
6
5
|
include Identitee
|
|
7
|
-
|
|
8
|
-
attr_accessor :successful
|
|
9
|
-
|
|
10
|
-
set_identify_root File.expand_path("../lazy_loading_tests/", __FILE__)
|
|
11
|
-
|
|
12
|
-
def initialize
|
|
13
|
-
@successful = false
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def successful?
|
|
17
|
-
@successful
|
|
18
|
-
end
|
|
6
|
+
set_identitee_root File.expand_path("../loading_all_tests/", __FILE__)
|
|
19
7
|
end
|
|
20
8
|
|
|
21
9
|
it "loads all the identifiable before calling all" do
|
|
22
|
-
|
|
10
|
+
identifiables = LoadingAllTest.all_identifiables
|
|
11
|
+
identifiables.length.should == 2
|
|
23
12
|
end
|
|
24
13
|
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require '
|
|
1
|
+
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe "Lazy Loading" do
|
|
4
4
|
|
|
@@ -7,7 +7,7 @@ describe "Lazy Loading" do
|
|
|
7
7
|
|
|
8
8
|
attr_accessor :successful
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
set_identitee_root File.expand_path("../lazy_loading_tests/", __FILE__)
|
|
11
11
|
|
|
12
12
|
def initialize
|
|
13
13
|
@successful = false
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require '
|
|
1
|
+
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
module Identitee
|
|
4
4
|
describe Identifiables do
|
|
@@ -47,5 +47,12 @@ module Identitee
|
|
|
47
47
|
identifiables.all.should == [instance]
|
|
48
48
|
end
|
|
49
49
|
end
|
|
50
|
+
|
|
51
|
+
context "when find the key" do
|
|
52
|
+
it "gives the string identifier for the instance" do
|
|
53
|
+
identifiables.register :foo, instance
|
|
54
|
+
identifiables.find_key(instance).should eq 'foo'
|
|
55
|
+
end
|
|
56
|
+
end
|
|
50
57
|
end
|
|
51
58
|
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require '
|
|
1
|
+
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe Identitee do
|
|
4
4
|
it "acts as a constructor" do
|
|
@@ -62,7 +62,7 @@ describe Identitee do
|
|
|
62
62
|
TestAddingFind.should respond_to :find
|
|
63
63
|
end
|
|
64
64
|
|
|
65
|
-
it "doesn't
|
|
65
|
+
it "doesn't symplify find_identifiable when find exists" do
|
|
66
66
|
TestNotReplacingFind = Class.new do
|
|
67
67
|
def self.find key
|
|
68
68
|
key
|
|
@@ -76,4 +76,14 @@ describe Identitee do
|
|
|
76
76
|
TestNotReplacingFind.find("something").should == "something"
|
|
77
77
|
TestNotReplacingFind.find_identifiable("something").should == "Unknown"
|
|
78
78
|
end
|
|
79
|
+
|
|
80
|
+
it "finds the key for an identifiable" do
|
|
81
|
+
TestFindIdentiteeKey = Class.new do
|
|
82
|
+
include Identitee
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
instance = TestFindIdentiteeKey.identify :testing_key
|
|
86
|
+
|
|
87
|
+
TestFindIdentiteeKey.find_identifiable_key(instance).should eq 'testing_key'
|
|
88
|
+
end
|
|
79
89
|
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require '
|
|
1
|
+
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
module Identitee
|
|
4
4
|
describe Loader do
|
|
@@ -20,11 +20,7 @@ module Identitee
|
|
|
20
20
|
|
|
21
21
|
loader.should_receive(:force_load).with('known.rb').once
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
"Failing"
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
identity.should_not == "Failing"
|
|
23
|
+
loader.lazy_load('known')
|
|
28
24
|
end
|
|
29
25
|
end
|
|
30
26
|
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
|
1
|
+
require 'coveralls'
|
|
2
|
+
Coveralls.wear!
|
|
3
|
+
|
|
4
|
+
require 'identitee'
|
|
5
|
+
|
|
7
6
|
RSpec.configure do |config|
|
|
8
7
|
config.treat_symbols_as_metadata_keys_with_true_values = true
|
|
9
8
|
config.run_all_when_everything_filtered = true
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: identitee
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Nate Davis Olds
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2014-
|
|
11
|
+
date: 2014-02-18 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Identifies and stores instances of a class for later loading
|
|
14
14
|
email:
|
|
@@ -17,6 +17,7 @@ executables: []
|
|
|
17
17
|
extensions: []
|
|
18
18
|
extra_rdoc_files: []
|
|
19
19
|
files:
|
|
20
|
+
- .coveralls.yml
|
|
20
21
|
- .gitignore
|
|
21
22
|
- .rspec
|
|
22
23
|
- .travis.yml
|
|
@@ -28,15 +29,21 @@ files:
|
|
|
28
29
|
- Rakefile
|
|
29
30
|
- identitee.gemspec
|
|
30
31
|
- lib/identitee.rb
|
|
32
|
+
- lib/identitee/default_path_builder.rb
|
|
31
33
|
- lib/identitee/identifiable_not_found.rb
|
|
32
34
|
- lib/identitee/identifiables.rb
|
|
33
35
|
- lib/identitee/identify.rb
|
|
34
36
|
- lib/identitee/identify/find_alias.rb
|
|
35
37
|
- lib/identitee/loader.rb
|
|
36
38
|
- lib/identitee/version.rb
|
|
39
|
+
- spec/acceptance/alias_find_acceptance_spec.rb
|
|
40
|
+
- spec/acceptance/default_directory_acceptance_spec.rb
|
|
41
|
+
- spec/acceptance/default_directory_set_tests/default_directory_test.rb
|
|
37
42
|
- spec/acceptance/force_all_loading_acceptance_spec.rb
|
|
38
43
|
- spec/acceptance/lazy_loading_acceptance_spec.rb
|
|
39
44
|
- spec/acceptance/lazy_loading_tests/autoload_test.rb
|
|
45
|
+
- spec/acceptance/loading_all_tests/test1.rb
|
|
46
|
+
- spec/acceptance/loading_all_tests/test2.rb
|
|
40
47
|
- spec/integration/loader_integration_spec.rb
|
|
41
48
|
- spec/integration/test_files/test_lazy_load.rb
|
|
42
49
|
- spec/lib/identitee/identifiables_spec.rb
|
|
@@ -53,24 +60,29 @@ require_paths:
|
|
|
53
60
|
- lib
|
|
54
61
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
55
62
|
requirements:
|
|
56
|
-
- -
|
|
63
|
+
- - '>='
|
|
57
64
|
- !ruby/object:Gem::Version
|
|
58
65
|
version: '0'
|
|
59
66
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
60
67
|
requirements:
|
|
61
|
-
- -
|
|
68
|
+
- - '>='
|
|
62
69
|
- !ruby/object:Gem::Version
|
|
63
70
|
version: '0'
|
|
64
71
|
requirements: []
|
|
65
72
|
rubyforge_project:
|
|
66
|
-
rubygems_version: 2.0.
|
|
73
|
+
rubygems_version: 2.0.14
|
|
67
74
|
signing_key:
|
|
68
75
|
specification_version: 4
|
|
69
76
|
summary: ''
|
|
70
77
|
test_files:
|
|
78
|
+
- spec/acceptance/alias_find_acceptance_spec.rb
|
|
79
|
+
- spec/acceptance/default_directory_acceptance_spec.rb
|
|
80
|
+
- spec/acceptance/default_directory_set_tests/default_directory_test.rb
|
|
71
81
|
- spec/acceptance/force_all_loading_acceptance_spec.rb
|
|
72
82
|
- spec/acceptance/lazy_loading_acceptance_spec.rb
|
|
73
83
|
- spec/acceptance/lazy_loading_tests/autoload_test.rb
|
|
84
|
+
- spec/acceptance/loading_all_tests/test1.rb
|
|
85
|
+
- spec/acceptance/loading_all_tests/test2.rb
|
|
74
86
|
- spec/integration/loader_integration_spec.rb
|
|
75
87
|
- spec/integration/test_files/test_lazy_load.rb
|
|
76
88
|
- spec/lib/identitee/identifiables_spec.rb
|