ciesta 0.2.2 → 0.2.3

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: 7e68ef3d47949c3fa6788ae15a08f5fa76078401cc2423bea094658486a1ec7b
4
- data.tar.gz: f64ad04746e5acccddceb91442663e633cb3e46357311b35bf09499416ff80d4
3
+ metadata.gz: 686725e6d7930c99dafab26c796538ac28410261704491f9f676bb2204950481
4
+ data.tar.gz: 16b64dd435105dcc1a66c778e4cd321137b47d4859588a1b9c5f4d19ae7c4e42
5
5
  SHA512:
6
- metadata.gz: 2b39a7a1f8a9b5b9624e7681e59f2398aa40be9b86dd4c1d5848776a62b4e9e399799aee207461c8daa9ef73458a06da2444c2c0e923a851eb55eb01676ce545
7
- data.tar.gz: eaee3b3910b0fe808289e43ecc2707e07b91c50dd44d9072cd3c8e540882cc0594c16745aff680e9a55105667df65aec58dfada19f2ac051fa51aee9baf38894
6
+ metadata.gz: 12cce79f11ee00426ad3675c2bb1506a28b526ab0b565dae0719945661261c9d62fe6c01210f2d68697b595e174fc1c4e6f015d823adae3cf9a9ab83c63a73f9
7
+ data.tar.gz: 5b98c72dd163212fdea889553d501f486df12ddc7dfcd3ba73d6e09aae4e9d11afd0a61b0a1f5927fc0fd4fcbe4c937aef9ed5413b174d18923b9a07a25a9598
@@ -1,14 +1,48 @@
1
- inherit_gem:
2
- rubocop-config-umbrellio: lib/rubocop.rails.yml
3
-
4
1
  AllCops:
5
2
  TargetRubyVersion: 2.1
6
3
  Exclude:
7
4
  - db/schema.rb
8
- - ciesta.gemspec
5
+ - config/**/*.rb
6
+
7
+ # Metrics
8
+ Metrics/CyclomaticComplexity:
9
+ Enabled: true
10
+ Max: 6
9
11
 
10
12
  Metrics/LineLength:
13
+ Enabled: true
14
+ Max: 100
15
+ AllowHeredoc: true
11
16
  IgnoredPatterns: ['#.*']
12
17
 
13
- Rails/SaveBang:
18
+ Metrics/BlockLength:
19
+ Enabled: false
20
+
21
+ Metrics/MethodLength:
22
+ Enabled: false
23
+
24
+ Metrics/AbcSize:
25
+ Enabled: false
26
+
27
+ # Style
28
+ Style/StringLiterals:
29
+ Enabled: false
30
+
31
+ Style/Documentation:
32
+ Enabled: false
33
+
34
+ Style/ClassAndModuleChildren:
35
+ Enabled: false
36
+
37
+ Style/FrozenStringLiteralComment:
38
+ Enabled: false
39
+
40
+ Style/RegexpLiteral:
41
+ Enabled: false
42
+
43
+ # Lint
44
+ Lint/AmbiguousOperator:
45
+ Enabled: false
46
+
47
+ Lint/AmbiguousBlockAssociation:
14
48
  Enabled: false
@@ -1,13 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ciesta (0.2.1)
4
+ ciesta (0.2.3)
5
5
  dry-types (~> 0.12.1)
6
6
  dry-validation (~> 0.11.1)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
+ ast (2.4.0)
11
12
  coderay (1.1.2)
12
13
  concurrent-ruby (1.0.5)
13
14
  coveralls (0.8.21)
@@ -23,7 +24,7 @@ GEM
23
24
  dry-container (0.6.0)
24
25
  concurrent-ruby (~> 1.0)
25
26
  dry-configurable (~> 0.1, >= 0.1.3)
26
- dry-core (0.4.4)
27
+ dry-core (0.4.5)
27
28
  concurrent-ruby (~> 1.0)
28
29
  dry-equalizer (0.2.0)
29
30
  dry-logic (0.4.2)
@@ -48,9 +49,14 @@ GEM
48
49
  inflecto (0.0.2)
49
50
  json (2.1.0)
50
51
  method_source (0.9.0)
52
+ parallel (1.12.1)
53
+ parser (2.5.0.4)
54
+ ast (~> 2.4.0)
55
+ powerpack (0.1.1)
51
56
  pry (0.11.3)
52
57
  coderay (~> 1.1.0)
53
58
  method_source (~> 0.9.0)
59
+ rainbow (3.0.0)
54
60
  rake (10.5.0)
55
61
  rspec (3.7.0)
56
62
  rspec-core (~> 3.7.0)
@@ -65,6 +71,14 @@ GEM
65
71
  diff-lcs (>= 1.2.0, < 2.0)
66
72
  rspec-support (~> 3.7.0)
67
73
  rspec-support (3.7.1)
74
+ rubocop (0.54.0)
75
+ parallel (~> 1.10)
76
+ parser (>= 2.5)
77
+ powerpack (~> 0.1)
78
+ rainbow (>= 2.2.2, < 4.0)
79
+ ruby-progressbar (~> 1.7)
80
+ unicode-display_width (~> 1.0, >= 1.0.1)
81
+ ruby-progressbar (1.9.0)
68
82
  simplecov (0.14.1)
69
83
  docile (~> 1.1.0)
70
84
  json (>= 1.8, < 3)
@@ -74,6 +88,7 @@ GEM
74
88
  tins (~> 1.0)
75
89
  thor (0.19.4)
76
90
  tins (1.16.3)
91
+ unicode-display_width (1.3.0)
77
92
 
78
93
  PLATFORMS
79
94
  ruby
@@ -85,6 +100,7 @@ DEPENDENCIES
85
100
  pry (~> 0.11)
86
101
  rake (~> 10.0)
87
102
  rspec (~> 3.0)
103
+ rubocop (~> 0.52)
88
104
 
89
105
  BUNDLED WITH
90
106
  1.16.1
data/README.md CHANGED
@@ -15,10 +15,10 @@ You should keep it in mind that here uses [dry-validation](https://github.com/dr
15
15
  - [Basic case](#basic-case)
16
16
  - [Syncing](#syncing)
17
17
  - [Validation](#validation)
18
- - [Advanced declaring fields](#advanced-declaring-fields)
18
+ - [Advanced field declaration](#advanced-field-declaration)
19
19
  - [Types](#types)
20
20
  - [Default value](#default-value)
21
- - [Mass updating values](#mass-updating-values)
21
+ - [Values mass update](#values-mass-update)
22
22
  - [Contributing](#contributing)
23
23
  - [License](#license)
24
24
 
@@ -42,14 +42,15 @@ Or install it yourself as:
42
42
  ## Usage
43
43
 
44
44
  ### Basic case
45
- Just imageine that we have a user object with `name` and `age` attributes:
45
+ For example will be used user object with `name` and `age` attributes:
46
46
 
47
47
  ```ruby
48
48
  User = Struct.new(:name, :age)
49
49
 
50
50
  user = User.new(nil, nil)
51
51
  ```
52
- And we need to save new values and update and we will use simple form object:
52
+
53
+ For setting and syncing new values let's create a form object:
53
54
 
54
55
  ```ruby
55
56
  class Form < Ciesta::Form
@@ -77,10 +78,10 @@ form.sync! do |user|
77
78
  user.make_happy!
78
79
  end
79
80
  ```
80
- Both methods `sync` and `sync!` are provides this DSL.
81
+ Both `sync` and `sync!` provide this DSL.
81
82
 
82
83
  ### Validation
83
- There we want to validate incoming values. We should use `validate` method:
84
+ For validating incoming values you can use `validate` method:
84
85
 
85
86
  ```ruby
86
87
  class Form < Ciesta::Form
@@ -96,7 +97,7 @@ end
96
97
  form = Form.new(user)
97
98
  ```
98
99
 
99
- Trying to sync with invalid form will raise `Ciesta::FormNotValid` error.
100
+ An attempt to sync with invalid form will raise `Ciesta::FormNotValid` error.
100
101
 
101
102
  ```ruby
102
103
  form.age = 15
@@ -110,10 +111,10 @@ form.sync! # => true
110
111
  user.age # => 42
111
112
  ```
112
113
 
113
- ### Advanced declaring fields
114
+ ### Advanced field declaration
114
115
 
115
116
  #### Types
116
- You can define a type of the field using `Ciesta::Types` namespace.
117
+ You can define the type of a field using `Ciesta::Types` namespace.
117
118
 
118
119
  ```ruby
119
120
  field :age, type: Ciesta::Types::Coercible::Int
@@ -124,7 +125,7 @@ form.age # => 42
124
125
  Default type is `Ciesta::Types::Any`.
125
126
 
126
127
  #### Default value
127
- If your attribute wasn't set yet but value already is in use, you can set `default` option to avoid some kind of exceptions.
128
+ If your attribute wasnt set yet, but value is already in use, one can set a `default` option to avoid exceptions.
128
129
 
129
130
  ```ruby
130
131
  field :age, default: 42
@@ -132,7 +133,7 @@ field :age, default: 42
132
133
  form.age # => 42
133
134
  ```
134
135
 
135
- Default value can also be a `Proc`, wich will executed in object context.
136
+ Default value can also be a `Proc`, wich will be called in the object context.
136
137
 
137
138
  ```ruby
138
139
  class User
@@ -148,8 +149,8 @@ field :age, default: -> { default_age }
148
149
  form.age # => 42
149
150
  ```
150
151
 
151
- ## Mass updating values
152
- There are exists two methods for mass update form fields: `assign` and `assign!`.
152
+ ## Values mass update
153
+ There are two methods for form fields mass update: `assign` and `assign!`.
153
154
 
154
155
  ```ruby
155
156
  form.assign!(name: "Neo", age: 30)
@@ -159,7 +160,7 @@ user.name # => "Neo"
159
160
  user.age # => 30
160
161
  ```
161
162
 
162
- `assign!` method will raise `Ciesta::FieldNotDefined` error if one of passed attribute is not exists in the form.
163
+ `assign!` method will raise `Ciesta::FieldNotDefined` error if one of the passed attributes is not declared in the form.
163
164
 
164
165
  ## Contributing
165
166
 
@@ -1,7 +1,7 @@
1
1
 
2
2
  # frozen_string_literal: true
3
3
 
4
- lib = File.expand_path("../lib", __FILE__)
4
+ lib = File.expand_path('lib', __dir__)
5
5
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
6
  require "ciesta/version"
7
7
 
@@ -18,9 +18,7 @@ Gem::Specification.new do |spec|
18
18
 
19
19
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
20
20
  # to allow pushing to a single host or delete this section to allow pushing to any host.
21
- if spec.respond_to?(:metadata)
22
- # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
23
- else
21
+ unless spec.respond_to?(:metadata)
24
22
  raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
25
23
  end
26
24
 
@@ -30,7 +28,7 @@ Gem::Specification.new do |spec|
30
28
  spec.bindir = "exe"
31
29
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
30
  spec.require_paths = ["lib"]
33
- spec.required_ruby_version = ">= 2.0"
31
+ spec.required_ruby_version = ">= 2.1"
34
32
 
35
33
  spec.add_dependency "dry-types", "~> 0.12.1"
36
34
  spec.add_dependency "dry-validation", "~> 0.11.1"
@@ -40,4 +38,5 @@ Gem::Specification.new do |spec|
40
38
  spec.add_development_dependency "pry", "~> 0.11"
41
39
  spec.add_development_dependency "rake", "~> 10.0"
42
40
  spec.add_development_dependency "rspec", "~> 3.0"
41
+ spec.add_development_dependency "rubocop", "~> 0.52"
43
42
  end
@@ -13,7 +13,7 @@ module Ciesta::Delegator
13
13
  " if !#{to}.nil?",
14
14
  " #{to}.#{name}(*args, &block)",
15
15
  " end",
16
- "end",
16
+ "end"
17
17
  ].join(";")
18
18
 
19
19
  module_eval(method_def)
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ciesta
4
- # Error class for error about violating constraints
4
+ # Error for violating constraints
5
5
  ViolatesConstraints = Class.new(ArgumentError)
6
6
 
7
7
  # Error for invalid object
@@ -9,4 +9,7 @@ module Ciesta
9
9
 
10
10
  # Error for missing field definition
11
11
  FieldNotDefined = Class.new(NoMethodError)
12
+
13
+ # Error for nil object
14
+ ModelNotPresent = Class.new(StandardError)
12
15
  end
@@ -56,7 +56,11 @@ class Ciesta::FieldList
56
56
  # @return [Boolean]
57
57
  def assign(attributes)
58
58
  attributes = attributes.keep_if { |key| keys.include?(key) }
59
- assign!(attributes) rescue false
59
+ begin
60
+ assign!(attributes)
61
+ rescue StandardError
62
+ false
63
+ end
60
64
  end
61
65
 
62
66
  # Getting all field names
@@ -72,7 +76,7 @@ class Ciesta::FieldList
72
76
  # @api private
73
77
  # @return [Hash<Symbol, any>]
74
78
  def attributes
75
- list.values.each_with_object({}) { |field, mem| mem[field.name] = field.value }
79
+ list.values.map { |field| [field.name, field.value] }.to_h
76
80
  end
77
81
 
78
82
  # Iterate over all fields
@@ -12,11 +12,6 @@ class Ciesta::Form
12
12
  # @see Ciesta::FieldList
13
13
  delegate :assign, :assign!, :attributes, to: :fields
14
14
 
15
- # @!method sync!
16
- # @!method sync
17
- # @see Ciesta::Syncer
18
- delegate :sync, to: :syncer
19
-
20
15
  # @!method errors
21
16
  # @see Ciesta::Validator
22
17
  delegate :errors, to: :validator
@@ -65,14 +60,13 @@ class Ciesta::Form
65
60
  # Constructor
66
61
  #
67
62
  # @param [Object] object Object wich will be updated though this form
68
- def initialize(object)
63
+ def initialize(object = nil)
69
64
  @object = object
70
65
 
71
- obj_values = fields.keys.each_with_object({}) do |key, mem|
72
- mem[key] = object.public_send(key)
73
- end
66
+ return if object.nil?
74
67
 
75
- assign(obj_values)
68
+ values = fields.keys.map { |key| [key, object.public_send(key)] }.to_h
69
+ assign(values)
76
70
  end
77
71
 
78
72
  # Checks if form is valid
@@ -87,15 +81,31 @@ class Ciesta::Form
87
81
 
88
82
  # Sync form attributes to object
89
83
  #
84
+ # @see Ciesta::Syncer
85
+ #
90
86
  # @param [Block] block Block wich will be yielded after synfing
91
87
  #
88
+ # @raise Ciesta::ModelNotPresent
92
89
  # @raise Ciesta::FormNotValid
93
90
  # @return [Boolean]
94
91
  def sync!(&block)
92
+ raise Ciesta::ModelNotPresent, "Model not present" if object.nil?
95
93
  raise Ciesta::FormNotValid, "Form is not valid" unless valid?
96
94
  syncer.sync(&block)
97
95
  end
98
96
 
97
+ # Sync form attributes to object
98
+ #
99
+ # @see Ciesta::Syncer
100
+ #
101
+ # @param [Block] block Block wich will be yielded after synfing
102
+ #
103
+ # @return [Boolean]
104
+ def sync(&block)
105
+ return if object.nil?
106
+ syncer.sync(&block)
107
+ end
108
+
99
109
  private
100
110
 
101
111
  # Sync class for form
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ciesta
4
- VERSION = "0.2.2".freeze
4
+ VERSION = "0.2.3".freeze
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ciesta
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexey
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-03-06 00:00:00.000000000 Z
11
+ date: 2018-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-types
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: '3.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.52'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.52'
111
125
  description: Gem for creating and using form object
112
126
  email:
113
127
  - alex.coder1@gmail.com
@@ -151,7 +165,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
151
165
  requirements:
152
166
  - - ">="
153
167
  - !ruby/object:Gem::Version
154
- version: '2.0'
168
+ version: '2.1'
155
169
  required_rubygems_version: !ruby/object:Gem::Requirement
156
170
  requirements:
157
171
  - - ">="