tramway-core 1.6.4 → 1.7

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
  SHA256:
3
- metadata.gz: a7a31d83fb7b26555a3b8576ca1b95e411be1b37cdf17a06fd799e2a07623201
4
- data.tar.gz: 0f6f62ec9a9e36575747947c55932dedbab9292c77e05012d5dd66020f29aa8d
3
+ metadata.gz: 5d7036cd15efb8465dd098b71750d1b38767611545fe8a58796030a7670db1f2
4
+ data.tar.gz: 1f12dad57781d6604b1c28f78a9ba9612561f0ca16154a2ade685f60f4ff42c4
5
5
  SHA512:
6
- metadata.gz: 6d5166de9d1a332ccc120d027d6563c93fcbdbb499236bf01e8019add7cdb3900e72c3551a5c0761fcd0b0f1169b1511a24e5d1c13fa9149cc078bc4f0283b55
7
- data.tar.gz: ffa7418423d002e5efb9809db865bdcd6132d92485968f79876ba729bcfc1f05d5c0ad41f1f2236e0c6e9c127b41e29b9f02ea7093a933e42249cc09b05d48d5
6
+ metadata.gz: 34cb3bab7fbcc827765b97f944484212a2a3706d5abdac64dcd4cf14425478af4fefd24ff239685b466eac760379ae9a8c641a176151878c15161a985544e507
7
+ data.tar.gz: f266e1d01de459a2e73e9025daff5540c961bcec2911458006c4595c8f1360cee29bed82e3e7ea497eb7aa8abdc6eb4d217a1011fd40e1117f0be925b2c00dd2
@@ -1,21 +1,30 @@
1
1
  class Tramway::Core::ExtendableForm
2
2
  class << self
3
- def new(name, **more_properties)
3
+ def new(name, simple_properties: {}, **more_properties)
4
4
  if Object.const_defined? name
5
5
  name.constantize
6
6
  else
7
7
  Object.const_set(name, Class.new(::Tramway::Core::ApplicationForm) do
8
+ properties(*simple_properties.keys) if simple_properties.keys.any?
9
+
8
10
  define_method 'submit' do |params|
9
11
  model.values ||= {}
10
- model.values = params.permit!.to_h.reduce({}) do |hash, pair|
12
+ extended_params = params.except(*simple_properties.keys)
13
+ model.values = extended_params.permit!.to_h.reduce(model.values) do |hash, pair|
11
14
  hash.merge! pair[0] => pair[1]
12
15
  end
13
16
  super params
14
17
  end
15
18
 
16
19
  define_method 'properties' do
17
- more_properties.reduce({}) do |hash, property|
18
- hash.merge! property[0] => {
20
+ hash = simple_properties.reduce({}) do |h, property|
21
+ unless model.class.state_machines.keys.include?(property[0])
22
+ h.merge! property[0] => property[1]
23
+ end
24
+ h
25
+ end
26
+ more_properties.reduce(hash) do |h, property|
27
+ h.merge! property[0] => {
19
28
  extended_form_property: property[1]
20
29
  }
21
30
  end
@@ -6,8 +6,8 @@
6
6
  - else
7
7
  = f.input field.title.to_sym, as: field.field_type, input_html: { class: class_name, id: "#{class_name}_#{field.title}", name: "#{class_name}[#{field.title}]" }
8
8
  - when 'select'
9
- - parsed_json = JSON.parse(field.options) unless field.options == ''
10
- - if parsed_json && parsed_json['collection']['name']
9
+ - parsed_json = field.options.is_a?(Hash) ? field.options : (JSON.parse(field.options) unless field.options == '')
10
+ - if parsed_json && parsed_json.dig('collection', 'name')
11
11
  - if value.present?
12
12
  = f.input field.title.to_sym, as: :select, collection: collection_list_by(name: parsed_json['collection']['name']), input_html: { class: class_name, id: "#{class_name}_#{field.title}", name: "#{class_name}[#{field.title}]" }, selected: value
13
13
  - else
@@ -1,5 +1,5 @@
1
1
  module Tramway
2
2
  module Core
3
- VERSION = '1.6.4'
3
+ VERSION = '1.7'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tramway-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.4
4
+ version: '1.7'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Kalashnikov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-07 00:00:00.000000000 Z
11
+ date: 2018-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: reform-rails