ars-medium 0.1.0.alpha2

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ea1765d4ab22488b51526680a72c25349bdaaaa9
4
+ data.tar.gz: 4f463d32dd947d6ab6aa7d1caad60d42d1d5ee52
5
+ SHA512:
6
+ metadata.gz: ef1a7312d68ba42eef6667c936a57efe6b1ee2c88f70c2f4725545ffd7de2466dcb59f89e5993e4274a922f045f141416f069ad55bd95dd798296e460ddc341f
7
+ data.tar.gz: 63e64f071d1cf543d6b9d72b379a6bf939361afb39b870ddd640af541433dc53016d6ddccec3970ef468db22e1db2438a162f0cc3300e5c9404e20e9fcb53f31
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /Gemfile.local
11
+ /.rvmrc
12
+
13
+ # rspec failure tracking
14
+ .rspec_status
15
+
16
+ # Emacs
17
+ *~
18
+ \#*\#
19
+ .\#*
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.1.5
5
+ before_install: gem install bundler -v 1.14.3
data/Gemfile ADDED
@@ -0,0 +1,20 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ars-medium.gemspec
4
+ gemspec
5
+
6
+ gem 'rake'
7
+ gem 'bundler'#, '~> 1.14'
8
+ gem 'rspec'#, '~> 3.0'
9
+
10
+ gem 'yard', require: false
11
+
12
+ %w[ars-familiar ars-doppelganger].each do |lib|
13
+ lib_path = File.expand_path("../../#{lib}", __FILE__)
14
+ lib_path = false unless File.exists? lib_path
15
+ if lib_path
16
+ gem lib, :path => lib_path
17
+ end
18
+ end
19
+
20
+ eval File.read('Gemfile.local') if File.exist?('Gemfile.local')
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 cunningfolk
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Michael Lee Vazquez
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Ars::Medium
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ars/medium`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'ars-medium'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install ars-medium
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Michael Lee Vazquez/ars-medium.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -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,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ars/medium/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ars-medium"
8
+ spec.version = Ars::Medium::VERSION
9
+ spec.authors = ["Michael Lee Vazquez"]
10
+ spec.email = ["magnus.nothus@gmail.com"]
11
+
12
+ spec.summary = %q{ars-medium-#{Ars::Medium::VERSION}}
13
+ spec.description = %q{Ruby Web Client that syncs with most models}
14
+ spec.homepage = "http://github.com/cunningfolk/ars-medium"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ %w[familiar doppelganger].each do |lib_name|
25
+ if Ars::Medium::VERSION =~ /[a-zA-Z]+/
26
+ spec.add_runtime_dependency "ars-#{lib_name}", "= #{Ars::Medium::VERSION}"
27
+ else
28
+ spec.add_runtime_dependency "ars-#{lib_name}", "~> #{Ars::Medium::VERSION.sub(/^((?:\d+\.){2}).*$/, '\1.0')}"
29
+ end
30
+ end
31
+
32
+ spec.add_runtime_dependency 'her', '>= 0', '>= 0'
33
+ spec.add_runtime_dependency 'rack-test', '>= 0', '>= 0'
34
+
35
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ars/medium"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,37 @@
1
+ module Ars
2
+ module Medium
3
+ class Link
4
+
5
+ class << self
6
+ attr_accessor :default_link
7
+ end
8
+
9
+ # def self.prime!(config = Ars::Medium.configuration, opts = {})
10
+ # @default_link = new(config, opts)
11
+ # end
12
+
13
+ def self.prime(config = Ars::Medium.configuration, opts = {})
14
+ @default_link || prime!(config, opts)
15
+ end
16
+
17
+ def initialize(config = Ars::Medium.configuration, opts = {})
18
+ prime(config, opts)
19
+ end
20
+
21
+ def self.prime!(config = Ars::Medium.configuration, opts = {})
22
+
23
+ opts = config.connection_options.merge(opts)
24
+
25
+ require 'her'
26
+
27
+ @default_link = Her::API.new opts do |c|
28
+ c.ssl.verify = false
29
+ config.middleware.each do |ware|
30
+ c.send *ware
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+
@@ -0,0 +1,23 @@
1
+ require 'her'
2
+ require 'ars/familiar/scribe'
3
+
4
+ module Ars
5
+ module Medium
6
+ class Model
7
+ def self.filter_root_element(root_element)
8
+ root_element.to_s.sub(/_medium$/, '').to_sym
9
+ end
10
+
11
+ def self.inherited(subclass)
12
+ subclass.include Her::Model
13
+ subclass.include Ars::Familiar
14
+ subclass.include Ars::Familiar::Scribe
15
+
16
+ subclass.use_api Ars::Medium::Link.prime
17
+ subclass.root_element filter_root_element(subclass.root_element)
18
+ end
19
+
20
+ end
21
+ end
22
+ end
23
+
@@ -0,0 +1,106 @@
1
+ require 'her'
2
+ require 'rack/test'
3
+
4
+ module Ars
5
+ module Medium
6
+ module TestMethods
7
+
8
+ def self.app
9
+ @app ||= Rack::Builder.parse_file('server.ru').first
10
+ end
11
+
12
+ def stub_api_for(klass)
13
+ klass.use_api( Link.prime!(Medium::configuration) )
14
+ end
15
+
16
+ class RackChanneler
17
+ attr_accessor :path_map
18
+
19
+ class RHash < Hash
20
+ def [](lookup)
21
+ (find {|rkey,_| lookup =~ rkey } || []).last
22
+ end
23
+ end
24
+
25
+ def initialize
26
+ @path_map = RHash.new
27
+ end
28
+
29
+ def focus(medium)
30
+ [:collection_path, :resource_path].each do |path|
31
+ path = medium.send(path)
32
+ path_regex = path_regex path
33
+ path_map[path_regex] = { medium: medium, path: path, regex: path_regex }
34
+ end
35
+ end
36
+
37
+ def path_regex(path)
38
+ Regexp.new("^/#{path.gsub(/\:([^\/]+)/, '(?<\1>[^\/]+)')}$")
39
+ end
40
+
41
+ def call(env)
42
+ [status, headers, body]
43
+ end
44
+
45
+ def status
46
+ 200
47
+ end
48
+
49
+ def headers
50
+ {}
51
+ end
52
+
53
+ def body
54
+ []
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+
61
+ RSpec.configure do |config|
62
+ config.include Ars::Medium::TestMethods
63
+ end
64
+
65
+ RSpec.shared_context "Ars::Medium Rack Stubs" do |*media|
66
+ Ars::Medium.configure do |config|
67
+ config.middleware = [
68
+ [:request, :multipart],
69
+ [:request, :url_encoded],
70
+ [:use, ::Her::Middleware::DefaultParseJSON],
71
+ #[:response, :logger, nil, {bodies: true}],
72
+ [:adapter, :rack, Ars::Medium::TestMethods.app]
73
+ ]
74
+ end
75
+
76
+ media = [*media]
77
+ media.each do |medium|
78
+ before { stub_api_for medium }
79
+ end
80
+ end
81
+
82
+ RSpec.shared_context "Ars::Medium API Stubs" do |*media|
83
+ media = [*media]
84
+
85
+ rack_channeler = Ars::Medium::TestMethods::RackChanneler.new
86
+
87
+ let(:rack_handle) { rack_channeler }
88
+
89
+ media.each do |medium|
90
+ rack_channeler.focus medium
91
+ end
92
+
93
+ Ars::Medium.configure do |config|
94
+ config.middleware = [
95
+ [:request, :multipart],
96
+ [:request, :url_encoded],
97
+ [:use, ::Her::Middleware::DefaultParseJSON],
98
+ [:adapter, :rack, rack_channeler]
99
+ ]
100
+ end
101
+
102
+ media.each do |medium|
103
+ before { stub_api_for medium }
104
+ end
105
+ end
106
+
@@ -0,0 +1,5 @@
1
+ module Ars
2
+ module Medium
3
+ VERSION = "0.1.0.alpha2"
4
+ end
5
+ end
data/lib/ars/medium.rb ADDED
@@ -0,0 +1,42 @@
1
+ require "ars/medium/version"
2
+
3
+ module Ars
4
+ module Medium
5
+
6
+ autoload :Link, 'ars/medium/link'
7
+ autoload :Model, 'ars/medium/model'
8
+ autoload :TestMethods, 'ars/medium/test_methods'
9
+
10
+ class << self
11
+ attr_accessor :configuration
12
+ end
13
+
14
+ def self.configuration
15
+ @configuration ||= Configuration.new
16
+ end
17
+
18
+ def self.configure
19
+ yield configuration
20
+ end
21
+
22
+ class Configuration
23
+ attr_accessor :url, :ssl, :middleware, :root
24
+
25
+ def initialize
26
+ @url = 'http://localhost/'
27
+ @ssl = {verify: false}
28
+ @middleware = [
29
+ [:request, :multipart],
30
+ [:request, :url_encoded],
31
+ [:use, Her::Middleware::DefaultParseJSON],
32
+ [:adapter, :net_http_persistent]
33
+ ]
34
+ end
35
+
36
+ def connection_options
37
+ %i{url ssl}.inject({}) {|hash, key| hash[key] = self.send key ; hash}
38
+ end
39
+ end
40
+ end
41
+ end
42
+
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ars-medium
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.alpha2
5
+ platform: ruby
6
+ authors:
7
+ - Michael Lee Vazquez
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-02-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ars-familiar
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.0.alpha2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.0.alpha2
27
+ - !ruby/object:Gem::Dependency
28
+ name: ars-doppelganger
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.0.alpha2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 0.1.0.alpha2
41
+ - !ruby/object:Gem::Dependency
42
+ name: her
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
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: rack-test
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Ruby Web Client that syncs with most models
70
+ email:
71
+ - magnus.nothus@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - LICENSE
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - ars-medium.gemspec
85
+ - bin/console
86
+ - bin/setup
87
+ - lib/ars/medium.rb
88
+ - lib/ars/medium/link.rb
89
+ - lib/ars/medium/model.rb
90
+ - lib/ars/medium/test_methods.rb
91
+ - lib/ars/medium/version.rb
92
+ homepage: http://github.com/cunningfolk/ars-medium
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">"
108
+ - !ruby/object:Gem::Version
109
+ version: 1.3.1
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.2.2
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: ars-medium-#{Ars::Medium::VERSION}
116
+ test_files: []