From 76f5e4e6e10444e2173d2f61380ebac8f3c21299 Mon Sep 17 00:00:00 2001 From: Torsten Date: Sun, 11 Dec 2022 14:39:32 +0200 Subject: [PATCH] rename Option to OptionDefinition to be full Rails compliant --- app/models/merged/card.rb | 2 +- app/models/merged/card_style.rb | 2 +- .../{option.rb => option_definition.rb} | 2 +- app/models/merged/section_style.rb | 2 +- .../{options.yml => option_definitions.yml} | 0 lib/merged.rb | 2 +- spec/models/merged/option_definition_spec.rb | 20 +++++++++++++++++++ spec/models/merged/option_spec.rb | 20 ------------------- spec/models/merged/section_spec.rb | 2 +- 9 files changed, 26 insertions(+), 26 deletions(-) rename app/models/merged/{option.rb => option_definition.rb} (91%) rename config/merged/{options.yml => option_definitions.yml} (100%) create mode 100644 spec/models/merged/option_definition_spec.rb delete mode 100644 spec/models/merged/option_spec.rb diff --git a/app/models/merged/card.rb b/app/models/merged/card.rb index 6d70da5..3562b6e 100644 --- a/app/models/merged/card.rb +++ b/app/models/merged/card.rb @@ -36,7 +36,7 @@ module Merged def save super data = Card.all.collect {|obj| obj.attributes} - File.write( Option.full_path , data.to_yaml) + File.write( OptionDefinition.full_path , data.to_yaml) end def set_index(index) diff --git a/app/models/merged/card_style.rb b/app/models/merged/card_style.rb index 57585f4..1bc2dcf 100644 --- a/app/models/merged/card_style.rb +++ b/app/models/merged/card_style.rb @@ -11,7 +11,7 @@ module Merged def options_definitions option_defs = [] options.each do |name| - option = Option.find_by_name(name) + option = OptionDefinition.find_by_name(name) raise "no option for #{name}:#{name.class}" if option.blank? option_defs << option end if options diff --git a/app/models/merged/option.rb b/app/models/merged/option_definition.rb similarity index 91% rename from app/models/merged/option.rb rename to app/models/merged/option_definition.rb index c052e31..bbeceaa 100644 --- a/app/models/merged/option.rb +++ b/app/models/merged/option_definition.rb @@ -1,5 +1,5 @@ module Merged - class Option < ActiveYaml::Base + class OptionDefinition < ActiveYaml::Base set_root_path Engine.root + "config" fields :name , :default , :description , :values , :type diff --git a/app/models/merged/section_style.rb b/app/models/merged/section_style.rb index dcdb476..fbb8efb 100644 --- a/app/models/merged/section_style.rb +++ b/app/models/merged/section_style.rb @@ -15,7 +15,7 @@ module Merged def options_definitions option_defs = [] options.each do |name| - option = Option.find_by_name(name) + option = OptionDefinition.find_by_name(name) raise "no option for #{name}:#{name.class}" if option.blank? option_defs << option end if options diff --git a/config/merged/options.yml b/config/merged/option_definitions.yml similarity index 100% rename from config/merged/options.yml rename to config/merged/option_definitions.yml diff --git a/lib/merged.rb b/lib/merged.rb index 242c056..8f1f72c 100644 --- a/lib/merged.rb +++ b/lib/merged.rb @@ -5,7 +5,7 @@ module Merged def self.load_data # pre-load data - Option.all + OptionDefinition.all CardStyle.all SectionStyle.all Page.all diff --git a/spec/models/merged/option_definition_spec.rb b/spec/models/merged/option_definition_spec.rb new file mode 100644 index 0000000..f526f8d --- /dev/null +++ b/spec/models/merged/option_definition_spec.rb @@ -0,0 +1,20 @@ +require 'rails_helper' + +module Merged + RSpec.describe OptionDefinition, type: :model do + let(:first) {OptionDefinition.first} + + it "has OptionDefinition.first" do + expect(OptionDefinition.first.class).to be OptionDefinition + end + it "there are options" do + expect(OptionDefinition.all.length).to be 16 + end + it "has option objects" do + expect(first.class).to be OptionDefinition + end + it "has values" do + expect(first.values.class).to be Array + end + end +end diff --git a/spec/models/merged/option_spec.rb b/spec/models/merged/option_spec.rb deleted file mode 100644 index 70e4f88..0000000 --- a/spec/models/merged/option_spec.rb +++ /dev/null @@ -1,20 +0,0 @@ -require 'rails_helper' - -module Merged - RSpec.describe Option, type: :model do - let(:first) {Option.first} - - it "has Option.first" do - expect(Option.first.class).to be Option - end - it "there are options" do - expect(Option.all.length).to be 16 - end - it "has option objects" do - expect(first.class).to be Option - end - it "has values" do - expect(first.values.class).to be Array - end - end -end diff --git a/spec/models/merged/section_spec.rb b/spec/models/merged/section_spec.rb index 6317a7b..86e9566 100644 --- a/spec/models/merged/section_spec.rb +++ b/spec/models/merged/section_spec.rb @@ -28,7 +28,7 @@ module Merged it "has option_definitions" do expect(last.option_definitions.class).to be Array expect(last.option_definitions.length).to be 4 - expect(last.option_definitions.second.class).to be Option + expect(last.option_definitions.second.class).to be OptionDefinition expect(last.option_definitions.second.name).to eq "handler" end it "last has previous" do