llt-db_handler-stub 0.0.1

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: 4d3f4b683c463af527bac4df8814cf1f56615523
4
+ data.tar.gz: bdf9f12b881fffef91265f91bc61a75bc53ac282
5
+ SHA512:
6
+ metadata.gz: 334df83039047b83360eb32148a124240a105a3ef051fd7ff68148b7f9ddb76ff8d0008ea099c9e75024a767eaffb744add954d3b691f217f5cbda58002a5164
7
+ data.tar.gz: cb554d3e4b246d6cce6d478a2ea357a57caa9ece8ce21f9cec9589f2f725e9bf08bd2d676663996574eb400987ec8b2a697ca3408f636527fb823ef450d8c926
@@ -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/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,8 @@
1
+ ---
2
+ language: ruby
3
+ before_script:
4
+ - export JRUBY_OPTS=--2.0
5
+ rvm:
6
+ - 2.1.0
7
+ - 2.0.0
8
+ - jruby-1.7.8
data/Gemfile ADDED
@@ -0,0 +1,19 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in llt-db_handler-stub.gemspec
4
+ gemspec
5
+ gem 'coveralls', require: false
6
+
7
+ gem 'llt-core_extensions', git: 'git@github.com:latin-language-toolkit/llt-core_extensions.git'
8
+ gem 'llt-constants', git: 'git@github.com:latin-language-toolkit/llt-constants.git'
9
+ gem 'llt-db_handler', git: 'git@github.com:latin-language-toolkit/llt-db_handler.git'
10
+ gem 'llt-form_builder', git: 'git@github.com:latin-language-toolkit/llt-form_builder.git'
11
+ gem 'llt-helpers', git: 'git@github.com:latin-language-toolkit/llt-helpers.git'
12
+
13
+ platform :ruby do
14
+ gem 'pg'
15
+ end
16
+
17
+ platform :jruby do
18
+ gem 'activerecord-jdbcpostgresql-adapter'
19
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 LFDM
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,35 @@
1
+ # LLT::DbHandler::Stub
2
+
3
+ [![Version](http://allthebadges.io/latin-language-toolkit/llt-db_handler-stub/badge_fury.png)](http://allthebadges.io/latin-language-toolkit/llt-db_handler-stub/badge_fury)
4
+ [![Dependencies](http://allthebadges.io/latin-language-toolkit/llt-db_handler-stub/gemnasium.png)](http://allthebadges.io/latin-language-toolkit/llt-db_handler-stub/gemnasium)
5
+ [![Build Status](http://allthebadges.io/latin-language-toolkit/llt-db_handler-stub/travis.png)](http://allthebadges.io/latin-language-toolkit/llt-db_handler-stub/travis)
6
+ [![Coverage](http://allthebadges.io/latin-language-toolkit/llt-db_handler-stub/coveralls.png)](http://allthebadges.io/latin-language-toolkit/llt-db_handler-stub/coveralls)
7
+ [![Code Climate](http://allthebadges.io/latin-language-toolkit/llt-db_handler-stub/code_climate.png)](http://allthebadges.io/latin-language-toolkit/llt-db_handler-stub/code_climate)
8
+
9
+ A testing helper for LLT
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ gem 'llt-db_handler-stub'
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install llt-db_handler-stub
24
+
25
+ ## Usage
26
+
27
+ TODO: Write usage instructions here
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it ( http://github.com/<my-github-username>/llt-db_handler-stub/fork )
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create new Pull Request
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,61 @@
1
+ require 'llt/db_handler/common_db'
2
+
3
+ module LLT
4
+ module DbHandler
5
+ class Stub < CommonDb
6
+ require 'llt/db_handler/stub/stub_entries'
7
+
8
+ @stems = {}
9
+
10
+ class << self
11
+ include Helpers::Normalizer
12
+
13
+ attr_reader :stems
14
+
15
+ def create_stem_stub(return_val, args)
16
+ args = normalize_args(args)
17
+ @stems[args] = return_val
18
+ end
19
+ alias :create :create_stem_stub
20
+
21
+ def setup
22
+ StubEntries.setup
23
+ end
24
+ end
25
+
26
+ def type
27
+ :stub
28
+ end
29
+
30
+ def look_up_stem(args)
31
+ super
32
+ stems.select do |stored_args|
33
+ if stored_args.merge(args_to_query) == stored_args
34
+ if restr = @args[:restrictions]
35
+ restr[:values].include?(stored_args[restr[:type]])
36
+ end
37
+ end
38
+ end.values
39
+ end
40
+
41
+ def direct_lookup(type, string)
42
+ args = dl_to_query(type, string)
43
+ stems.select do |stored|
44
+ stored.merge(args) == stored
45
+ end.values
46
+ end
47
+
48
+ def dl_to_query(type, string)
49
+ { type: type, word: string}
50
+ end
51
+
52
+ def args_to_query
53
+ {type: @args[:type], @args[:stem_type] => @args[:stem] }
54
+ end
55
+
56
+ def stems
57
+ self.class.stems
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,90 @@
1
+ require 'ostruct'
2
+
3
+ class LLT::DbHandler::Stub::StubEntries
4
+ class << self
5
+ def setup(size = :medium)
6
+ db_stub.stems.clear
7
+
8
+ medium_setup
9
+ # not implemented yet
10
+ #case size
11
+ #when :big then big_setup
12
+ #when :small then small_setup
13
+ #else medium_setup
14
+ #end
15
+ end
16
+
17
+ private
18
+
19
+ def small_setup
20
+ end
21
+
22
+ def medium_setup
23
+ wsr(type: :noun, nom: "homo", stem: "homin", itype: 3, sexus: :m)
24
+ wsr(type: :noun, nom: "vir", stem: "vir", itype: 2, sexus: :m)
25
+ wsr(type: :noun, nom: "ratio", stem: "ration", itype: 3, sexus: :f)
26
+ wsr(type: :noun, nom: "magnitudo", stem: "magnitudin", itype: 3, sexus: :f)
27
+ wsr(type: :noun, nom: "libido", stem: "libidin", itype: 3, sexus: :f)
28
+ wsr(type: :noun, nom: "nox", stem: "noct", itype: 3, sexus: :f)
29
+ wsr(type: :noun, nom: "filius", stem: "fili", itype: 2, sexus: :m)
30
+ wsr(type: :noun, nom: "servus", stem: "serv", itype: 2, sexus: :m)
31
+ wsr(type: :noun, nom: "dominus", stem: "domin", itype: 2, sexus: :m)
32
+
33
+ wsr(type: :noun, nom: "flumen", stem: "flumin", itype: 3, sexus: :n)
34
+ wsr(type: :noun, nom: "arma", stem: "arm", itype: 2, sexus: :n) # this might actually be wrong?
35
+
36
+ wsr(type: :persona, nom: "Plato", stem: "Platon", itype: 3)
37
+ wsr(type: :persona, nom: "Solon", stem: "Solon", itype: 3)
38
+ wsr(type: :persona, nom: "Paulinus", stem: "Paulin", itype: 2)
39
+
40
+ wsr(type: :adjective, nom: "communis", stem: "commun", itype: 3, number_of_endings: 1)
41
+ wsr(type: :adjective, nom: "diligens", stem: "diligent", itype: 3, number_of_endings: 1)
42
+ wsr(type: :adjective, nom: "laetus", stem: "laet", itype: 1, number_of_endings: 3)
43
+ wsr(type: :adjective, nom: "ferus", stem: "fer", itype: 1, number_of_endings: 3)
44
+ wsr(type: :adjective, nom: "bonus", stem: "bon", itype: 1, number_of_endings: 3)
45
+
46
+ wsr(type: :adjective, nom: "aestivus", stem: "aestiv", itype: 1, number_of_endings: 3)
47
+ wsr(type: :adjective, nom: "suavis", stem: "suav", itype: 3, number_of_endings: 2)
48
+
49
+
50
+ wsr(type: :ethnic, stem: "Haedu", inflection_class: 1)
51
+ wsr(type: :ethnic, stem: "Redon", inflection_class: 3)
52
+
53
+ wsr(type: :verb, pr: "ita", pf: "itav", pf_composition: "v", itype: 1, dep: false, dir_objs: "", indir_objs: "")
54
+ wsr(type: :verb, pr: "cana", pf: "canav", ppp: "canat", pf_composition: "v", itype: 1, dep: false, dir_objs: "", indir_objs: "")
55
+ wsr(type: :verb, pr: "mone", pf: "monu", ppp: "monit", pf_composition: "u", itype: 2, dep: false, dir_objs: "", indir_objs: "")
56
+ wsr(type: :verb, pr: "move", pf: "movi", ppp: "mot", pf_composition: "ablaut", itype: 2, dep: false, dir_objs: "", indir_objs: "")
57
+ wsr(type: :verb, pr: "mitt", pf: "mis", ppp: "miss", pf_composition: "s", itype: 3, dep: false, dir_objs: "", indir_objs: "")
58
+ wsr(type: :verb, pr: "viv", pf: "vix", ppp: "-", pf_composition: "s", itype: 3, dep: false, dir_objs: "", indir_objs: "")
59
+ wsr(type: :verb, pr: "audi", pf: "audiv", ppp: "audit", pf_composition: "v", itype: 4, dep: false, dir_objs: "", indir_objs: "")
60
+ wsr(type: :verb, pr: "horta", ppp: "hortat", itype: 1, dep: true , dir_objs: "", indir_objs: "")
61
+
62
+ dl(type: :adverb, word: "ita")
63
+ dl(type: :adverb, word: "iam")
64
+ dl(type: :adverb, word: "subito")
65
+ end
66
+
67
+ def big_setup
68
+ end
69
+
70
+ def db_stub
71
+ LLT::DbHandler::Stub
72
+ end
73
+
74
+ def factory(type, args)
75
+ LLT::StemBuilder.build(type, args, "stub")
76
+ end
77
+
78
+ # with_single_return
79
+ def wsr(args)
80
+ ret_val = factory(args[:type], args.reject { |k, _| k == :type })
81
+ db_stub.create(ret_val, args)
82
+ end
83
+
84
+ # direct_lookup
85
+ def dl(args)
86
+ ret_val = OpenStruct.new(word: args[:word])
87
+ db_stub.create(ret_val, args)
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "llt-db_handler-stub"
7
+ spec.version = '0.0.1'
8
+ spec.authors = ["LFDM"]
9
+ spec.email = ["1986gh@gmail.com"]
10
+ spec.summary = %q{A testing helper for llt}
11
+ spec.description = spec.summary
12
+ spec.homepage = ""
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.5"
21
+ spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "rspec"
23
+ spec.add_development_dependency "simplecov", "~> 0.7"
24
+
25
+ spec.add_development_dependency "llt-db_handler"
26
+ end
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+ require 'llt/db_handler/stub'
3
+
4
+ describe LLT::DbHandler::Stub do
5
+ let(:db_stub) { LLT::DbHandler::Stub }
6
+
7
+ describe "#type" do
8
+ it "identifies the db_stub as stub" do
9
+ db_stub.new.type.should == :stub
10
+ end
11
+ end
12
+ describe ".create_stem_stub" do
13
+ it "creates a new stem stub" do
14
+ db_stub.stems.clear
15
+ db_stub.create_stem_stub("test", test: "val")
16
+ db_stub.stems.should have(1).item
17
+ end
18
+
19
+ it "has alias create" do
20
+ db_stub.stems.clear
21
+ db_stub.create("test", test: "val")
22
+ db_stub.stems.should have(1).item
23
+ end
24
+ end
25
+
26
+ describe "#look_up_stem" do
27
+ it "returns an array of db entries" do
28
+ db_stub.create_stem_stub("test", type: :noun, nom: "rosa", stem: "ros", inflection_class: 1)
29
+ result = db_stub.new.look_up_stem(type: :noun, stem_type: :stem, stem: "ros", restrictions: { type: :inflection_class, values: [1] })
30
+ result2 = db_stub.new.look_up_stem(type: :noun, stem_type: :stem, stem: "ros", restrictions: { type: :inflection_class, values: [2] })
31
+ result.should have(1).item
32
+ result.first.should == "test"
33
+
34
+ result2.should be_empty
35
+ end
36
+ end
37
+
38
+ describe "#direct_lookup" do
39
+ it "returns an array of db entries" do
40
+ db_stub.create(:success, type: :adverb, word: "ita")
41
+ result = db_stub.new.direct_lookup(:adverb, "ita")
42
+ result.should have(1).item
43
+ result.first.should == :success
44
+ end
45
+ end
46
+
47
+ describe ".setup" do
48
+ it "creates stub entries as defined in stub_entries.rb" do
49
+ db_stub.stems.clear
50
+ db_stub.setup
51
+ db_stub.stems.should_not be_empty
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,22 @@
1
+ require 'simplecov'
2
+ require 'coveralls'
3
+
4
+ Coveralls.wear!
5
+
6
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
7
+ SimpleCov::Formatter::HTMLFormatter,
8
+ Coveralls::SimpleCov::Formatter
9
+ ]
10
+
11
+ SimpleCov.start do
12
+ add_filter '/spec/'
13
+ end
14
+
15
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
16
+ require 'llt/db_handler/stub'
17
+
18
+ RSpec.configure do |config|
19
+ config.treat_symbols_as_metadata_keys_with_true_values = true
20
+ config.run_all_when_everything_filtered = true
21
+ config.filter_run :focus
22
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: llt-db_handler-stub
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - LFDM
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-08 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.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
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
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: llt-db_handler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: A testing helper for llt
84
+ email:
85
+ - 1986gh@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - lib/llt/db_handler/stub.rb
98
+ - lib/llt/db_handler/stub/stub_entries.rb
99
+ - llt-db_handler-stub.gemspec
100
+ - spec/lib/llt/db_handler/stub_spec.rb
101
+ - spec/spec_helper.rb
102
+ homepage: ''
103
+ licenses:
104
+ - MIT
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.2.0
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: A testing helper for llt
126
+ test_files:
127
+ - spec/lib/llt/db_handler/stub_spec.rb
128
+ - spec/spec_helper.rb