Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7652465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:46:37+00:00 2026-05-31T11:46:37+00:00

I’m developing a model which holds configuration settings for server options. The number and

  • 0

I’m developing a model which holds configuration settings for server options. The number and type of server options change, and I need some input on the pros/cons of two ways of doing it.
I’m doing this separate from the rails ActiveRecord database. All my database interactions are going to be manually with the file system.

First, having the model dynamically create attributes as needed for each server specified. (as long as this is possible… I’ve never done it before)

Second, creating a single Hash, which has Keys of the server options, and values of the server settings.

I think the second would be easier to implement, but I’m not sure if it is the right way to go? It seems to be cleaner to go with dynamic attributes.

Is there a rule of thumb to go with for this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T11:46:39+00:00Added an answer on May 31, 2026 at 11:46 am

    Made something for you.

    Here is how it would work.

    s = Settings.new(SettingsFileManager.new(some_file))
    
    s.ip # returns whats in the file.
    s.ip = 10.0.0.1 # overrides the new value.
    

    I haven’t written the way it interacts with the files yet so you’ll have to write a proper SettingsFileManager.

    If anything it should give you a good base to get started. But I wrote it primarily as a test to see what I know about ruby. Since it uses some semi-tricky stuff.

    Hosted it on github too with some tests.

    class Settings
    
      attr_accessor :settings
    
      def initialize(file_writer)
        @file_writer = file_writer
        read_settings_to_new_hash
      end
    
      def read_settings_to_new_hash
        @settings = fabricate_hash
        @settings.replace(@file_writer.read_keys)
      end
    
      def fabricate_hash
        InterceptedHash.new( &hash_saved_proc )
      end
    
      def hash_saved_proc
        Proc.new do |key, value|
          @file_writer.write_key(key, value)
        end
      end
    
      def method_missing(m, *args, &block)
        if @settings.has_key?(m) || args[0]
          if args[0]
            @settings[m.to_s.sub("=","").to_sym] = args[0]
          else
            @settings[m]
          end
        else
          raise "unknown setting"
        end
      end
    
    end
    
    # Not implemented. This should continue the logic to interact with whatever you want.
    class SettingsFileManager
      def initialize(file)
        @file = file
      end
    
      # write the key and its value somewhere.
      def write_key(key, value)
        puts 'write_key', key, value
      end
    
      # should return hash of keys.
      def read_keys
        puts 'read_keys'
        Hash.new
      end
    end
    
    class InterceptedHash < Hash
      def initialize(&block)
        super
        @block = block
      end
    
      def store(key, value)
        super(key, value)
        @block.call(key, value)
      end
    
      def []=(key, value)
        store(key, value)
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to clean up various Word 'smart' characters in user input, including but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
In my XML file chapters tag has more chapter tag.i need to display chapters
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.