radar-app 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -1
- data/.rspec +1 -0
- data/README.md +1 -0
- data/lib/radar-app.rb +1 -0
- data/lib/radar/app.rb +1 -1
- data/lib/radar/app/version.rb +1 -1
- data/lib/thrift/builder.rb +36 -0
- data/spec/example.thrift +19 -0
- data/spec/gen-rb/example_constants.rb +9 -0
- data/spec/gen-rb/example_types.rb +66 -0
- data/spec/lib/thrift/builder_spec.rb +36 -0
- data/templates/analyzers/analyzer.rb.erb +13 -5
- data/templates/config/app.rb +1 -0
- metadata +14 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8077f6b19cc433e1198234acecc5530f2924cad
|
4
|
+
data.tar.gz: db68706cf9312353688b89776c8b66ec8431ad02
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84f92d0b169a92324130d3849ee11ed697c1fc63fc708def3f3d1d1bea4ae2d985d87034a2dfedf1b5e9996e39b8345d9f65573c485e8f3b0943c3981c7cc518
|
7
|
+
data.tar.gz: 00d99b8f78970d34a40a0b5dc37ec827fd1dd75f296a311588605e7f5ccc6258315fe1a082ad10c9e8efe13a72e4bac45d5c0f4363a9bcd121f67e2c1d26d269
|
data/.gitignore
CHANGED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# Radar::App
|
2
2
|
|
3
3
|
[![Build Status](https://travis-ci.org/investtools/radar-app.svg)](https://travis-ci.org/investtools/radar-app)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/investtools/radar-app.png)](https://codeclimate.com/github/investtools/radar-app)
|
4
5
|
|
5
6
|
Radar::App é um framework para criação de apps para o Radar.
|
6
7
|
|
data/lib/radar-app.rb
CHANGED
data/lib/radar/app.rb
CHANGED
data/lib/radar/app/version.rb
CHANGED
@@ -0,0 +1,36 @@
|
|
1
|
+
module Thrift
|
2
|
+
class Builder
|
3
|
+
def initialize(clazz)
|
4
|
+
@class = clazz
|
5
|
+
end
|
6
|
+
|
7
|
+
def build(attributes)
|
8
|
+
@class.new.tap do |obj|
|
9
|
+
attributes.each do |attribute, value|
|
10
|
+
obj.send "#{attribute}=", build_attr(@class::FIELDS[obj.name_to_id(attribute.to_s)], value)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
protected
|
16
|
+
|
17
|
+
def build_attr(field, value)
|
18
|
+
case field[:type]
|
19
|
+
when Thrift::Types::STRUCT
|
20
|
+
Builder.new(field[:class]).build(value)
|
21
|
+
when Thrift::Types::LIST
|
22
|
+
value.map { |child| build_attr(field[:element], child) }
|
23
|
+
when Thrift::Types::SET
|
24
|
+
value.map { |child| build_attr(field[:element], child) }.to_set
|
25
|
+
when Thrift::Types::I32
|
26
|
+
if field.include?(:enum_class)
|
27
|
+
field[:enum_class].const_get(value.upcase)
|
28
|
+
else
|
29
|
+
value
|
30
|
+
end
|
31
|
+
else
|
32
|
+
value
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/spec/example.thrift
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
enum Gender {
|
2
|
+
MALE, FEMALE
|
3
|
+
}
|
4
|
+
|
5
|
+
struct PhoneNumber {
|
6
|
+
1: string contry_code
|
7
|
+
2: string area_code
|
8
|
+
3: string number
|
9
|
+
}
|
10
|
+
|
11
|
+
struct Person {
|
12
|
+
1: string name
|
13
|
+
2: PhoneNumber phone
|
14
|
+
3: list<Person> children
|
15
|
+
4: list<string> notes
|
16
|
+
5: Gender gender
|
17
|
+
6: i32 age
|
18
|
+
7: set<i32> favorite_numbers
|
19
|
+
}
|
@@ -0,0 +1,66 @@
|
|
1
|
+
#
|
2
|
+
# Autogenerated by Thrift Compiler (0.9.3)
|
3
|
+
#
|
4
|
+
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
|
5
|
+
#
|
6
|
+
|
7
|
+
require 'thrift'
|
8
|
+
|
9
|
+
module Gender
|
10
|
+
MALE = 0
|
11
|
+
FEMALE = 1
|
12
|
+
VALUE_MAP = {0 => "MALE", 1 => "FEMALE"}
|
13
|
+
VALID_VALUES = Set.new([MALE, FEMALE]).freeze
|
14
|
+
end
|
15
|
+
|
16
|
+
class PhoneNumber
|
17
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
18
|
+
CONTRY_CODE = 1
|
19
|
+
AREA_CODE = 2
|
20
|
+
NUMBER = 3
|
21
|
+
|
22
|
+
FIELDS = {
|
23
|
+
CONTRY_CODE => {:type => ::Thrift::Types::STRING, :name => 'contry_code'},
|
24
|
+
AREA_CODE => {:type => ::Thrift::Types::STRING, :name => 'area_code'},
|
25
|
+
NUMBER => {:type => ::Thrift::Types::STRING, :name => 'number'}
|
26
|
+
}
|
27
|
+
|
28
|
+
def struct_fields; FIELDS; end
|
29
|
+
|
30
|
+
def validate
|
31
|
+
end
|
32
|
+
|
33
|
+
::Thrift::Struct.generate_accessors self
|
34
|
+
end
|
35
|
+
|
36
|
+
class Person
|
37
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
38
|
+
NAME = 1
|
39
|
+
PHONE = 2
|
40
|
+
CHILDREN = 3
|
41
|
+
NOTES = 4
|
42
|
+
GENDER = 5
|
43
|
+
AGE = 6
|
44
|
+
FAVORITE_NUMBERS = 7
|
45
|
+
|
46
|
+
FIELDS = {
|
47
|
+
NAME => {:type => ::Thrift::Types::STRING, :name => 'name'},
|
48
|
+
PHONE => {:type => ::Thrift::Types::STRUCT, :name => 'phone', :class => ::PhoneNumber},
|
49
|
+
CHILDREN => {:type => ::Thrift::Types::LIST, :name => 'children', :element => {:type => ::Thrift::Types::STRUCT, :class => ::Person}},
|
50
|
+
NOTES => {:type => ::Thrift::Types::LIST, :name => 'notes', :element => {:type => ::Thrift::Types::STRING}},
|
51
|
+
GENDER => {:type => ::Thrift::Types::I32, :name => 'gender', :enum_class => ::Gender},
|
52
|
+
AGE => {:type => ::Thrift::Types::I32, :name => 'age'},
|
53
|
+
FAVORITE_NUMBERS => {:type => ::Thrift::Types::SET, :name => 'favorite_numbers', :element => {:type => ::Thrift::Types::I32}}
|
54
|
+
}
|
55
|
+
|
56
|
+
def struct_fields; FIELDS; end
|
57
|
+
|
58
|
+
def validate
|
59
|
+
unless @gender.nil? || ::Gender::VALID_VALUES.include?(@gender)
|
60
|
+
raise ::Thrift::ProtocolException.new(::Thrift::ProtocolException::UNKNOWN, 'Invalid value of field gender!')
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
::Thrift::Struct.generate_accessors self
|
65
|
+
end
|
66
|
+
|
@@ -0,0 +1,36 @@
|
|
1
|
+
$:.unshift File.expand_path('../../../gen-rb', __FILE__)
|
2
|
+
|
3
|
+
require 'thrift/builder'
|
4
|
+
require 'example_types'
|
5
|
+
|
6
|
+
describe Thrift::Builder do
|
7
|
+
describe '#build' do
|
8
|
+
it 'builds a object of type defined by constructor' do
|
9
|
+
expect(Thrift::Builder.new(Person).build({})).to be_kind_of(Person)
|
10
|
+
end
|
11
|
+
it 'sets basic attributes' do
|
12
|
+
expect(Thrift::Builder.new(Person).build(name: 'Andre').name).to eq 'Andre'
|
13
|
+
end
|
14
|
+
it 'sets nested objects' do
|
15
|
+
expect(Thrift::Builder.new(Person).build(phone: {}).phone).to be_kind_of(PhoneNumber)
|
16
|
+
end
|
17
|
+
it 'sets nested objects attributes' do
|
18
|
+
expect(Thrift::Builder.new(Person).build(phone: {contry_code: '55'}).phone.contry_code).to eq '55'
|
19
|
+
end
|
20
|
+
it 'sets nested objects inside arrays' do
|
21
|
+
expect(Thrift::Builder.new(Person).build(children: [ { name: 'Helena' } ]).children.first.name).to eq 'Helena'
|
22
|
+
end
|
23
|
+
it 'sets basic attributes inside arrays' do
|
24
|
+
expect(Thrift::Builder.new(Person).build(notes: [ 'test' ]).notes).to eq [ 'test' ]
|
25
|
+
end
|
26
|
+
it 'sets enum attributes' do
|
27
|
+
expect(Thrift::Builder.new(Person).build(gender: :male).gender).to eq Gender::MALE
|
28
|
+
end
|
29
|
+
it 'sets i32 attributes' do
|
30
|
+
expect(Thrift::Builder.new(Person).build(age: 34).age).to eq 34
|
31
|
+
end
|
32
|
+
it 'sets set attributes' do
|
33
|
+
expect(Thrift::Builder.new(Person).build(favorite_numbers: [7, 10]).favorite_numbers).to eq Set.new([7, 10])
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -3,25 +3,33 @@ require 'radar-api'
|
|
3
3
|
class <%= @class_name %>
|
4
4
|
|
5
5
|
def config
|
6
|
-
Radar::API::AnalyzerConfig.
|
7
|
-
|
8
|
-
|
6
|
+
Thrift::Builder.new(Radar::API::AnalyzerConfig).build(
|
7
|
+
id: '<%= @class_name %>',
|
8
|
+
name: '<%= @class_name %>',
|
9
|
+
result_type: :table,
|
10
|
+
accepted_events: [:each_day, :each_month, :finish]
|
9
11
|
)
|
10
12
|
end
|
11
13
|
|
12
14
|
def on_each_day(portfolio)
|
13
15
|
end
|
14
16
|
|
17
|
+
def on_month_day(portfolio)
|
18
|
+
end
|
19
|
+
|
15
20
|
def on_finish(portfolio)
|
16
21
|
end
|
17
22
|
|
18
|
-
def dump
|
23
|
+
def dump
|
19
24
|
end
|
20
25
|
|
21
26
|
def resume(data)
|
22
27
|
end
|
23
28
|
|
24
|
-
def
|
29
|
+
def example_result
|
30
|
+
end
|
31
|
+
|
32
|
+
def result
|
25
33
|
end
|
26
34
|
|
27
35
|
end
|
data/templates/config/app.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: radar-app
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Leonardo Mendonca
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2016-08-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -160,6 +160,7 @@ extensions: []
|
|
160
160
|
extra_rdoc_files: []
|
161
161
|
files:
|
162
162
|
- .gitignore
|
163
|
+
- .rspec
|
163
164
|
- Gemfile
|
164
165
|
- Guardfile
|
165
166
|
- LICENSE.txt
|
@@ -182,8 +183,13 @@ files:
|
|
182
183
|
- lib/radar/app/tasks/new.rb
|
183
184
|
- lib/radar/app/tasks/server.rb
|
184
185
|
- lib/radar/app/version.rb
|
186
|
+
- lib/thrift/builder.rb
|
185
187
|
- radar-app.gemspec
|
188
|
+
- spec/example.thrift
|
189
|
+
- spec/gen-rb/example_constants.rb
|
190
|
+
- spec/gen-rb/example_types.rb
|
186
191
|
- spec/lib/radar/app/tasks/generate_spec.rb
|
192
|
+
- spec/lib/thrift/builder_spec.rb
|
187
193
|
- templates/.webhook
|
188
194
|
- templates/Gemfile
|
189
195
|
- templates/Procfile
|
@@ -210,9 +216,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
210
216
|
version: '0'
|
211
217
|
requirements: []
|
212
218
|
rubyforge_project:
|
213
|
-
rubygems_version: 2.
|
219
|
+
rubygems_version: 2.2.2
|
214
220
|
signing_key:
|
215
221
|
specification_version: 4
|
216
222
|
summary: radar-app generator
|
217
223
|
test_files:
|
224
|
+
- spec/example.thrift
|
225
|
+
- spec/gen-rb/example_constants.rb
|
226
|
+
- spec/gen-rb/example_types.rb
|
218
227
|
- spec/lib/radar/app/tasks/generate_spec.rb
|
228
|
+
- spec/lib/thrift/builder_spec.rb
|
229
|
+
has_rdoc:
|