Skip to content

Commit

Permalink
Merge pull request #22 from iiwo/chore/add_persisted_value_accessor
Browse files Browse the repository at this point in the history
add context_list_persisted
  • Loading branch information
iiwo authored Sep 13, 2019
2 parents 69c7ef0 + f3c66c7 commit 6519eb7
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 7 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [0.2.0] - 2019-09-12
### Added
- `[context]_list_persisted` interface method for accessing persisted/previous tag list string

## [0.1.0] - 2019-07-15
Initial release

[Unreleased]: https://github.com/iiwo/easy_tagscompare/v0.2.0...HEAD
[0.2.0]: https://github.com/iiwo/easy_tags/compare/v0.1.0...v0.2.0
[0.1.0]: https://github.com/iiwo/easy_tags/releases/tag/v0.1.0
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,13 @@ easy_tags_on :highlights

the following methods will be auto-generated and made available for your model instance (`highlights` being an example context name):

| description | method |
|------------------------------------|---------------------------|
| set tags using string of tag names | `highlights_list=(value)` |
| get string of tag names | `highlights_list` |
| set tags with array of tag names | `highlights=(value)` |
| get array of tag names | `highlights` |
| description | method |
|------------------------------------|----------------------------------|
| set tags using string of tag names | `highlights_list=(value)` |
| get string of tag names | `highlights_list` |
| get string of persisted tag names | `highlights_list_persisted` |
| set tags with array of tag names | `highlights=(value)` |
| get array of tag names | `highlights` |

- the String accessor is helpful when working with client side tagging UI solutions such as ie. [select2](https://select2.org/tagging)
- the Array accessor gives you convenient array item manipulation
Expand Down
8 changes: 8 additions & 0 deletions easy_tags.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'easy_tags/version'

# rubocop:disable Metrics/BlockLength
Gem::Specification.new do |spec|
spec.name = 'easy_tags'
spec.version = EasyTags::VERSION
Expand All @@ -12,6 +13,12 @@ Gem::Specification.new do |spec|
spec.description = 'Easy tagging for Rails'
spec.homepage = 'https://github.com/iiwo/easy_tags'
spec.license = 'MIT'
spec.metadata = {
'homepage_uri' => 'https://github.com/iiwo/easy_tags',
'changelog_uri' => 'https://github.com/iiwo/easy_tags/blob/master/CHANGELOG.md',
'source_code_uri' => 'https://github.com/iiwo/easy_tags',
'bug_tracker_uri' => 'https://github.com/iiwo/easy_tags/issues'
}

spec.files = `git ls-files -z`.split("\x0").reject do |f|
f.match(%r{^(test|spec|features)/})
Expand All @@ -31,3 +38,4 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'simplecov-console'
spec.add_development_dependency 'sqlite3', '~> 1.3.6'
end
# rubocop:enable Metrics/BlockLength
4 changes: 4 additions & 0 deletions lib/easy_tags/taggable_context_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ def #{context}_list=(value)
_taggable_context(:#{context}).update(value)
#{context}_list
end
def #{context}_list_persisted
_taggable_context(:#{context}).persisted_tags.to_s
end
RUBY
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/easy_tags/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module EasyTags
VERSION = '0.1.0'.freeze
VERSION = '0.2.0'.freeze
end
12 changes: 12 additions & 0 deletions spec/easy_tags/context_methods_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ def create_tag_for(taggable:, tag_name:, context: 'bees')
end
end

describe '#context_list_persisted' do
before do
taggable.bees_list = 'bumble, busy'
taggable.save!
taggable.bees_list = 'cool, angry'
end

it 'returns persisted tags string' do
expect(taggable.bees_list_persisted).to eq('bumble,busy')
end
end

shared_examples 'a proper assignment' do
describe 'unpersisted' do
it 'sets proper context_list value' do
Expand Down

0 comments on commit 6519eb7

Please sign in to comment.