alephant 0.0.3-java → 0.0.4-java

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5fdb4ac2f34ec66ad78e4a5f312ca2bf9c95e755
4
- data.tar.gz: 47b7a310bfe3d304625fe53e2a9484be33ffdcab
3
+ metadata.gz: ac3689e07939593c100632167541ecc2efd0994a
4
+ data.tar.gz: b12b4f8cd17d1a380eabdb1bf44f93ed62628fa0
5
5
  SHA512:
6
- metadata.gz: 78bfe8034f1139f7f3eb71ced0fb5b15e1a0b27feb020100fd026c1059a60e7ab0bb5eab9f704e18ce9ce88e604e7aa29a34e2d24e74c7347d7e9a1182d27d21
7
- data.tar.gz: 8dbc4c0f41e345a69c28a651bae4515537492699ba532d66223c4a8bb8d758f3ad8ead14696167c6a099e6ca93a4a661dfb8123ccb823590eae1dc1dffbab393
6
+ metadata.gz: 2094d441612a43e1571817ece377e602f9367f33b7b91cadc003b33a20144cda6938f8f08c207970949efb6dfcd142a684d1bd0cea00ac92b821a65db4077876
7
+ data.tar.gz: 054fcbe96e00401de0376192925c9278089b386238be2b3bb6c7a44b1085da372620ea1caf4bf081d2be98f142a8446d5d56380e3d7b2fffee46edb55cd8a168
data/.gitignore CHANGED
@@ -1,3 +1,7 @@
1
- config/*.yml
1
+ /config/*.yml
2
2
  Gemfile.lock
3
- pkg/*.gem
3
+ .rspec
4
+
5
+ /pkg
6
+ /tmp
7
+
data/Guardfile ADDED
@@ -0,0 +1,6 @@
1
+ guard 'rspec' do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/.+\.rb$})
4
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
5
+ watch('spec/spec_helper.rb') { "spec" }
6
+ end
data/README.md CHANGED
@@ -1,11 +1,13 @@
1
1
  alephant
2
2
  =========
3
3
 
4
+ Static publishing to S3 on push notification from SQS
5
+
4
6
  [![Code Climate](https://codeclimate.com/repos/52cd866de30ba018f10000a2/badges/5d9c02131201565a630e/gpa.png)](https://codeclimate.com/repos/52cd866de30ba018f10000a2/feed)
5
7
 
6
8
  [![Build Status](https://travis-ci.org/kenoir/alephant.png?branch=master)](https://travis-ci.org/kenoir/alephant)
7
9
 
8
- Static publishing to S3 on push notification from SQS
10
+ [![Gem Version](https://badge.fury.io/rb/alephant.png)](http://badge.fury.io/rb/alephant)
9
11
 
10
12
  ##Dependencies
11
13
 
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  $:.unshift File.join(File.dirname(__FILE__), 'lib')
2
2
 
3
3
  require 'rspec/core/rake_task'
4
- require "bundler/gem_tasks"
4
+ require 'bundler/gem_tasks'
5
5
  require 'alephant'
6
6
 
7
7
  RSpec::Core::RakeTask.new(:spec)
data/alephant.gemspec CHANGED
@@ -23,6 +23,9 @@ Gem::Specification.new do |s|
23
23
 
24
24
  s.add_development_dependency "rake"
25
25
  s.add_development_dependency "rspec"
26
+ s.add_development_dependency "rspec-nc"
27
+ s.add_development_dependency "guard"
28
+ s.add_development_dependency "guard-rspec"
26
29
  s.add_development_dependency "pry"
27
30
 
28
31
  s.add_runtime_dependency 'aws-sdk', '~> 1.0'
data/lib/alephant.rb CHANGED
@@ -6,6 +6,10 @@ require 'alephant/models/cache'
6
6
  require 'alephant/models/renderer'
7
7
  require 'alephant/models/sequencer'
8
8
 
9
+ require 'alephant/errors'
10
+ require 'alephant/views'
11
+
12
+
9
13
  module Alephant
10
14
 
11
15
  def self.run(cache_id)
@@ -0,0 +1,6 @@
1
+ module Alephant::Errors
2
+ autoload :InvalidViewPath, 'alephant/errors/invalid_view_path'
3
+ autoload :ViewModelNotFound, 'alephant/errors/view_model_not_found'
4
+ autoload :ViewTemplateNotFound, 'alephant/errors/view_template_not_found'
5
+ end
6
+
@@ -0,0 +1,6 @@
1
+ module Alephant::Errors
2
+ class InvalidViewPath < Exception
3
+
4
+ end
5
+ end
6
+
@@ -0,0 +1,6 @@
1
+ module Alephant::Errors
2
+ class ViewModelNotFound < Exception
3
+
4
+ end
5
+ end
6
+
@@ -0,0 +1,6 @@
1
+ module Alephant::Errors
2
+ class ViewTemplateNotFound < Exception
3
+
4
+ end
5
+ end
6
+
@@ -3,6 +3,8 @@ require 'mustache'
3
3
 
4
4
  module Alephant
5
5
  class Renderer
6
+ DEFAULT_LOCATION = 'views'
7
+
6
8
  attr_reader :id
7
9
 
8
10
  def initialize(id)
@@ -10,21 +12,46 @@ module Alephant
10
12
  end
11
13
 
12
14
  def render(data)
13
- Mustache.render(template(@id), data)
15
+ Mustache.render(
16
+ template(@id),
17
+ model(@id,data)
18
+ )
19
+ end
20
+
21
+ def base_path
22
+ @base_path || DEFAULT_LOCATION
23
+ end
24
+
25
+ def base_path=(path)
26
+ if File.directory?(path)
27
+ @base_path = path
28
+ else
29
+ raise Errors::InvalidViewPath
30
+ end
31
+ end
32
+
33
+ def model(id, data)
34
+ model_location =
35
+ File.join(base_path,'models',"#{id}.rb")
36
+
37
+ begin
38
+ require model_location
39
+ klass = ::Alephant::Views.get_registered_class(id)
40
+ rescue Exception => e
41
+ raise Errors::ViewModelNotFound
42
+ end
43
+
44
+ klass.new(data)
14
45
  end
15
46
 
16
- private
17
47
  def template(id)
18
- <<-eos
19
- {{#results}}
20
- <ul>
21
- <li>Con: {{con}}</li>
22
- <li>Lab: {{lab}}</li>
23
- <li>Lib: {{lib}}</li>
24
- </ul>
25
- {{/results}}
26
- <p>Sequence number: {{seq}}</p>
27
- eos
48
+ template_location =
49
+ File.join(base_path,'templates',"#{id}.mustache")
50
+ begin
51
+ File.open(template_location).read
52
+ rescue Exception => e
53
+ raise Errors::ViewTemplateNotFound
54
+ end
28
55
  end
29
56
  end
30
57
  end
@@ -0,0 +1,9 @@
1
+ class String
2
+ def underscore
3
+ self.gsub(/::/, '/').
4
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
5
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
6
+ tr("-", "_").
7
+ downcase
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module Alephant
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -0,0 +1,15 @@
1
+ module Alephant::Views
2
+ autoload :Base, 'alephant/views/base'
3
+
4
+ @@views = {}
5
+
6
+ def self.register(klass)
7
+ id = klass.name.split('::').last
8
+ @@views[id.underscore] = klass
9
+ end
10
+
11
+ def self.get_registered_class(id)
12
+ @@views[id]
13
+ end
14
+ end
15
+
@@ -0,0 +1,16 @@
1
+ require 'mustache'
2
+
3
+ module Alephant::Views
4
+ class Base < Mustache
5
+ attr_accessor :data
6
+
7
+ def initialize(data)
8
+ @data = data
9
+ end
10
+
11
+ def self.inherited(subclass)
12
+ ::Alephant::Views.register(subclass)
13
+ end
14
+ end
15
+ end
16
+
data/lib/env.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  require 'aws-sdk'
2
2
  require 'yaml'
3
3
 
4
+ require 'alephant/util/string'
5
+
4
6
  config_file = File.join("config", "aws.yml")
5
7
 
6
8
  if File.exists? config_file
@@ -0,0 +1,7 @@
1
+ module MyApp
2
+ class Example < ::Alephant::Views::Base
3
+ def content
4
+ "content"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1 @@
1
+ {{content}}
@@ -0,0 +1,132 @@
1
+ require 'spec_helper'
2
+
3
+ describe Alephant::Renderer do
4
+ let(:id) { :id }
5
+ subject { Alephant::Renderer }
6
+
7
+ describe "id=" do
8
+ it "sets the attribute id" do
9
+ expect(subject.new(id).id).to eq(id)
10
+ end
11
+ end
12
+
13
+ describe "template(id)" do
14
+ let(:id) { 'example' }
15
+ it "returns the template" do
16
+ instance = subject.new(id)
17
+ instance.base_path = File.join(
18
+ File.dirname(__FILE__),
19
+ 'fixtures',
20
+ 'views'
21
+ )
22
+
23
+ template = instance.template(id)
24
+ expect(template).to eq("{{content}}\n")
25
+ end
26
+
27
+ context 'invalid template' do
28
+ let(:id) { 'invalid_example' }
29
+ it 'should raise ViewTemplateNotFound' do
30
+ instance = subject.new(id)
31
+ instance.base_path = File.join(
32
+ File.dirname(__FILE__),
33
+ 'fixtures',
34
+ 'views'
35
+ )
36
+
37
+ expect {
38
+ instance.template(id)
39
+ }.to raise_error(
40
+ Alephant::Errors::ViewTemplateNotFound
41
+ )
42
+ end
43
+ end
44
+ end
45
+
46
+ describe "model(id, data)" do
47
+ let(:id) { 'example' }
48
+ let(:data) { { :key => :value } }
49
+ it "returns the model" do
50
+ instance = subject.new(id)
51
+ instance.base_path = File.join(
52
+ File.dirname(__FILE__),
53
+ 'fixtures',
54
+ 'views'
55
+ )
56
+
57
+ model = instance.model(id, data)
58
+ model.should be_an Alephant::Views::Base
59
+ expect(model.data).to eq(data)
60
+ end
61
+
62
+ context "invalid model" do
63
+ let(:id) { 'invalid_example' }
64
+ it 'should raise ViewModelNotFound' do
65
+ instance = subject.new(id)
66
+ instance.base_path = File.join(
67
+ File.dirname(__FILE__),
68
+ 'fixtures',
69
+ 'views'
70
+ )
71
+ expect {
72
+ instance.model(id, data)
73
+ }.to raise_error(
74
+ Alephant::Errors::ViewModelNotFound
75
+ )
76
+ end
77
+ end
78
+ end
79
+
80
+ describe "base_path" do
81
+ it "should return DEFAULT_LOCATION" do
82
+ expect(subject.new(id).base_path).to eq(
83
+ Alephant::Renderer::DEFAULT_LOCATION
84
+ )
85
+ end
86
+
87
+ context "base_path = '.'" do
88
+ let(:base_path) { '.' }
89
+ it "should return '.'" do
90
+ instance = subject.new(id)
91
+ instance.base_path = base_path
92
+ expect(instance.base_path).to eq(base_path)
93
+ end
94
+ end
95
+ end
96
+
97
+ describe "base_path=(path)" do
98
+ context "base_path = valid_path" do
99
+ let(:valid_path) {'.'}
100
+ it "should set the base_path" do
101
+ instance = subject.new(id)
102
+ instance.base_path = valid_path
103
+ expect(instance.base_path).to eq(valid_path)
104
+ end
105
+ end
106
+
107
+ context "base_path = invalid_path" do
108
+ let(:invalid_path) {'./invalid_path'}
109
+ it "should raise InvalidViewPath" do
110
+ instance = subject.new(id)
111
+ expect {
112
+ instance.base_path = invalid_path
113
+ }.to raise_error(
114
+ Alephant::Errors::InvalidViewPath
115
+ )
116
+ end
117
+ end
118
+ end
119
+
120
+ describe "render(data)" do
121
+ it 'renders a template returned from template(id)' do
122
+ Mustache.any_instance.stub(:render)
123
+ .with(:template, :model).and_return(:content)
124
+ Alephant::Renderer.any_instance.stub(:template)
125
+ .with(id).and_return(:template)
126
+ Alephant::Renderer.any_instance.stub(:model)
127
+ .with(id, :data).and_return(:model)
128
+
129
+ expect(subject.new(id).render(:data)).to eq(:content)
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,4 @@
1
+ $: << File.join(File.dirname(__FILE__),"..", "lib")
2
+
3
+ require 'alephant'
4
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alephant
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: java
6
6
  authors:
7
7
  - Robert Kenny
@@ -38,6 +38,48 @@ dependencies:
38
38
  version: '0'
39
39
  prerelease: false
40
40
  type: :development
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec-nc
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ prerelease: false
54
+ type: :development
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ prerelease: false
68
+ type: :development
69
+ - !ruby/object:Gem::Dependency
70
+ name: guard-rspec
71
+ version_requirements: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirement: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ prerelease: false
82
+ type: :development
41
83
  - !ruby/object:Gem::Dependency
42
84
  name: pry
43
85
  version_requirements: !ruby/object:Gem::Requirement
@@ -90,19 +132,28 @@ files:
90
132
  - .ruby-version
91
133
  - .travis.yml
92
134
  - Gemfile
135
+ - Guardfile
93
136
  - LICENSE
94
137
  - README.md
95
138
  - Rakefile
96
139
  - alephant.gemspec
97
140
  - lib/alephant.rb
141
+ - lib/alephant/errors.rb
142
+ - lib/alephant/errors/invalid_view_path.rb
143
+ - lib/alephant/errors/view_model_not_found.rb
144
+ - lib/alephant/errors/view_template_not_found.rb
98
145
  - lib/alephant/models/cache.rb
99
146
  - lib/alephant/models/renderer.rb
100
147
  - lib/alephant/models/sequencer.rb
148
+ - lib/alephant/util/string.rb
101
149
  - lib/alephant/version.rb
150
+ - lib/alephant/views.rb
151
+ - lib/alephant/views/base.rb
102
152
  - lib/env.rb
103
- - package.py
104
- - project.json
105
- - spec/foo_spec.rb
153
+ - spec/fixtures/views/models/example.rb
154
+ - spec/fixtures/views/templates/example.mustache
155
+ - spec/renderer_spec.rb
156
+ - spec/spec_helper.rb
106
157
  homepage: http://rubygems.org/gems/alephant
107
158
  licenses:
108
159
  - GPLv3
@@ -128,4 +179,7 @@ signing_key:
128
179
  specification_version: 4
129
180
  summary: Static Publishing in the Cloud
130
181
  test_files:
131
- - spec/foo_spec.rb
182
+ - spec/fixtures/views/models/example.rb
183
+ - spec/fixtures/views/templates/example.mustache
184
+ - spec/renderer_spec.rb
185
+ - spec/spec_helper.rb
data/package.py DELETED
@@ -1,71 +0,0 @@
1
- from subprocess import check_call as call
2
- import tempfile
3
-
4
- def package(builder):
5
-
6
- name = builder.name
7
- jruby_version = builder.metadata["packaging"]["jruby_version"]
8
- install_path = "/usr/lib/{0}".format(builder.name)
9
-
10
- tmpdir = tempfile.mkdtemp()
11
-
12
- def install_jruby():
13
-
14
- url = "http://jruby.org.s3.amazonaws.com/downloads/{0}/jruby-bin-{0}.tar.gz".format(jruby_version)
15
- package_path = "{0}/jruby-bin-{1}.tar.gz".format(tmpdir, jruby_version)
16
-
17
- print "Downloading JRuby {0}".format(jruby_version)
18
- call(["/usr/bin/curl", "--progress-bar", "-L", url, "-o", package_path])
19
-
20
- print "Extracting {0}".format(package_path)
21
- call(["tar", "zxf", package_path, "-C", tmpdir])
22
-
23
- def create_jar():
24
- gem_bin = "{0}/jruby-{1}/bin/gem".format(tmpdir, jruby_version)
25
- jruby_bin = "{0}/jruby-{1}/bin/jruby".format(tmpdir, jruby_version)
26
- # gem_home = "{0}/jruby-{1}/lib/ruby/gems/shared".format(tmpdir, jruby_version)
27
-
28
- # print "Installing bundler: {0}".format(gem_bin)
29
- call([jruby_bin, gem_bin, "install", "bundler", "--install-dir", ".gem"])
30
- call([jruby_bin, "-e", "ENV['GEM_HOME']=File.join(Dir.pwd,'.gem');ENV['GEM_PATH']=File.join(Dir.pwd,'.gem');ENV['BUNDLE_GEMFILE']=File.join(Dir.pwd,'Gemfile');require'rubygems';require'bundler';require'bundler/cli';cli=Bundler::CLI.start"])
31
- call([jruby_bin, "-e", "ENV['GEM_HOME']=File.join(Dir.pwd,'.gem');ENV['GEM_PATH']=File.join(Dir.pwd,'.gem');ENV['BUNDLE_GEMFILE']=File.join(Dir.pwd,'Gemfile');require'rubygems';require'warbler';Dir.mkdir('target');Warbler::Application.new.run;"])
32
-
33
-
34
- def setup_dependencies():
35
- builder.spec.set_build_arch('x86_64')
36
-
37
- builder.spec.add_build_requires([
38
- 'cosmos-ca-tools'
39
- ])
40
-
41
- def user():
42
- builder.spec.add_pre_steps([
43
- ["groupadd -r {0}".format(name)],
44
- ["useradd -r -g {0} -G {0} -d / -s /sbin/nologin -c \"{0} ruby service\" {0}".format(name)]
45
- ])
46
-
47
- def set_perms():
48
- builder.spec.add_pre_steps([
49
- ["chown -R {0}:{0}".format(name)],
50
- ["chmod 744 {0}".format(install_path)]
51
- ])
52
-
53
- def setup_bundler():
54
- builder.spec.add_post_steps([
55
- ['/opt/jruby/bin/gem install bundler --no-ri --no-rdoc']
56
- ])
57
-
58
- def install_gems():
59
- builder.spec.add_post_steps([[
60
- "GEM_HOME=/opt/jruby/lib/ruby/gems/shared",
61
- "BUNDLE_GEMFILE={0}/Gemfile".format(install_path),
62
- "/opt/jruby/bin/jruby -e \"require 'bundler/cli'; Bundler::CLI.start\""]
63
- ])
64
-
65
- install_jruby()
66
- create_jar()
67
-
68
- setup_dependencies()
69
- user()
70
- setup_bundler()
71
- install_gems()
data/project.json DELETED
@@ -1,11 +0,0 @@
1
- {
2
- "name": "S3-Render",
3
- "packaging": {
4
- "type": "custom_service",
5
- "application_port": 7080,
6
- "jruby_version": "1.7.9",
7
- "requires": [
8
- "jruby"
9
- ]
10
- }
11
- }
data/spec/foo_spec.rb DELETED
@@ -1,5 +0,0 @@
1
- describe "a test that fails" do
2
- it "fails so hard" do
3
- fail
4
- end
5
- end