forest_liana 1.1.20 → 1.1.22

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9ddcfda22c4ff09d0c572f50c1f9b915aaf2c594
4
- data.tar.gz: 6e446ba8d2b87adbeaf577b444d9aa3bb962fdd7
3
+ metadata.gz: 21865b20b7689f8391863232851fae17d931a22f
4
+ data.tar.gz: f9fc1e5fcaee763363eb1cf08f938f729e34a4fa
5
5
  SHA512:
6
- metadata.gz: de6db21eb97e3be4c111d451df11fc8e16a70047bb7caa127206a6498128ced2310e4d4926d5a9a2556de2daab19c25f064ede67b8cd89299cef5877198feeb4
7
- data.tar.gz: 821e98ce6b1e834d42e86b38e39132b764b5a956919628e257ba92308a50e160921d99a5f5553d9176a2cacaead96133f66ade8b76edd185d9abbc3387a60f7a
6
+ metadata.gz: 59ea6edeb1719c0f12cc49a99610cbd2ce5117d9347569602814c8efe7f3bc87c4af283ed570bc1d5a82c8a00a3593f6766188de8e9c736bf2aa3d37a771aa95
7
+ data.tar.gz: be1c07ed787bee9dfcbf38a7153d7c624afb280c7cb8c36601de06c60377bb07b3dd6863effb233c3e32d83e4814c139ed2eae21d2942ce5df1b6a8680e65a3e
@@ -10,7 +10,7 @@ module ForestLiana
10
10
  result << SchemaAdapter.new(model).perform if model.try(:table_exists?)
11
11
  end
12
12
 
13
- render json: serialize_models(result, serializer: ApimapSerializer)
13
+ render json: serialize_models(result)
14
14
  end
15
15
  end
16
16
  end
@@ -0,0 +1,22 @@
1
+ class ForestLiana::Model::Action
2
+ include ActiveModel::Validations
3
+ include ActiveModel::Conversion
4
+ include ActiveModel::Serialization
5
+ extend ActiveModel::Naming
6
+
7
+ attr_accessor :name, :endpoint, :http_method, :fields
8
+
9
+ def initialize(attributes = {})
10
+ attributes.each do |name, value|
11
+ send("#{name}=", value)
12
+ end
13
+ end
14
+
15
+ def persisted?
16
+ false
17
+ end
18
+
19
+ def id
20
+ name
21
+ end
22
+ end
@@ -0,0 +1,24 @@
1
+ class ForestLiana::Model::Collection
2
+ include ActiveModel::Validations
3
+ include ActiveModel::Conversion
4
+ include ActiveModel::Serialization
5
+ extend ActiveModel::Naming
6
+
7
+ attr_accessor :name, :fields, :actions
8
+
9
+ def initialize(attributes = {})
10
+ @actions = []
11
+
12
+ attributes.each do |name, value|
13
+ send("#{name}=", value)
14
+ end
15
+ end
16
+
17
+ def persisted?
18
+ false
19
+ end
20
+
21
+ def id
22
+ name
23
+ end
24
+ end
@@ -0,0 +1,22 @@
1
+ class ForestLiana::Model::Stat
2
+ include ActiveModel::Validations
3
+ include ActiveModel::Conversion
4
+ include ActiveModel::Serialization
5
+ extend ActiveModel::Naming
6
+
7
+ attr_accessor :value
8
+
9
+ def initialize(attributes = {})
10
+ attributes.each do |name, value|
11
+ send("#{name}=", value)
12
+ end
13
+ end
14
+
15
+ def persisted?
16
+ false
17
+ end
18
+
19
+ def id
20
+ SecureRandom.uuid
21
+ end
22
+ end
@@ -0,0 +1,18 @@
1
+ require 'jsonapi-serializers'
2
+
3
+ class ForestLiana::ActionSerializer
4
+ include JSONAPI::Serializer
5
+
6
+ attribute :name
7
+ attribute :http_method
8
+ attribute :endpoint
9
+ attribute :fields
10
+
11
+ def relationship_related_link(attribute_name)
12
+ nil
13
+ end
14
+
15
+ def relationship_self_link(attribute_name)
16
+ nil
17
+ end
18
+ end
@@ -0,0 +1,20 @@
1
+ require 'jsonapi-serializers'
2
+
3
+ class ForestLiana::CollectionSerializer
4
+ include JSONAPI::Serializer
5
+
6
+ attribute :name
7
+ attribute :fields
8
+
9
+ has_many :actions do
10
+ object.actions
11
+ end
12
+
13
+ def relationship_related_link(attribute_name)
14
+ nil
15
+ end
16
+
17
+ def relationship_self_link(attribute_name)
18
+ nil
19
+ end
20
+ end
@@ -20,10 +20,12 @@ module ForestLiana
20
20
  "ForestLiana::StripeCardSerializer"
21
21
  elsif active_record_class == Stripe::Invoice
22
22
  "ForestLiana::StripeInvoiceSerializer"
23
- elsif active_record_class == ForestLiana::Stat
23
+ elsif active_record_class == ForestLiana::Model::Stat
24
24
  "ForestLiana::StatSerializer"
25
- elsif active_record_class == ForestLiana::Collection
26
- "ForestLiana::ApimapSerializer"
25
+ elsif active_record_class == ForestLiana::Model::Collection
26
+ "ForestLiana::CollectionSerializer"
27
+ elsif active_record_class == ForestLiana::Model::Action
28
+ "ForestLiana::ActionSerializer"
27
29
  else
28
30
  class_name = active_record_class.table_name.classify
29
31
  module_name = class_name.deconstantize
@@ -0,0 +1,27 @@
1
+ class ForestLiana::Collection
2
+ mattr_accessor :collection_name
3
+
4
+ def self.fields(fields)
5
+ collection = ForestLiana::Model::Collection.new({
6
+ name: self.collection_name,
7
+ fields: fields
8
+ })
9
+
10
+ ForestLiana.apimap << collection
11
+ end
12
+
13
+ def self.action(name, opts = {})
14
+ collection = ForestLiana.apimap.find do |x|
15
+ x.name == self.collection_name.try(:to_s)
16
+ end
17
+
18
+ return if collection.blank?
19
+
20
+ collection.actions << ForestLiana::Model::Action.new({
21
+ name: name,
22
+ http_method: opts[:http_method],
23
+ endpoint: opts[:endpoint],
24
+ fields: opts[:fields]
25
+ })
26
+ end
27
+ end
@@ -40,7 +40,7 @@ module ForestLiana
40
40
  end
41
41
  end
42
42
 
43
- @record = Stat.new(value: value)
43
+ @record = Model::Stat.new(value: value)
44
44
  end
45
45
 
46
46
  private
@@ -24,7 +24,7 @@ module ForestLiana
24
24
  { key: k, value: v }
25
25
  end
26
26
 
27
- @record = Stat.new(value: value)
27
+ @record = Model::Stat.new(value: value)
28
28
  end
29
29
  end
30
30
 
@@ -5,7 +5,7 @@ module ForestLiana
5
5
  end
6
6
 
7
7
  def perform
8
- @collection = ForestLiana::Collection.new({
8
+ @collection = ForestLiana::Model::Collection.new({
9
9
  name: @model.name.tableize,
10
10
  fields: []
11
11
  })
@@ -17,7 +17,7 @@ module ForestLiana
17
17
  filter_value)
18
18
  end
19
19
 
20
- @record = Stat.new(value: count(value))
20
+ @record = Model::Stat.new(value: count(value))
21
21
  end
22
22
 
23
23
  private
data/lib/forest_liana.rb CHANGED
@@ -1,4 +1,4 @@
1
- require "forest_liana/engine"
1
+ require 'forest_liana/engine'
2
2
 
3
3
  module ForestLiana
4
4
  mattr_accessor :jwt_signing_key
@@ -9,10 +9,6 @@ module ForestLiana
9
9
  isolate_namespace ForestLiana
10
10
  logger = Logger.new(STDOUT)
11
11
 
12
- initializer 'forest_liana.require_all' do |app|
13
- Dir["#{app.root}/app/models/forest/*.rb"].each {|file| require file }
14
- end
15
-
16
12
  config.middleware.insert_before 0, 'Rack::Cors' do
17
13
  allow do
18
14
  origins 'http://localhost:4200', 'https://www.forestadmin.com',
@@ -21,7 +17,7 @@ module ForestLiana
21
17
  end
22
18
  end
23
19
 
24
- config.after_initialize do
20
+ config.after_initialize do |app|
25
21
  unless Rails.env.test?
26
22
  SchemaUtils.tables_names.map do |table_name|
27
23
  model = SchemaUtils.find_model_from_table_name(table_name)
@@ -48,10 +44,13 @@ module ForestLiana
48
44
  end
49
45
  end
50
46
 
47
+ Dir["#{app.root}/app/models/forest/*.rb"].each {|file| require file }
48
+
51
49
  liana_version = Gem::Specification.find_by_name('forest_liana')
52
50
  .version.to_s
53
51
  json = JSONAPI::Serializer.serialize(ForestLiana.apimap, {
54
52
  is_collection: true,
53
+ include: ['actions'],
55
54
  meta: { liana: 'forest-rails', liana_version: liana_version }
56
55
  })
57
56
 
@@ -1,3 +1,3 @@
1
1
  module ForestLiana
2
- VERSION = "1.1.20"
2
+ VERSION = "1.1.22"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forest_liana
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.20
4
+ version: 1.1.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sandro Munda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-23 00:00:00.000000000 Z
11
+ date: 2015-12-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -129,14 +129,17 @@ files:
129
129
  - app/controllers/forest_liana/stripe_controller.rb
130
130
  - app/deserializers/forest_liana/resource_deserializer.rb
131
131
  - app/helpers/forest_liana/application_helper.rb
132
- - app/models/forest_liana/collection.rb
133
- - app/models/forest_liana/stat.rb
134
- - app/serializers/forest_liana/apimap_serializer.rb
132
+ - app/models/forest_liana/model/action.rb
133
+ - app/models/forest_liana/model/collection.rb
134
+ - app/models/forest_liana/model/stat.rb
135
+ - app/serializers/forest_liana/action_serializer.rb
136
+ - app/serializers/forest_liana/collection_serializer.rb
135
137
  - app/serializers/forest_liana/serializer_factory.rb
136
138
  - app/serializers/forest_liana/stat_serializer.rb
137
139
  - app/serializers/forest_liana/stripe_card_serializer.rb
138
140
  - app/serializers/forest_liana/stripe_invoice_serializer.rb
139
141
  - app/serializers/forest_liana/stripe_payment_serializer.rb
142
+ - app/services/forest_liana/collection.rb
140
143
  - app/services/forest_liana/has_many_getter.rb
141
144
  - app/services/forest_liana/line_stat_getter.rb
142
145
  - app/services/forest_liana/operator_value_parser.rb
@@ -147,7 +150,6 @@ files:
147
150
  - app/services/forest_liana/schema_adapter.rb
148
151
  - app/services/forest_liana/schema_utils.rb
149
152
  - app/services/forest_liana/search_query_builder.rb
150
- - app/services/forest_liana/smart_collection.rb
151
153
  - app/services/forest_liana/stripe_cards_getter.rb
152
154
  - app/services/forest_liana/stripe_invoices_getter.rb
153
155
  - app/services/forest_liana/stripe_payment_refunder.rb
@@ -1,26 +0,0 @@
1
- module ForestLiana
2
- class Collection
3
-
4
- include ActiveModel::Validations
5
- include ActiveModel::Conversion
6
- include ActiveModel::Serialization
7
- extend ActiveModel::Naming
8
-
9
- attr_accessor :name, :fields
10
-
11
- def initialize(attributes = {})
12
- attributes.each do |name, value|
13
- send("#{name}=", value)
14
- end
15
- end
16
-
17
- def persisted?
18
- false
19
- end
20
-
21
- def id
22
- name
23
- end
24
-
25
- end
26
- end
@@ -1,26 +0,0 @@
1
- module ForestLiana
2
- class Stat
3
-
4
- include ActiveModel::Validations
5
- include ActiveModel::Conversion
6
- include ActiveModel::Serialization
7
- extend ActiveModel::Naming
8
-
9
- attr_accessor :value
10
-
11
- def initialize(attributes = {})
12
- attributes.each do |name, value|
13
- send("#{name}=", value)
14
- end
15
- end
16
-
17
- def persisted?
18
- false
19
- end
20
-
21
- def id
22
- SecureRandom.uuid
23
- end
24
-
25
- end
26
- end
@@ -1,10 +0,0 @@
1
- require 'jsonapi-serializers'
2
-
3
- module ForestLiana
4
- class ApimapSerializer
5
- include JSONAPI::Serializer
6
-
7
- attribute :name
8
- attribute :fields
9
- end
10
- end
@@ -1,12 +0,0 @@
1
- module ForestLiana
2
- class SmartCollection
3
- def self.register(name, opts)
4
- smartCollection = ForestLiana::Collection.new({
5
- name: name,
6
- fields: opts[:fields]
7
- })
8
-
9
- ForestLiana.apimap << smartCollection
10
- end
11
- end
12
- end